a
    é´«jù1  ã                   @  s”   d Z ddlmZ ddlZddlmZmZ ddlZddlm	Z	 ddl
mZ er`ddlmZmZmZ dd	d
œdd„Zddd	dœdd„ZG dd„ dƒZdS )zN
Utilities for interpreting CSS from Stylers for formatting non-HTML outputs.
é    )ÚannotationsN)ÚTYPE_CHECKINGÚCallable)Ú
CSSWarning)Úfind_stack_level)Ú	GeneratorÚIterableÚIteratorÚstrr   )Úprop_fmtÚreturnc                   s   dddœ‡ fdd„}|S )a)  
    Wrapper to expand shorthand property into top, right, bottom, left properties

    Parameters
    ----------
    side : str
        The border side to expand into properties

    Returns
    -------
        function: Return to call when a 'border(-{side}): {value}' string is encountered
    r
   ú&Generator[tuple[str, str], None, None]©Úvaluer   c              	   3  s~   |  ¡ }z| jt|ƒ }W n4 tyN   tjd|› d|› d�ttƒ d� Y dS 0 t| j	|ƒD ]\}}ˆ  
|¡|| fV  q\dS )a<  
        Expand shorthand property into side-specific property (top, right, bottom, left)

        Parameters
        ----------
            prop (str): CSS property name
            value (str): String token for property

        Yields
        ------
            Tuple (str, str): Expanded property, value
        zCould not expand "z: ú"©Ú
stacklevelN)ÚsplitÚSIDE_SHORTHANDSÚlenÚKeyErrorÚwarningsÚwarnr   r   ÚzipÚSIDESÚformat)ÚselfÚpropr   ÚtokensÚmappingÚkeyÚidx©r   © úT/var/www/html/laksyashrimp/venv/lib/python3.9/site-packages/pandas/io/formats/css.pyÚexpand&   s    ýz_side_expander.<locals>.expandr#   )r   r%   r#   r"   r$   Ú_side_expander   s    r&   Ú )Úsider   c                   s*   ˆ dkrdˆ › �‰ dddœ‡ fdd„}|S )a.  
    Wrapper to expand 'border' property into border color, style, and width properties

    Parameters
    ----------
    side : str
        The border side to expand into properties

    Returns
    -------
        function: Return to call when a 'border(-{side}): {value}' string is encountered
    r'   ú-r
   r   r   c                 3  sÞ   |  ¡ }t|ƒdks t|ƒdkr:tjd|› d�ttƒ d� dˆ› d�ddˆ› d	�d
dˆ› d�di}|D ]^‰ ˆ  ¡ | jv rŠˆ |dˆ› d	�< qft‡ fdd„| j	D ƒƒr´ˆ |dˆ› d�< qfˆ |dˆ› d�< qf|  
| ¡ ¡E dH  dS )aV  
        Expand border into color, style, and width tuples

        Parameters
        ----------
            prop : str
                CSS property name passed to styler
            value : str
                Value passed to styler for property

        Yields
        ------
            Tuple (str, str): Expanded property, value
        r   é   zToo many tokens provided to "z" (expected 1-3)r   Úborderz-colorÚblackz-styleÚnoneú-widthÚmediumc                 3  s   | ]}|ˆ   ¡ v V  qd S ©N)Úlower)Ú.0Úratio©Útokenr#   r$   Ú	<genexpr>s   ó    z3_border_expander.<locals>.expand.<locals>.<genexpr>N)r   r   r   r   r   r   r1   ÚBORDER_STYLESÚanyÚBORDER_WIDTH_RATIOSÚatomizeÚitems)r   r   r   r   Zborder_declarations©r(   r4   r$   r%   S   s$    
ýýz _border_expander.<locals>.expandr#   )r(   r%   r#   r=   r$   Ú_border_expanderC   s    
)r>   c                   @  s€  e Zd ZdZddddddddd	d
ddœZe ¡ Ze ddddddddddddœ¡ e ¡ Ze ddi¡ e ¡ Z	e	 dddddœ¡ g d¢Z
g d¢g d ¢g d!¢g d"¢d#œZd$Zi d%d&„ d'D ƒ¥d(d&„ d)D ƒ¥ed*ƒed+ƒd,œ¥ZdPd.d/d0d1œd2d3„Zd0d0d0d4œd5d6„Zd0d0d0d4œd7d8„Zd0d9d:œd;d<„Zd=d>d?œd@dA„Zd0d0d:œdBdC„Zd-efd=dDœdEdF„ZdGdHdIœdJdK„Zd=dLdMœdNdO„Zd-S )QÚCSSResolverzH
    A callable for parsing and resolving CSS to atomic properties.
    )Úpté   )ÚemrA   )r@   é   )rB   ç      à?)r@   g      è?)r@   éH   )ÚingL&“Éd2Ù?)rF   g
…B¡P(¤?)Úmmg      Ð?)rB   r   )r@   rB   ÚremÚexÚpxZpcrF   ÚcmrG   Úqú	!!default)rB   g{®Gáz„?)rH   rD   )rH   g      ä?)rH   gš™™™™™é?)rH   rA   )rH   g      ò?)rH   g      ø?)rH   é   )rB   g«ªªªªªê?)rB   g333333ó?)ú%zxx-smallzx-smallÚsmallr/   Zlargezx-largezxx-largeZsmallerZlargerrM   r-   )r@   r   )rJ   é   )rJ   rN   )rJ   rA   )r-   Zthickr/   Zthin)r-   ÚhiddenZdottedZdashedZsolidÚdoubleZgrooveZridgeZinsetZoutsetZmediumdashdotZ
dashdotdotZhairZmediumdashdotdotZdashdotZslantdashdotZmediumdashed)r   r   r   r   )r   rA   r   rA   )r   rA   rN   rA   )r   rA   rN   r*   )rA   rN   r*   rQ   )ÚtopÚrightÚbottomÚleftc                 C  s$   i | ]}|rd |› �ndt |ƒ“qS )úborder-r+   )r>   ©r2   r   r#   r#   r$   Ú
<dictcomp>Ð   s   ÿzCSSResolver.<dictcomp>)r'   rT   rU   rV   rW   c                 C  s"   i | ]}d |› �t d|› �ƒ“qS )rX   zborder-{:s}-)r&   rY   r#   r#   r$   rZ   Ô   s   ÿ)ÚcolorÚstyleÚwidthzmargin-{:s}zpadding-{:s})ÚmarginÚpaddingNzstr | Iterable[tuple[str, str]]zdict[str, str] | Nonezdict[str, str])ÚdeclarationsÚ	inheritedr   c                 C  sP   t |tƒr|  |¡}t|  |¡ƒ}|du r.i }|  ||¡}|  ||¡}|  |¡S )a£  
        The given declarations to atomic properties.

        Parameters
        ----------
        declarations_str : str | Iterable[tuple[str, str]]
            A CSS string or set of CSS declaration tuples
            e.g. "font-weight: bold; background: blue" or
            {("font-weight", "bold"), ("background", "blue")}
        inherited : dict, optional
            Atomic properties indicating the inherited style context in which
            declarations_str is to be resolved. ``inherited`` should already
            be resolved, i.e. valid output of this method.

        Returns
        -------
        dict
            Atomic CSS 2.2 properties.

        Examples
        --------
        >>> resolve = CSSResolver()
        >>> inherited = {'font-family': 'serif', 'font-weight': 'bold'}
        >>> out = resolve('''
        ...               border-color: BLUE RED;
        ...               font-size: 1em;
        ...               font-size: 2em;
        ...               font-weight: normal;
        ...               font-weight: inherit;
        ...               ''', inherited)
        >>> sorted(out.items())  # doctest: +NORMALIZE_WHITESPACE
        [('border-bottom-color', 'blue'),
         ('border-left-color', 'red'),
         ('border-right-color', 'red'),
         ('border-top-color', 'blue'),
         ('font-family', 'serif'),
         ('font-size', '24pt'),
         ('font-weight', 'bold')]
        N)Ú
isinstancer
   ÚparseÚdictr;   Ú_update_initialÚ_update_font_sizeÚ_update_other_units)r   r`   ra   Úpropsr#   r#   r$   Ú__call__Ü   s    ,

zCSSResolver.__call__)rh   ra   r   c                 C  sl   |  ¡ D ]\}}||vr|||< q| ¡ }|  ¡ D ]4\}}|dkrN| |d¡}|dv r^||= q2|||< q2|S )NÚinheritÚinitial)rk   N)r<   ÚcopyÚget)r   rh   ra   r   ÚvalZ	new_propsr#   r#   r$   re     s    

zCSSResolver._update_initialc                 C  s.   |  d¡r*| j|d |  |¡| jd�|d< |S )Nú	font-size©Úconversions)rm   Ú
size_to_ptÚ_get_font_sizeÚFONT_SIZE_RATIOS)r   rh   ra   r#   r#   r$   rf   (  s    
ý
zCSSResolver._update_font_sizezfloat | None)rh   r   c                 C  s    |  d¡r|d }|  |¡S d S )Nro   )rm   Ú_get_float_font_size_from_pt)r   rh   Úfont_size_stringr#   r#   r$   rs   6  s    

zCSSResolver._get_font_sizer
   Úfloat)rv   r   c                 C  s   |  d¡sJ ‚t| d¡ƒS )Nr@   )Úendswithrw   Úrstrip)r   rv   r#   r#   r$   ru   <  s    z(CSSResolver._get_float_font_size_from_ptc                 C  s„   |   |¡}| jD ]n}d|› d�}||v rB| j|| || jd�||< d|› �d|› �fD ]&}||v rV| j|| || jd�||< qVq|S )NrX   r.   )Úem_ptrq   zmargin-zpadding-)rs   r   rr   r:   ÚMARGIN_RATIOS)r   rh   Z	font_sizer(   r   r#   r#   r$   rg   @  s"    

ý
ýzCSSResolver._update_other_units)r   c           
        s  ‡ ‡‡fdd„}t  dˆ¡}|d u r*|ƒ S | ¡ \}}|dkrDd}n&zt|ƒ}W n tyh   |ƒ  Y S 0 |dkrÊ|dkr–|d u rˆd}qj||9 }d}qjzˆ | \}}W n ty¾   |ƒ  Y S 0 ||9 }qjt|d	ƒ}t|ƒ|kròt|ƒd
›d�}	n|d›d�}	|	S )Nc                     s*   t jdtˆƒ› �ttƒ d� ˆjdˆ d�S )NzUnhandled size: r   z
1!!defaultrp   )r   r   Úreprr   r   rr   r#   ©rq   Úin_valr   r#   r$   Ú_errorW  s    ýz&CSSResolver.size_to_pt.<locals>._errorz^(\S*?)([a-zA-Z%!].*)r'   rA   r@   rB   rH   é   ÚdÚf)ÚreÚmatchÚgroupsrw   Ú
ValueErrorr   ÚroundÚint)
r   r~   rz   rq   r   r„   rn   ÚunitÚmulZsize_fmtr#   r}   r$   rr   V  s8    

zCSSResolver.size_to_ptr   r   )r`   r   c                 c  sT   |D ]J\}}|  ¡ }|  ¡ }|| jv rD| j| }|| ||ƒE d H  q||fV  qd S r0   )r1   ÚCSS_EXPANSIONS)r   r`   r   r   r%   r#   r#   r$   r;   ƒ  s    

zCSSResolver.atomizezIterator[tuple[str, str]])Údeclarations_strr   c                 c  sr   |  d¡D ]b}| ¡ sq
| d¡\}}}| ¡  ¡ }| ¡  ¡ }|rP||fV  q
tjdt|ƒ› �ttƒ d� q
dS )zÖ
        Generates (prop, value) pairs from declarations.

        In a future version may generate parsed tokens from tinycss/tinycss2

        Parameters
        ----------
        declarations_str : str
        ú;ú:z-Ill-formatted attribute: expected a colon in r   N)	r   ÚstripÚ	partitionr1   r   r   r|   r   r   )r   rŒ   Údeclr   Úseprn   r#   r#   r$   rc   �  s    
ýzCSSResolver.parse)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ZUNIT_RATIOSrl   rt   Úupdater{   r:   r8   r   r   r&   r‹   ri   re   rf   rs   ru   rg   rr   r;   rc   r#   r#   r#   r$   r?      s†   ôõÿüÿ
üþÿþû	ö ý6-
r?   )r'   )r–   Ú
__future__r   rƒ   Útypingr   r   r   Zpandas.errorsr   Zpandas.util._exceptionsr   Úcollections.abcr   r   r	   r&   r>   r?   r#   r#   r#   r$   Ú<module>   s   +<