o
    hS                     @   s  d Z ddlZddlZddlmZmZ ddlmZmZm	Z	m
Z
mZmZmZ ddlmZmZmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ee
eeef e
eeeef f Zeee f Z!ee
eeef e
eeeef f Z"G dd dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*de$ e% e$ e% e$ de% e& d
Z+de' e% e( e% e( de% e& d
Z,de$ de$ de$ de& d	Z-de' de( de( de& d	Z.dd dD Z/dej0 Z1eded G d!d" d"ej2Z3d#e
ed$f d%e#fd&d'Z4d#e d%e#fd(d)Z5dTd*eee f d+eee f d,eee f d-e	e d%e#f
d.d/Z6dUd#eee f d1ed%efd2d3Z7d#ede eef d%e	e fd4d5Z8dTd6e d7e d8e d9e d-e	e d%e#fd:d;Z9d<ed%efd=d>Z:i d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`i dadbdcdddedfdgdDdhdidjdkdldmdndodpdqdrdodsdtdudvdwdxdydzd{d|d}d~ddi dddddddddd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ddddddi ddÓddœddǓddɓdd˓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dd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$i d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d>d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQZ;dRdS e;< D Z=dS (V  aZ  Color definitions are used as per the CSS3
[CSS Color Module Level 3](http://www.w3.org/TR/css3-color/#svg-color) specification.

A few colors have multiple names referring to the sames colors, eg. `grey` and `gray` or `aqua` and `cyan`.

In these cases the _last_ color when sorted alphabetically takes preferences,
eg. `Color((0, 255, 255)).as_named() == 'cyan'` because "cyan" comes after "aqua".

Warning: Deprecated
    The `Color` class is deprecated, use `pydantic_extra_types` instead.
    See [`pydantic-extra-types.Color`](../usage/types/extra_types/color_types.md)
    for more information.
    N)
hls_to_rgb
rgb_to_hls)AnyCallableOptionalTupleTypeUnioncast)
CoreSchemaPydanticCustomErrorcore_schema)
deprecated   )_repr)GetJsonSchemaHandler)JsonSchemaValue)PydanticDeprecatedSince20c                	   @   sD   e Zd ZdZdZdedededee fddZd	ed
efddZ	dS )RGBAz1Internal use only as a representation of a color.rgbalpha_tupler   r   r   r   c                 C   s*   || _ || _|| _|| _||||f| _d S Nr   )selfr   r   r   r    r   K/var/www/Befach/backend/venv/lib/python3.10/site-packages/pydantic/color.py__init__&   s
   zRGBA.__init__itemreturnc                 C   s
   | j | S r   )r   )r   r    r   r   r   __getitem__.   s   
zRGBA.__getitem__N)
__name__
__module____qualname____doc__	__slots__floatr   r   r   r"   r   r   r   r   r   !   s
    r   z(\d{1,3}(?:\.\d+)?)z\s*,\s*z(\d(?:\.\d+)?|\.\d+|\d{1,2}%)z((-?\d+(?:\.\d+)?|-?\.\d+)(deg|rad|turn)?z(\d{1,3}(?:\.\d+)?)%z8\s*(?:#|0x)?([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])?\s*zD\s*(?:#|0x)?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})?\s*z\s*rgba?\(\s*z(?:z
)?\s*\)\s*z\s*hsla?\(\s*z\s+z
(?:\s*/\s*c                 C   s   h | ]	}t |d  dqS )      int.0cr   r   r   	<setcomp>D   s    r0   0123456789abcdefr)   zThe `Color` class is deprecated, use `pydantic_extra_types` instead. See https://docs.pydantic.dev/latest/api/pydantic_extra_types_color/.)categoryc                   @   sT  e Zd ZdZdZdeddfddZedej	d	e
defd
dZdefddZdddedefddZdefddZdefddZdddee defddZdefddZdddee defddZdefdd Zed!ee d	eege	f dej	fd"d#Zed$ed%edd fd&d'Zdefd(d)Z d2d+d,Z!d-edefd.d/Z"de#fd0d1Z$dS )3ColorzRepresents a color.)	_original_rgbavaluer!   Nc                 C   sf   |  |  t |ttfrt|| _nt |trt|| _nt |tr)|j| _|j}nt	dd|| _d S )Ncolor_errorzAvalue is not a valid color: value must be a tuple, list or string)

isinstancetuplelistparse_tupler5   str	parse_strr3   r4   r   )r   r6   r   r   r   r   R   s   


zColor.__init__r   handlerc                 C   s   i }|j ddd |S )Nstringcolor)typeformat)update)clsr   r>   field_schemar   r   r   __get_pydantic_json_schema__d   s   z"Color.__get_pydantic_json_schema__c                 C   s   | j S )z!Original value passed to `Color`.)r4   r   r   r   r   originall   s   zColor.originalFfallbackrJ   c             
   C   sr   | j jdu r5tttttf |  }zt| W S  ty4 } z|r+|  W  Y d}~S t	d|d}~ww |  S )a<  Returns the name of the color if it can be found in `COLORS_BY_VALUE` dictionary,
        otherwise returns the hexadecimal representation of the color or raises `ValueError`.

        Args:
            fallback: If True, falls back to returning the hexadecimal representation of
                the color instead of raising a ValueError when no named color is found.

        Returns:
            The name of the color, or the hexadecimal representation of the color.

        Raises:
            ValueError: When no named color is found and fallback is `False`.
        Nz=no named color found, use fallback=True, as_hex() or as_rgb())
r5   r   r
   r   r,   as_rgb_tupleCOLORS_BY_VALUEKeyErroras_hex
ValueError)r   rJ   rgber   r   r   as_namedp   s   

zColor.as_namedc                    s   dd | j dd D }| j jdur|t| j j ddd |D  tdd |D r@d fd	dtd
t dD  d  S )aS  Returns the hexadecimal representation of the color.

        Hex string representing the color can be 3, 4, 6, or 8 characters depending on whether the string
        a "short" representation of the color is possible and whether there's an alpha channel.

        Returns:
            The hexadecimal representation of the color.
        c                 S   s   g | ]}t |qS r   float_to_255r-   r   r   r   
<listcomp>   s    z Color.as_hex.<locals>.<listcomp>N    c                 s   s    | ]}|d V  qdS )02xNr   r.   vr   r   r   	<genexpr>       zColor.as_hex.<locals>.<genexpr>c                 s   s    | ]}|t v V  qd S r   )repeat_colorsr-   r   r   r   r[      r\   c                 3   s    | ]} | V  qd S r   r   r-   rN   r   r   r[      r\   r   r)   #)r5   r   appendrT   joinallrangelen)r   valuesr   r^   r   rN      s   	$zColor.as_hexc              
   C   s|   | j jdu rdt| j j dt| j j dt| j j dS dt| j j dt| j j dt| j j dt|  d d	S )zFColor as an `rgb(<r>, <g>, <b>)` or `rgba(<r>, <g>, <b>, <a>)` string.Nzrgb(, )zrgba(r)   )r5   r   rT   r   r   r   round_alpha_floatrG   r   r   r   as_rgb   s   0,zColor.as_rgbr   r   c                C   sj   dd | j dd D \}}}|du r&| j jdu r|||fS ||||  fS |r0||||  fS |||fS )a  Returns the color as an RGB or RGBA tuple.

        Args:
            alpha: Whether to include the alpha channel. There are three options for this input:

                - `None` (default): Include alpha only if it's set. (e.g. not `None`)
                - `True`: Always include alpha.
                - `False`: Always omit alpha.

        Returns:
            A tuple that contains the values of the red, green, and blue channels in the range 0 to 255.
                If alpha is included, it is in the range 0 to 1.
        c                 s       | ]}t |V  qd S r   rS   r-   r   r   r   r[      r\   z%Color.as_rgb_tuple.<locals>.<genexpr>NrV   )r5   r   ri   )r   r   r   r   r   r   r   r   rK      s   

zColor.as_rgb_tuplec              
   C   s   | j jdu r | jdd\}}}d|d dd|dd|dd	S | jd
d\}}}}d|d dd|dd|ddt|d d		S )zEColor as an `hsl(<h>, <s>, <l>)` or `hsl(<h>, <s>, <l>, <a>)` string.NFrk   zhsl(h  z0.0frf   z0.0%rg   Tr)   )r5   r   as_hsl_tuplerh   )r   hsliar   r   r   as_hsl   s
   ".zColor.as_hslc                C   sj   t | jj| jj| jj\}}}|du r&| jjdu r|||fS ||||  fS |r0||||  fS |||fS )aS  Returns the color as an HSL or HSLA tuple.

        Args:
            alpha: Whether to include the alpha channel.

                - `None` (default): Include the alpha channel only if it's set (e.g. not `None`).
                - `True`: Always include alpha.
                - `False`: Always omit alpha.

        Returns:
            The color as a tuple of hue, saturation, lightness, and alpha (if included).
                All elements are in the range 0 to 1.

        Note:
            This is HSL as used in HTML and most other places, not HLS as used in Python's `colorsys`.
        N)r   r5   r   r   r   r   ri   )r   r   ro   lrp   r   r   r   rn      s   

zColor.as_hsl_tuplec                 C   s   | j jd u rdS | j jS )Nr   )r5   r   rG   r   r   r   ri      s   zColor._alpha_floatsourcec                 C   s   t j| jt  dS )N)serialization)r   "with_info_plain_validator_function	_validateto_string_ser_schema)rD   ru   r>   r   r   r   __get_pydantic_core_schema__   s   
z"Color.__get_pydantic_core_schema___Color__input_value_c                 C   s   | |S r   r   )rD   r{   r|   r   r   r   rx      s   zColor._validatec                 C   s   | j ddS )NTrI   )rR   rG   r   r   r   __str__      zColor.__str___repr.ReprArgsc                 C   s    d | j ddfgd|  fg S )NTrI   rP   )rR   rK   rG   r   r   r   __repr_args__   s    zColor.__repr_args__otherc                 C   s   t |to|  | kS r   )r8   r3   rK   )r   r   r   r   r   __eq__   s   zColor.__eq__c                 C   s   t |  S r   )hashrK   rG   r   r   r   __hash__   r~   zColor.__hash__)r!   r   )%r#   r$   r%   r&   r'   	ColorTyper   classmethodr   r   _GetJsonSchemaHandlerr   rF   rH   boolr<   rR   rN   rj   r   
ColorTuplerK   rs   HslColorTuplern   r(   ri   r   r   r   rz   rx   r}   r   r   r,   r   r   r   r   r   r3   H   sD    
	
r3   r6   .r!   c                 C   sv   t | dkrdd | D \}}}t|||dS t | dkr6dd | dd D \}}}t|||t| d S tdd)	zParse a tuple or list to get RGBA values.

    Args:
        value: A tuple or list.

    Returns:
        An `RGBA` tuple parsed from the input tuple.

    Raises:
        PydanticCustomError: If tuple is not valid.
    rV   c                 s   rl   r   parse_color_valuerY   r   r   r   r[     r\   zparse_tuple.<locals>.<genexpr>N   c                 s   rl   r   r   rY   r   r   r   r[     r\   r7   z:value is not a valid color: tuples must have length 3 or 4)rd   r   parse_float_alphar   )r6   r   r   r   r   r   r   r;     s   
r;   c           	      C   sJ  |   }z	t| \}}}W n	 ty   Y nw t|||dS tt|}|rL| ^ }}dd |D \}}}|rCt|d dd }nd}t||||S tt	|}|rx| ^ }}dd |D \}}}|rot|dd }nd}t||||S tt
|ptt|}|rt|  S tt|ptt|}|rt|  S tdd	)
a8  Parse a string representing a color to an RGBA tuple.

    Possible formats for the input string include:

    * named color, see `COLORS_BY_NAME`
    * hex short eg. `<prefix>fff` (prefix can be `#`, `0x` or nothing)
    * hex long eg. `<prefix>ffffff` (prefix can be `#`, `0x` or nothing)
    * `rgb(<r>, <g>, <b>)`
    * `rgba(<r>, <g>, <b>, <a>)`

    Args:
        value: A string representing a color.

    Returns:
        An `RGBA` tuple parsed from the input string.

    Raises:
        ValueError: If the input string cannot be parsed to an RGBA tuple.
    Nc                 s   s    | ]
}t |d  dV  qdS )r)   r*   Nr+   rY   r   r   r   r[   7  s    zparse_str.<locals>.<genexpr>r)   r*      c                 s   s    | ]}t |d V  qdS )r*   Nr+   rY   r   r   r   r[   A  s    r7   zBvalue is not a valid color: string not recognised as a valid color)lowerCOLORS_BY_NAMErM   ints_to_rgbare	fullmatchr_hex_shortgroupsr,   
r_hex_longr_rgbr_rgb_v4_styler_hslr_hsl_v4_style	parse_hslr   )	r6   value_lowerr   r   r   mrP   rr   r   r   r   r   r=     s<   
r=   r   r   r   r   c                 C   s   t t| t|t|t|S )a  Converts integer or string values for RGB color and an optional alpha value to an `RGBA` object.

    Args:
        r: An integer or string representing the red color value.
        g: An integer or string representing the green color value.
        b: An integer or string representing the blue color value.
        alpha: A float representing the alpha value. Defaults to None.

    Returns:
        An instance of the `RGBA` class with the corresponding color and alpha values.
    )r   r   r   )r   r   r   r   r   r   r   r   S  s   r   r   max_valc                 C   sR   zt | }W n ty   tddw d|  kr |kr!|| S  tddd|i)a8  Parse the color value provided and return a number between 0 and 1.

    Args:
        value: An integer or string color value.
        max_val: Maximum range value. Defaults to 255.

    Raises:
        PydanticCustomError: If the value is not a valid color.

    Returns:
        A number between 0 and 1.
    r7   z?value is not a valid color: color values must be a valid numberr   zLvalue is not a valid color: color values must be in the range 0 to {max_val}r   )r(   rO   r   )r6   r   r@   r   r   r   r   b  s   
r   c                 C   s   | du rdS zt | tr| drt| dd d }nt| }W n ty-   tddw t|dr6dS d|  krAdkrB|S  tdd	)
aZ  Parse an alpha value checking it's a valid float in the range 0 to 1.

    Args:
        value: The input value to parse.

    Returns:
        The parsed value as a float, or `None` if the value was None or equal 1.

    Raises:
        PydanticCustomError: If the input value cannot be successfully parsed as a float in the expected range.
    N%d   r7   z>value is not a valid color: alpha values must be a valid floatr   r   zDvalue is not a valid color: alpha values must be in the range 0 to 1)r8   r<   endswithr(   rO   r   mathisclose)r6   r   r   r   r   r   }  s    

r   ro   h_unitssatlightc                 C   sv   t |dt |d}}t| }|dv r|d d }n|dkr%|t t }n|d }t|||\}}	}
t||	|
t|S )a.  Parse raw hue, saturation, lightness, and alpha values and convert to RGBA.

    Args:
        h: The hue value.
        h_units: The unit for hue value.
        sat: The saturation value.
        light: The lightness value.
        alpha: Alpha value.

    Returns:
        An instance of `RGBA`.
    r   >   Ndegrm   radr   )r   r(   radsr   r   r   )ro   r   r   r   r   s_valuel_valueh_valuer   r   r   r   r   r   r     s   r   r/   c                 C   s   t t| d S )a  Converts a float value between 0 and 1 (inclusive) to an integer between 0 and 255 (inclusive).

    Args:
        c: The float value to be converted. Must be between 0 and 1 (inclusive).

    Returns:
        The integer equivalent of the given float value rounded to the nearest whole number.

    Raises:
        ValueError: If the given float value is outside the acceptable range of 0 to 1 (inclusive).
    r   )r,   rh   )r/   r   r   r   rT     s   rT   	aliceblue)      r   antiquewhite)         aqua)r   r   r   
aquamarine)   r      azure)r   r   r   beige)   r      bisque)r         black)r   r   r   blanchedalmond)r   r      blue)r   r   r   
blueviolet)   +      brown)   *   r   	burlywood)         	cadetblue)_         
chartreuse)r   r   r   	chocolate)   i      coral)r   r   P   cornflowerblue)r         cornsilk)r   r   r   crimson)r      <   cyandarkblue)r   r      darkcyan)r   r   r   darkgoldenrod)r         darkgray)   r   r   	darkgreen)r   r   r   darkgrey	darkkhaki)      k   darkmagenta)r   r   r   darkolivegreen)U   r   /   
darkorange)r      r   
darkorchid)   2      darkred)r   r   r   
darksalmon)      z   darkseagreen)      r  darkslateblue)H   =   r   darkslategray)r   O   r  darkslategreydarkturquoise)r         
darkviolet)   r      deeppink)r   r      deepskyblue)r      r   dimgray)r   r   r   dimgrey
dodgerblue)r      r   	firebrick)   "   r  floralwhite)r   r   r   forestgreen)r  r   r  fuchsia)r   r   r   	gainsboro)r   r   r   
ghostwhite)r   r   r   gold)r   r   r   	goldenrod)   r       gray)   r$  r$  green)r   r$  r   greenyellow)   r   r   greyhoneydew)r   r   r   hotpink)r   r      	indianred)r   \   r-  indigo)K   r      ivory)r   r   r   khaki)r      r   lavender)r3  r3  r   lavenderblush)r   r   r   	lawngreen)|      r   lemonchiffon)r   r   r   	lightblue)r'     r3  
lightcoral)r   r$  r$  	lightcyan)   r   r   lightgoldenrodyellow)r   r   r   	lightgray)r  r  r  
lightgreen)r     r  	lightgrey	lightpink)r         lightsalmon)r   r   r   lightseagreen)r"  r     lightskyblue)r   r
  r   lightslategray)w      r   lightslategreylightsteelblue)   r   r   lightyellow)r   r   r>  lime)r   r   r   	limegreen)r   r   r   linen)r   r   r3  magentamaroon)r$  r   r   mediumaquamarine)f   r   rI  
mediumblue)r   r   r   mediumorchid)   r   r  mediumpurple)r  p      mediumseagreen)r      q   mediumslateblue){   h   rB  mediumspringgreen)r   r      mediumturquoise)r  r  r   mediumvioletred)         midnightblue)   rm  r]  	mintcream)r   r   r   	mistyrose)r   r      moccasin)r   r      navajowhite)r   r   r'  navy)r   r   r$  oldlace)   r   r3  olive)r$  r$  r   	olivedrab)r      #   orange)r   r   r   	orangered)r   E   r   orchid)r!  r]     palegoldenrod)rB     rI  	palegreen)      r  paleturquoise)   rB  rB  palevioletred)r^  r]  r  
papayawhip)r         	peachpuff)r   r!     peru)r   rk  ?   pink)r         plum)   r   r  
powderblue)rP  r>  r3  purple)r$  r   r$  red)r   r   r   	rosybrown)r  r  r  	royalblue)A   r   rp  saddlebrown)r   r}     salmon)r   r$  r   
sandybrown)      `   seagreen).   r   W   seashell)r   r   rB  sienna)r   R   -   silver)r  r  r  skyblue)r   r
  r   	slateblue)j   Z   r   	slategray)r]  r$  r  	slategreysnow)r   r   r   springgreen)r   r   r   	steelblue)F   r0  r+  )r   r+  r   )r   r$  r$  )r;  r  r;  )r   c   G   )@   r>     )rB  r0  rB  )r   r   r`  )r   r   r   )r   r   r   )r   r   r   )rf  r   r   )tantealthistletomato	turquoisevioletwheatwhite
whitesmokeyellowyellowgreenc                 C   s   i | ]\}}||qS r   r   )r.   krZ   r   r   r   
<dictcomp>\  s    r  r   )r   )>r&   r   r   colorsysr   r   typingr   r   r   r   r   r	   r
   pydantic_corer   r   r   typing_extensionsr   	_internalr   #_internal._schema_generation_sharedr   r   json_schemar   warningsr   r,   r(   r   r<   r   r   r   _r_255_r_comma_r_alpha_r_h_r_slr   r   r   r   r   r   r]   pir   Representationr3   r;   r=   r   r   r   r   rT   r   itemsrL   r   r   r   r   <module>   s   $""&&
 6>;""*	
 !"#$%&'()*+,-./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{|}~                 	  
 
 