Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/faker/providers/color/__init__.py: 67%
23 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
1from collections import OrderedDict
2from typing import Dict, Optional
4from ...typing import HueType
5from .. import BaseProvider, ElementsType
6from .color import RandomColor
8localized = True
11class Provider(BaseProvider):
12 """Implement default color provider for Faker."""
14 all_colors: Dict[str, str] = OrderedDict(
15 (
16 ("AliceBlue", "#F0F8FF"),
17 ("AntiqueWhite", "#FAEBD7"),
18 ("Aqua", "#00FFFF"),
19 ("Aquamarine", "#7FFFD4"),
20 ("Azure", "#F0FFFF"),
21 ("Beige", "#F5F5DC"),
22 ("Bisque", "#FFE4C4"),
23 ("Black", "#000000"),
24 ("BlanchedAlmond", "#FFEBCD"),
25 ("Blue", "#0000FF"),
26 ("BlueViolet", "#8A2BE2"),
27 ("Brown", "#A52A2A"),
28 ("BurlyWood", "#DEB887"),
29 ("CadetBlue", "#5F9EA0"),
30 ("Chartreuse", "#7FFF00"),
31 ("Chocolate", "#D2691E"),
32 ("Coral", "#FF7F50"),
33 ("CornflowerBlue", "#6495ED"),
34 ("Cornsilk", "#FFF8DC"),
35 ("Crimson", "#DC143C"),
36 ("Cyan", "#00FFFF"),
37 ("DarkBlue", "#00008B"),
38 ("DarkCyan", "#008B8B"),
39 ("DarkGoldenRod", "#B8860B"),
40 ("DarkGray", "#A9A9A9"),
41 ("DarkGreen", "#006400"),
42 ("DarkKhaki", "#BDB76B"),
43 ("DarkMagenta", "#8B008B"),
44 ("DarkOliveGreen", "#556B2F"),
45 ("DarkOrange", "#FF8C00"),
46 ("DarkOrchid", "#9932CC"),
47 ("DarkRed", "#8B0000"),
48 ("DarkSalmon", "#E9967A"),
49 ("DarkSeaGreen", "#8FBC8F"),
50 ("DarkSlateBlue", "#483D8B"),
51 ("DarkSlateGray", "#2F4F4F"),
52 ("DarkTurquoise", "#00CED1"),
53 ("DarkViolet", "#9400D3"),
54 ("DeepPink", "#FF1493"),
55 ("DeepSkyBlue", "#00BFFF"),
56 ("DimGray", "#696969"),
57 ("DodgerBlue", "#1E90FF"),
58 ("FireBrick", "#B22222"),
59 ("FloralWhite", "#FFFAF0"),
60 ("ForestGreen", "#228B22"),
61 ("Fuchsia", "#FF00FF"),
62 ("Gainsboro", "#DCDCDC"),
63 ("GhostWhite", "#F8F8FF"),
64 ("Gold", "#FFD700"),
65 ("GoldenRod", "#DAA520"),
66 ("Gray", "#808080"),
67 ("Green", "#008000"),
68 ("GreenYellow", "#ADFF2F"),
69 ("HoneyDew", "#F0FFF0"),
70 ("HotPink", "#FF69B4"),
71 ("IndianRed", "#CD5C5C"),
72 ("Indigo", "#4B0082"),
73 ("Ivory", "#FFFFF0"),
74 ("Khaki", "#F0E68C"),
75 ("Lavender", "#E6E6FA"),
76 ("LavenderBlush", "#FFF0F5"),
77 ("LawnGreen", "#7CFC00"),
78 ("LemonChiffon", "#FFFACD"),
79 ("LightBlue", "#ADD8E6"),
80 ("LightCoral", "#F08080"),
81 ("LightCyan", "#E0FFFF"),
82 ("LightGoldenRodYellow", "#FAFAD2"),
83 ("LightGray", "#D3D3D3"),
84 ("LightGreen", "#90EE90"),
85 ("LightPink", "#FFB6C1"),
86 ("LightSalmon", "#FFA07A"),
87 ("LightSeaGreen", "#20B2AA"),
88 ("LightSkyBlue", "#87CEFA"),
89 ("LightSlateGray", "#778899"),
90 ("LightSteelBlue", "#B0C4DE"),
91 ("LightYellow", "#FFFFE0"),
92 ("Lime", "#00FF00"),
93 ("LimeGreen", "#32CD32"),
94 ("Linen", "#FAF0E6"),
95 ("Magenta", "#FF00FF"),
96 ("Maroon", "#800000"),
97 ("MediumAquaMarine", "#66CDAA"),
98 ("MediumBlue", "#0000CD"),
99 ("MediumOrchid", "#BA55D3"),
100 ("MediumPurple", "#9370DB"),
101 ("MediumSeaGreen", "#3CB371"),
102 ("MediumSlateBlue", "#7B68EE"),
103 ("MediumSpringGreen", "#00FA9A"),
104 ("MediumTurquoise", "#48D1CC"),
105 ("MediumVioletRed", "#C71585"),
106 ("MidnightBlue", "#191970"),
107 ("MintCream", "#F5FFFA"),
108 ("MistyRose", "#FFE4E1"),
109 ("Moccasin", "#FFE4B5"),
110 ("NavajoWhite", "#FFDEAD"),
111 ("Navy", "#000080"),
112 ("OldLace", "#FDF5E6"),
113 ("Olive", "#808000"),
114 ("OliveDrab", "#6B8E23"),
115 ("Orange", "#FFA500"),
116 ("OrangeRed", "#FF4500"),
117 ("Orchid", "#DA70D6"),
118 ("PaleGoldenRod", "#EEE8AA"),
119 ("PaleGreen", "#98FB98"),
120 ("PaleTurquoise", "#AFEEEE"),
121 ("PaleVioletRed", "#DB7093"),
122 ("PapayaWhip", "#FFEFD5"),
123 ("PeachPuff", "#FFDAB9"),
124 ("Peru", "#CD853F"),
125 ("Pink", "#FFC0CB"),
126 ("Plum", "#DDA0DD"),
127 ("PowderBlue", "#B0E0E6"),
128 ("Purple", "#800080"),
129 ("Red", "#FF0000"),
130 ("RosyBrown", "#BC8F8F"),
131 ("RoyalBlue", "#4169E1"),
132 ("SaddleBrown", "#8B4513"),
133 ("Salmon", "#FA8072"),
134 ("SandyBrown", "#F4A460"),
135 ("SeaGreen", "#2E8B57"),
136 ("SeaShell", "#FFF5EE"),
137 ("Sienna", "#A0522D"),
138 ("Silver", "#C0C0C0"),
139 ("SkyBlue", "#87CEEB"),
140 ("SlateBlue", "#6A5ACD"),
141 ("SlateGray", "#708090"),
142 ("Snow", "#FFFAFA"),
143 ("SpringGreen", "#00FF7F"),
144 ("SteelBlue", "#4682B4"),
145 ("Tan", "#D2B48C"),
146 ("Teal", "#008080"),
147 ("Thistle", "#D8BFD8"),
148 ("Tomato", "#FF6347"),
149 ("Turquoise", "#40E0D0"),
150 ("Violet", "#EE82EE"),
151 ("Wheat", "#F5DEB3"),
152 ("White", "#FFFFFF"),
153 ("WhiteSmoke", "#F5F5F5"),
154 ("Yellow", "#FFFF00"),
155 ("YellowGreen", "#9ACD32"),
156 )
157 )
159 safe_colors: ElementsType[str] = (
160 "black",
161 "maroon",
162 "green",
163 "navy",
164 "olive",
165 "purple",
166 "teal",
167 "lime",
168 "blue",
169 "silver",
170 "gray",
171 "yellow",
172 "fuchsia",
173 "aqua",
174 "white",
175 )
177 def color_name(self) -> str:
178 """Generate a color name."""
179 return self.random_element(self.all_colors.keys())
181 def safe_color_name(self) -> str:
182 """Generate a web-safe color name."""
183 return self.random_element(self.safe_colors)
185 def hex_color(self) -> str:
186 """Generate a color formatted as a hex triplet."""
187 return f"#{self.random_int(1, 16777215):06x}"
189 def safe_hex_color(self) -> str:
190 """Generate a web-safe color formatted as a hex triplet."""
191 return f"#{self.random_int(0, 15) * 17:02x}{self.random_int(0, 15) * 17:02x}{self.random_int(0, 15) * 17:02x}"
193 def rgb_color(self) -> str:
194 """Generate a color formatted as a comma-separated RGB value."""
195 return ",".join(map(str, (self.random_int(0, 255) for _ in range(3))))
197 def rgb_css_color(self) -> str:
198 """Generate a color formatted as a CSS rgb() function."""
199 return f"rgb({self.random_int(0, 255)},{self.random_int(0, 255)},{self.random_int(0, 255)})"
201 def color(
202 self,
203 hue: Optional[HueType] = None,
204 luminosity: Optional[str] = None,
205 color_format: str = "hex",
206 ) -> str:
207 """Generate a color in a human-friendly way.
209 Under the hood, this method first creates a color represented in the HSV
210 color model and then converts it to the desired ``color_format``. The
211 argument ``hue`` controls the H value according to the following
212 rules:
214 - If the value is a number from ``0`` to ``360``, it will serve as the H
215 value of the generated color.
216 - If the value is a tuple/list of 2 numbers from 0 to 360, the color's H
217 value will be randomly selected from that range.
218 - If the value is a valid string, the color's H value will be randomly
219 selected from the H range corresponding to the supplied string. Valid
220 values are ``'monochrome'``, ``'red'``, ``'orange'``, ``'yellow'``,
221 ``'green'``, ``'blue'``, ``'purple'``, and ``'pink'``.
223 The argument ``luminosity`` influences both S and V values and is
224 partially affected by ``hue`` as well. The finer details of this
225 relationship are somewhat involved, so please refer to the source code
226 instead if you wish to dig deeper. To keep the interface simple, this
227 argument either can be omitted or can accept the following string
228 values:``'bright'``, ``'dark'``, ``'light'``, or ``'random'``.
230 The argument ``color_format`` controls in which color model the color is
231 represented. Valid values are ``'hsv'``, ``'hsl'``, ``'rgb'``, or
232 ``'hex'`` (default).
234 :sample: hue='red'
235 :sample: luminosity='light'
236 :sample: hue=(100, 200), color_format='rgb'
237 :sample: hue='orange', luminosity='bright'
238 :sample: hue=135, luminosity='dark', color_format='hsv'
239 :sample: hue=(300, 20), luminosity='random', color_format='hsl'
240 """
241 return RandomColor(self.generator).generate(
242 hue=hue,
243 luminosity=luminosity,
244 color_format=color_format,
245 )