Skip to content

Commit 68ba427

Browse files
committed
Be absolutely clear about the mappings no longer being supported API.
1 parent 785d6da commit 68ba427

File tree

6 files changed

+44
-42
lines changed

6 files changed

+44
-42
lines changed

src/webcolors/_definitions.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ def _reversedict(dict_to_reverse: dict) -> dict:
1717
return {value: key for key, value in dict_to_reverse.items()}
1818

1919

20-
HEX_COLOR_RE = re.compile(r"^#([a-fA-F0-9]{3}|[a-fA-F0-9]{6})$")
20+
_HEX_COLOR_RE = re.compile(r"^#([a-fA-F0-9]{3}|[a-fA-F0-9]{6})$")
2121

2222
HTML4 = "html4"
2323
CSS2 = "css2"
2424
CSS21 = "css21"
2525
CSS3 = "css3"
2626

27-
SUPPORTED_SPECIFICATIONS = (HTML4, CSS2, CSS21, CSS3)
27+
_SUPPORTED_SPECIFICATIONS = (HTML4, CSS2, CSS21, CSS3)
2828

29-
SPECIFICATION_ERROR_TEMPLATE = (
29+
_SPECIFICATION_ERROR_TEMPLATE = (
3030
f"{{spec}} is not a supported specification for color name lookups; "
31-
f"supported specifications are: {SUPPORTED_SPECIFICATIONS}."
31+
f"supported specifications are: {_SUPPORTED_SPECIFICATIONS}."
3232
)
3333

3434
# Mappings of color names to normalized hexadecimal color values.
@@ -43,7 +43,7 @@ def _reversedict(dict_to_reverse: dict) -> dict:
4343
# The file tests/definitions.py in the source distribution of this module downloads a
4444
# copy of the HTML 4 standard and parses out the color names to ensure the values below
4545
# are correct.
46-
HTML4_NAMES_TO_HEX = {
46+
_HTML4_NAMES_TO_HEX = {
4747
"aqua": "#00ffff",
4848
"black": "#000000",
4949
"blue": "#0000ff",
@@ -63,10 +63,10 @@ def _reversedict(dict_to_reverse: dict) -> dict:
6363
}
6464

6565
# CSS2 used the same list as HTML 4.
66-
CSS2_NAMES_TO_HEX = HTML4_NAMES_TO_HEX
66+
_CSS2_NAMES_TO_HEX = _HTML4_NAMES_TO_HEX
6767

6868
# CSS2.1 added orange.
69-
CSS21_NAMES_TO_HEX = {"orange": "#ffa500", **HTML4_NAMES_TO_HEX}
69+
_CSS21_NAMES_TO_HEX = {"orange": "#ffa500", **_HTML4_NAMES_TO_HEX}
7070

7171
# The CSS3/SVG named colors.
7272
#
@@ -84,7 +84,7 @@ def _reversedict(dict_to_reverse: dict) -> dict:
8484
# mapping below is to hex values instead. The file tests/definitions.py in the source
8585
# distribution of this module downloads a copy of the CSS3 color module and parses out
8686
# the color names to ensure the values below are correct.
87-
CSS3_NAMES_TO_HEX = {
87+
_CSS3_NAMES_TO_HEX = {
8888
"aliceblue": "#f0f8ff",
8989
"antiquewhite": "#faebd7",
9090
"aqua": "#00ffff",
@@ -238,13 +238,13 @@ def _reversedict(dict_to_reverse: dict) -> dict:
238238
# Mappings of normalized hexadecimal color values to color names.
239239
# --------------------------------------------------------------------------------
240240

241-
HTML4_HEX_TO_NAMES = _reversedict(HTML4_NAMES_TO_HEX)
241+
_HTML4_HEX_TO_NAMES = _reversedict(_HTML4_NAMES_TO_HEX)
242242

243-
CSS2_HEX_TO_NAMES = HTML4_HEX_TO_NAMES
243+
_CSS2_HEX_TO_NAMES = _HTML4_HEX_TO_NAMES
244244

245-
CSS21_HEX_TO_NAMES = _reversedict(CSS21_NAMES_TO_HEX)
245+
_CSS21_HEX_TO_NAMES = _reversedict(_CSS21_NAMES_TO_HEX)
246246

247-
CSS3_HEX_TO_NAMES = _reversedict(CSS3_NAMES_TO_HEX)
247+
_CSS3_HEX_TO_NAMES = _reversedict(_CSS3_NAMES_TO_HEX)
248248

249249
# CSS3 defines both "gray" and "grey", as well as defining either spelling variant for
250250
# other related colors like "darkgray"/"darkgrey", etc. For a "forward" lookup from
@@ -253,27 +253,27 @@ def _reversedict(dict_to_reverse: dict) -> dict:
253253
#
254254
# Since "gray" was the only spelling supported in HTML 4, CSS1, and CSS2, "gray" and its
255255
# variants are chosen here.
256-
CSS3_HEX_TO_NAMES["#a9a9a9"] = "darkgray"
257-
CSS3_HEX_TO_NAMES["#2f4f4f"] = "darkslategray"
258-
CSS3_HEX_TO_NAMES["#696969"] = "dimgray"
259-
CSS3_HEX_TO_NAMES["#808080"] = "gray"
260-
CSS3_HEX_TO_NAMES["#d3d3d3"] = "lightgray"
261-
CSS3_HEX_TO_NAMES["#778899"] = "lightslategray"
262-
CSS3_HEX_TO_NAMES["#708090"] = "slategray"
256+
_CSS3_HEX_TO_NAMES["#a9a9a9"] = "darkgray"
257+
_CSS3_HEX_TO_NAMES["#2f4f4f"] = "darkslategray"
258+
_CSS3_HEX_TO_NAMES["#696969"] = "dimgray"
259+
_CSS3_HEX_TO_NAMES["#808080"] = "gray"
260+
_CSS3_HEX_TO_NAMES["#d3d3d3"] = "lightgray"
261+
_CSS3_HEX_TO_NAMES["#778899"] = "lightslategray"
262+
_CSS3_HEX_TO_NAMES["#708090"] = "slategray"
263263

264264

265265
_names_to_hex = {
266-
HTML4: HTML4_NAMES_TO_HEX,
267-
CSS2: CSS2_NAMES_TO_HEX,
268-
CSS21: CSS21_NAMES_TO_HEX,
269-
CSS3: CSS3_NAMES_TO_HEX,
266+
HTML4: _HTML4_NAMES_TO_HEX,
267+
CSS2: _CSS2_NAMES_TO_HEX,
268+
CSS21: _CSS21_NAMES_TO_HEX,
269+
CSS3: _CSS3_NAMES_TO_HEX,
270270
}
271271

272272
_hex_to_names = {
273-
HTML4: HTML4_HEX_TO_NAMES,
274-
CSS2: CSS2_HEX_TO_NAMES,
275-
CSS21: CSS21_HEX_TO_NAMES,
276-
CSS3: CSS3_HEX_TO_NAMES,
273+
HTML4: _HTML4_HEX_TO_NAMES,
274+
CSS2: _CSS2_HEX_TO_NAMES,
275+
CSS21: _CSS21_HEX_TO_NAMES,
276+
CSS3: _CSS3_HEX_TO_NAMES,
277277
}
278278

279279

@@ -284,8 +284,8 @@ def _get_name_to_hex_map(spec: str):
284284
:raises ValueError: when the given spec is not supported.
285285
286286
"""
287-
if spec not in SUPPORTED_SPECIFICATIONS:
288-
raise ValueError(SPECIFICATION_ERROR_TEMPLATE.format(spec=spec))
287+
if spec not in _SUPPORTED_SPECIFICATIONS:
288+
raise ValueError(_SPECIFICATION_ERROR_TEMPLATE.format(spec=spec))
289289
return _names_to_hex[spec]
290290

291291

@@ -296,6 +296,6 @@ def _get_hex_to_name_map(spec: str):
296296
:raises ValueError: when the given spec is not supported.
297297
298298
"""
299-
if spec not in SUPPORTED_SPECIFICATIONS:
300-
raise ValueError(SPECIFICATION_ERROR_TEMPLATE.format(spec=spec))
299+
if spec not in _SUPPORTED_SPECIFICATIONS:
300+
raise ValueError(_SPECIFICATION_ERROR_TEMPLATE.format(spec=spec))
301301
return _hex_to_names[spec]

src/webcolors/_html5.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import string
1919

20-
from ._definitions import CSS3_NAMES_TO_HEX
20+
from ._definitions import _CSS3_NAMES_TO_HEX
2121
from ._types import HTML5SimpleColor, IntTuple
2222

2323

@@ -164,7 +164,7 @@ def html5_parse_legacy_color(value: str) -> HTML5SimpleColor:
164164
# return the simple color corresponding to that keyword.
165165
#
166166
# Note: CSS2 System Colors are not recognized.
167-
keyword_hex = CSS3_NAMES_TO_HEX.get(value.lower())
167+
keyword_hex = _CSS3_NAMES_TO_HEX.get(value.lower())
168168
if keyword_hex is not None:
169169
return html5_parse_simple_color(keyword_hex)
170170

src/webcolors/_normalization.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# SPDX-License-Identifier: BSD-3-Clause
77

8-
from ._definitions import HEX_COLOR_RE
8+
from ._definitions import _HEX_COLOR_RE
99
from ._types import IntegerRGB, IntTuple, PercentRGB, PercentTuple
1010

1111

@@ -44,7 +44,7 @@ def normalize_hex(hex_value: str) -> str:
4444
:raises ValueError: when the input is not a valid hexadecimal color value.
4545
4646
"""
47-
match = HEX_COLOR_RE.match(hex_value)
47+
match = _HEX_COLOR_RE.match(hex_value)
4848
if match is None:
4949
raise ValueError(f'"{hex_value}" is not a valid hexadecimal color value.')
5050
hex_digits = match.group(1)

tests/definitions.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_color_definitions(self):
4848
4949
"""
5050
for color_name, color_value in self.html4_colors.items():
51-
extracted = webcolors._definitions.HTML4_NAMES_TO_HEX[color_name.lower()]
51+
extracted = webcolors._definitions._HTML4_NAMES_TO_HEX[color_name.lower()]
5252
assert color_value.lower() == extracted
5353

5454

@@ -83,7 +83,7 @@ def test_color_definitions(self):
8383
8484
"""
8585
for color_name, color_value in self.css21_colors.items():
86-
extracted = webcolors._definitions.CSS21_NAMES_TO_HEX[color_name.lower()]
86+
extracted = webcolors._definitions._CSS21_NAMES_TO_HEX[color_name.lower()]
8787
assert color_value.lower() == extracted
8888

8989

@@ -134,7 +134,9 @@ def test_color_definitions(self):
134134
135135
"""
136136
for color_name, color_values in self.css3_colors.items():
137-
extracted_hex = webcolors._definitions.CSS3_NAMES_TO_HEX[color_name.lower()]
137+
extracted_hex = webcolors._definitions._CSS3_NAMES_TO_HEX[
138+
color_name.lower()
139+
]
138140
extracted_rgb = webcolors.name_to_rgb(color_name)
139141
assert color_values["hex"].lower() == extracted_hex
140142
assert color_values["rgb"] == extracted_rgb

tests/test_conversion.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test_hex_to_name_specs(self):
5252
specification raises ValueError.
5353
5454
"""
55-
for supported_spec in webcolors._definitions.SUPPORTED_SPECIFICATIONS:
55+
for supported_spec in webcolors._definitions._SUPPORTED_SPECIFICATIONS:
5656
result = webcolors.hex_to_name("#ffffff", spec=supported_spec)
5757
assert "white" == result
5858

@@ -135,7 +135,7 @@ def test_rgb_to_name_specs(self):
135135
specification raises ValueError.
136136
137137
"""
138-
for supported_spec in webcolors._definitions.SUPPORTED_SPECIFICATIONS:
138+
for supported_spec in webcolors._definitions._SUPPORTED_SPECIFICATIONS:
139139
result = webcolors.rgb_to_name((255, 255, 255), spec=supported_spec)
140140
assert "white" == result
141141

@@ -219,7 +219,7 @@ def test_name_to_hex_specs(self):
219219
specification raises ValueError.
220220
221221
"""
222-
for supported_spec in webcolors._definitions.SUPPORTED_SPECIFICATIONS:
222+
for supported_spec in webcolors._definitions._SUPPORTED_SPECIFICATIONS:
223223
result = webcolors.name_to_hex("white", spec=supported_spec)
224224
assert "#ffffff" == result
225225

tests/test_html5.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def test_parse_legacy_color_names(self):
8989
Test the HTML5 legacy color parsing of SVG/CSS3 color names.
9090
9191
"""
92-
for name in webcolors._definitions.CSS3_NAMES_TO_HEX:
92+
for name in webcolors._definitions._CSS3_NAMES_TO_HEX:
9393
parsed = webcolors.html5_parse_legacy_color(name)
9494
assert parsed == webcolors.name_to_rgb(name)
9595

0 commit comments

Comments
 (0)