o
    ic                     @   s  d Z ddlZddlZddlmZmZmZ dZdedefddZ	e
d	Zd
ZdZdZdZeeeefZdjdedZeddefdefdefgZeddefdefdefgZeddefdefdefgZeeeeeeef f Zeeeeeef f Zi dddddddddddd d!d"d#d$d%d&d'd(d)d*dd+d,d-d.d/d0d1d2d3ZeZd4d5ieZi d6d7d8d9ddd:d;d<d=d>d?d@dAdddBdCdddDdEdFdGdHdIdJdKdLdMdNdOdPdQi dRdSdTdUdVdWdXddYdZd[d\d]d^d_d`dad`dbdcdddedfdgdhdidjdkdldmdndodpdqi drdsdtdudvdwdxdwdydzd{d|d}d~ddddddddddddddddddddi dddddd dd ddddddddddddddddddddddddddi ddddddddddddddddddddddddddēddƓd!d"ddȓddʓi ddd#d$dd͓ddϓddѓddӓddՓddדddٓddۓddݓddߓddddddddd%d&i ddd'd(ddd4d5ddddddddddddddddddddd dddd)d*i dd+dddddd	d
dddddddddd,d-dddddddddddddd d!d/d"d#d$d%d&d1d'd3d(d)Ze	eZeZ e	eZ!e	eZ"d_e"d`< dve"dw< de"d< de"d < de"d< de"d< de"d< d*edefd+d,Z#d-edefd.d/Z$d0edefd1d2Z%d-edefd3d4Z&d0edefd5d6Z'efd7ed8edefd9d:Z(efd7ed8edefd;d<Z)efd7ed8edefd=d>Z*efd*ed8edefd?d@Z+d*edefdAdBZ,d*edefdCdDZ-efd0ed8edefdEdFZ.d0edefdGdHZ/d0edefdIdJZ0efdKed8edefdLdMZ1dKedefdNdOZ2dPedefdQdRZ3dKedefdSdTZ4dUedefdVdWZ5dXedefdYdZZ6dUedefd[d\Z7dS (]  a  
Utility functions for working with the color names and color value
formats defined by the HTML and CSS specifications for use in
documents on the Web.

See documentation (in docs/ directory of source distribution) for
details of the supported formats, conventions and conversions.

    N)
NamedTupleTupleUnionz1.11.1dreturnc                 C   s   dd |   D S )z
    Internal helper for generating reverse mappings; given a
    dictionary, returns a new dictionary with keys and values swapped.

    c                 S   s   i | ]\}}||qS  r   ).0keyvaluer   r   D/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/webcolors.py
<dictcomp>   s    z _reversedict.<locals>.<dictcomp>)items)r   r   r   r   _reversedict   s   r   z"^#([a-fA-F0-9]{3}|[a-fA-F0-9]{6})$html4css2css21css3zl{{spec}} is not a supported specification for color name lookups; supported specifications are: {supported}.,)	supported
IntegerRGBredgreenblue
PercentRGBHTML5SimpleColoraquaz#00ffffblackz#000000z#0000fffuchsiaz#ff00ffz#008000grayz#808080limez#00ff00maroonz#800000navyz#000080olivez#808000purplez#800080z#ff0000silverz#c0c0c0tealz#008080whitez#ffffffyellowz#ffff00orangez#ffa500	alicebluez#f0f8ffantiquewhitez#faebd7
aquamarinez#7fffd4azurez#f0ffffbeigez#f5f5dcbisquez#ffe4c4blanchedalmondz#ffebcd
bluevioletz#8a2be2brownz#a52a2a	burlywoodz#deb887	cadetbluez#5f9ea0
chartreusez#7fff00	chocolatez#d2691ecoralz#ff7f50cornflowerbluez#6495edcornsilkz#fff8dccrimsonz#dc143ccyandarkbluez#00008bdarkcyanz#008b8bdarkgoldenrodz#b8860bdarkgrayz#a9a9a9darkgrey	darkgreenz#006400	darkkhakiz#bdb76bdarkmagentaz#8b008bdarkolivegreenz#556b2f
darkorangez#ff8c00
darkorchidz#9932ccdarkredz#8b0000
darksalmonz#e9967adarkseagreenz#8fbc8fdarkslatebluez#483d8bdarkslategrayz#2f4f4fdarkslategreydarkturquoisez#00ced1
darkvioletz#9400d3deeppinkz#ff1493deepskybluez#00bfffdimgrayz#696969dimgrey
dodgerbluez#1e90ff	firebrickz#b22222floralwhitez#fffaf0forestgreenz#228b22	gainsboroz#dcdcdc
ghostwhitez#f8f8ffgoldz#ffd700	goldenrodz#daa520greygreenyellowz#adff2fhoneydewz#f0fff0hotpinkz#ff69b4	indianredz#cd5c5cindigoz#4b0082ivoryz#fffff0khakiz#f0e68clavenderz#e6e6falavenderblushz#fff0f5	lawngreenz#7cfc00lemonchiffonz#fffacd	lightbluez#add8e6
lightcoralz#f08080	lightcyanz#e0fffflightgoldenrodyellowz#fafad2	lightgrayz#d3d3d3	lightgrey
lightgreenz#90ee90	lightpinkz#ffb6c1lightsalmonz#ffa07alightseagreenz#20b2aalightskybluez#87cefalightslategrayz#778899lightslategreylightsteelbluez#b0c4delightyellowz#ffffe0	limegreenz#32cd32linenz#faf0e6magentamediumaquamarinez#66cdaa
mediumbluez#0000cdmediumorchidz#ba55d3mediumpurplez#9370dbmediumseagreenz#3cb371mediumslatebluez#7b68eemediumspringgreenz#00fa9amediumturquoisez#48d1ccmediumvioletredz#c71585midnightbluez#191970	mintcreamz#f5fffa	mistyrosez#ffe4e1moccasinz#ffe4b5navajowhitez#ffdeadoldlacez#fdf5e6	olivedrabz#6b8e23	orangeredz#ff4500orchidz#da70d6palegoldenrodz#eee8aa	palegreenz#98fb98paleturquoisez#afeeeepalevioletredz#db7093
papayawhipz#ffefd5	peachpuffz#ffdab9peruz#cd853fpinkz#ffc0cbplumz#dda0dd
powderbluez#b0e0e6	rosybrownz#bc8f8f	royalbluez#4169e1saddlebrownz#8b4513salmonz#fa8072
sandybrownz#f4a460seagreenz#2e8b57seashellz#fff5eesiennaz#a0522dskybluez#87ceeb	slatebluez#6a5acd	slategrayz#708090	slategreysnowz#fffafaspringgreenz#00ff7f	steelbluez#4682b4z#d2b48cz#d8bfd8z#ff6347z#40e0d0z#ee82eez#f5deb3z#f5f5f5z#9acd32)tanr%   thistletomato	turquoisevioletwheatr&   
whitesmoker'   yellowgreen	hex_valuec                 C   sX   t | }|du rtd| |d}t|dkr%ddd |D }d| S )	zF
    Normalize a hexadecimal color value to 6 digits, lowercase.

    Nz,'{}' is not a valid hexadecimal color value.       c                 s   s    | ]}d | V  qdS )   Nr   )r   sr   r   r   	<genexpr>4      z normalize_hex.<locals>.<genexpr>z#{})HEX_COLOR_REmatch
ValueErrorformatgrouplenjoinlower)r   r   
hex_digitsr   r   r   normalize_hex(  s   

r   r
   c                 C   s   | dk rdS | dkrdS | S )zw
    Internal normalization function for clipping integer values into
    the permitted range (0-255, inclusive).

    r      r   )r
   r   r   r   _normalize_integer_rgb8  s   r   rgb_tripletc                 C      t dd | D S )zn
    Normalize an integer ``rgb()`` triplet so that all values are
    within the range 0-255 inclusive.

    c                 s       | ]}t |V  qd S N)r   r   r
   r   r   r   r   G  r   z,normalize_integer_triplet.<locals>.<genexpr>)r   _maker   r   r   r   normalize_integer_tripletA     r   c                 C   sH   |  dd } d| v rt| nt| }|dk rdS |dkrdS d|S )zy
    Internal normalization function for clipping percent values into
    the permitted range (0%-100%, inclusive).

    %r   .0%d   100%z{}%)splitfloatintr   )r
   percentr   r   r   _normalize_percent_rgbJ  s   "r   c                 C   r   )zr
    Normalize a percentage ``rgb()`` triplet so that all values are
    within the range 0%-100% inclusive.

    c                 s   r   r   )r   r   r   r   r   r   \  r   z,normalize_percent_triplet.<locals>.<genexpr>)r   r   r   r   r   r   normalize_percent_tripletV  r   r   namespecc                 C   s\   |t vrttj|d|  }ttttt	t
tti| |}|du r,tdj| |d|S )a5  
    Convert a color name to a normalized hexadecimal color value.

    The optional keyword argument ``spec`` determines which
    specification's list of color names will be used. The default is
    CSS3.

    When no color of that name exists in the given specification,
    ``ValueError`` is raised.

    r   Nz2'{name}' is not defined as a named color in {spec}r   r   )SUPPORTED_SPECIFICATIONSr   SPECIFICATION_ERROR_TEMPLATEr   r   CSS2CSS2_NAMES_TO_HEXCSS21CSS21_NAMES_TO_HEXCSS3CSS3_NAMES_TO_HEXHTML4HTML4_NAMES_TO_HEXget)r   r   
normalizedr   r   r   r   name_to_hexc  s&   r   c                 C      t t| |dS )z|
    Convert a color name to a 3-tuple of integers suitable for use in
    an ``rgb()`` triplet specifying that color.

    r   )
hex_to_rgbr   r   r   r   r   name_to_rgb     r   c                 C   r   )z
    Convert a color name to a 3-tuple of percentages suitable for use
    in an ``rgb()`` triplet specifying that color.

    r   )rgb_to_rgb_percentr   r   r   r   r   name_to_rgb_percent  r   r   c                 C   sZ   |t vrttj|dt| }ttttt	t
tti| |}|du r+td| ||S )aj  
    Convert a hexadecimal color value to its corresponding normalized
    color name, if any such name exists.

    The optional keyword argument ``spec`` determines which
    specification's list of color names will be used. The default is
    CSS3.

    When no color name for the value is found in the given
    specification, ``ValueError`` is raised.

    r   Nz$'{}' has no defined color name in {})r   r   r   r   r   r   CSS2_HEX_TO_NAMESr   CSS21_HEX_TO_NAMESr   CSS3_HEX_TO_NAMESr   HTML4_HEX_TO_NAMESr   )r   r   r   r   r   r   r   hex_to_name  s   r   c                 C   s2   t t| dd d}t|d? |d? d@ |d@ S )z
    Convert a hexadecimal color value to a 3-tuple of integers
    suitable for use in an ``rgb()`` triplet specifying that color.

    r   N      r   )r   r   r   )r   	int_valuer   r   r   r     s   r   c                 C   s   t t| S )z
    Convert a hexadecimal color value to a 3-tuple of percentages
    suitable for use in an ``rgb()`` triplet representing that color.

    )r   r   )r   r   r   r   hex_to_rgb_percent  s   r   c                 C      t tt| |dS )ao  
    Convert a 3-tuple of integers, suitable for use in an ``rgb()``
    color triplet, to its corresponding normalized color name, if any
    such name exists.

    The optional keyword argument ``spec`` determines which
    specification's list of color names will be used. The default is
    CSS3.

    If there is no matching name, ``ValueError`` is raised.

    r   )r   
rgb_to_hexr   )r   r   r   r   r   rgb_to_name  s   r   c                 C   s   dj t|  S )z
    Convert a 3-tuple of integers, suitable for use in an ``rgb()``
    color triplet, to a normalized hexadecimal value for that color.

    z#{:02x}{:02x}{:02x})r   r   r   r   r   r   r     s   r   c                    s.   ddddddd t  fdd	t| D S )
am  
    Convert a 3-tuple of integers, suitable for use in an ``rgb()``
    color triplet, to a 3-tuple of percentages suitable for use in
    representing that color.

    This function makes some trade-offs in terms of the accuracy of
    the final representation; for some common integer values,
    special-case logic is used to ensure a precise result (e.g.,
    integer 128 will always convert to '50%', integer 32 will always
    convert to '12.5%'), but for all other values a standard Python
    ``float`` is used and rounded to two decimal places, which may
    result in a loss of precision for some values.

    r   z50%z25%z12.5%z6.25%r   )r      @       r   r   c                 3   s*    | ]}  |d |d d V  qdS )z{:.02f}%g     o@r   N)r   r   )r   r   specialsr   r   r     s
    
z%rgb_to_rgb_percent.<locals>.<genexpr>)r   r   r   r   r   r   r   r     s   r   rgb_percent_tripletc                 C   r   )ar  
    Convert a 3-tuple of percentages, suitable for use in an ``rgb()``
    color triplet, to its corresponding normalized color name, if any
    such name exists.

    The optional keyword argument ``spec`` determines which
    specification's list of color names will be used. The default is
    CSS3.

    If there is no matching name, ``ValueError`` is raised.

    r   )r   rgb_percent_to_rgbr   )r   r   r   r   r   rgb_percent_to_name  s   r   c                 C   s   t tt| S )z
    Convert a 3-tuple of percentages, suitable for use in an ``rgb()``
    color triplet, to a normalized hexadecimal color value for that
    color.

    )r   r   r   r   r   r   r   rgb_percent_to_hex  s   
r   r   c                 C   s"   t tt| dd d d S )zk
    Internal helper for converting a percentage value to an integer
    between 0 and 255 inclusive.

    r   r   r   r   )r   roundr   r   )r   r   r   r   _percent_to_integer#  s   "r  c                 C   s   t ttt| S )a-  
    Convert a 3-tuple of percentages, suitable for use in an ``rgb()``
    color triplet, to a 3-tuple of integers suitable for use in
    representing that color.

    Some precision may be lost in this conversion. See the note
    regarding precision for ``rgb_to_rgb_percent()`` for details.

    )r   r   mapr  r   r   r   r   r   r   ,  s   
r   inputc                 C   s   t | trt| dkrtd| dstdtdd | dd D s)td	tt| dd
 dt| d
d dt| dd dS )zT
    Apply the simple color parsing algorithm from section 2.4.6 of
    HTML5.

       zMAn HTML5 simple color must be a Unicode string exactly seven characters long.#zAAn HTML5 simple color must begin with the character '#' (U+0023).c                 s       | ]}|t jv V  qd S r   string	hexdigitsr   cr   r   r   r   b      z+html5_parse_simple_color.<locals>.<genexpr>r   Nz@An HTML5 simple color must contain exactly six ASCII hex digits.r   r      )
isinstancestrr   r   
startswithallr   r   )r  r   r   r   html5_parse_simple_colorI  s   

0r  simple_colorc                 C   s@   | \}}}d}d}|| |7 }|| |7 }|| |7 }|S )z`
    Apply the serialization algorithm for a simple color from section
    2.4.6 of HTML5.

    r  z{:02x})r   )r  r   r   r   resultformat_stringr   r   r   html5_serialize_simple_colorx  s   
r  c                 C   s  t | ts	td| dkrtd|  } |  dkrtdt|  }|dur.t|S t| dkrc| 	drct
d	d
 | dd D rctt| d dd t| d dd t| d dd }|S ddd
 | D } t| dkry| dd } | 	dr| dd } ddd
 | D } t| dkst| d dkr| d7 } t| dkst| d dkstt| d }| d| }| ||d  }| |d d }|dkr||d d ||d d ||d d }}}d}|dkr8|d dkr8|d dkr8|d dkr8|dd |dd |dd }}}|d8 }|dkr8|d dkr8|d dkr8|d dks|dkrQ|dd |dd |dd }}}tt|dt|dt|dS )zT
    Apply the legacy color parsing algorithm from section 2.4.6 of
    HTML5.

    z>HTML5 legacy color parsing requires a Unicode string as input.r   z;HTML5 legacy color parsing forbids empty string as a value.transparentz<HTML5 legacy color parsing forbids "transparent" as a value.N   r  c                 s   r  r   r  r
  r   r   r   r     r  z+html5_parse_legacy_color.<locals>.<genexpr>r   r      r   r   c                 s   s$    | ]}t |d krdn|V  qdS )i  00N)ordr
  r   r   r   r     s   " r   c                 s   s"    | ]}|t jv r|nd V  qdS )0Nr  r
  r   r   r   r     s     r   r  r   )r  r  r   stripr   r   r   r  r   r  r  r   r   r   )r  keyword_hexr  lengthr   r   r   r   r   r   html5_parse_legacy_color  sX   
0
44(4
(r   )8__doc__rer  typingr   r   r   __version__dictr   compiler   r   r   r   r   r   r   r   r   r   r   r  r   r   IntTuplePercentTupler   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r  r  r   r   r   r   r   <module>   s   

		
	
 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~                 	  
 
 		"""	"
"	"#	/