o
    ge"                     @  sL   d Z ddlmZ ddlZddlZG dd deZddd	ZG d
d dZdS )zN
Utilities for interpreting CSS from Stylers for formatting non-HTML outputs.
    )annotationsNc                   @  s   e Zd ZdZdS )
CSSWarningz5
    This CSS syntax cannot currently be parsed.
    N)__name__
__module____qualname____doc__ r   r   S/home/ubuntu/cloudmapper/venv/lib/python3.10/site-packages/pandas/io/formats/css.pyr   
   s    r   prop_fmtstrc                   s   d fdd}|S )Nvaluer   c              
   3  sz    |  }z	| jt| }W n ty%   td| d| dt Y d S w t| j|D ]\}} 	||| fV  q,d S )NzCould not expand "z: ")
splitSIDE_SHORTHANDSlenKeyErrorwarningswarnr   zipSIDESformat)selfpropr   tokensmappingkeyidxr
   r   r	   expand   s   z_side_expander.<locals>.expand)r   r   r   )r
   r   r   r   r	   _side_expander   s   
r   c                   @  s.  e Zd ZdZ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g dg dg d d!Z
d"Z	#dEdFd*d+ZdGd-d.ZdGd/d0ZdHd2d3ZdId6d7ZdJd8d9Zd#efd:d;Zd<d= Zed>Zed?Zed@ZedAZedBZdKdCdDZd#S )LCSSResolverzH
    A callable for parsing and resolving CSS to atomic properties.
    )pt   )em      ?)r!   g      ?)r!   H   )ingL&d2?)r&   g
BP(?)mmg      ?)r#   r   )	remexpxpcr&   cmr'   q	!!default)r#   g{Gz?)r(   r$   )r(   g      ?)r(   g?)r(      )r(   g      ?)r(   g      ?)r(      )r#   g?)r#   g333333?)r#   r/   )%zxx-smallzx-smallsmallmediumlargezx-largezxx-largesmallerlargerr.   none)r!   r   )r*      )r*   r0   )r*   r/   )r7   thickr3   thin)r   r   r   r   )r   r/   r   r/   )r   r/   r0   r/   )r   r/   r0      )r/   r0   r;   r8   )toprightbottomleftNdeclarations_strr   	inheriteddict[str, str] | Nonereturndict[str, str]c                 C  sB   t | | |}|du ri }| ||}| ||}| |S )a  
        The given declarations to atomic properties.

        Parameters
        ----------
        declarations_str : str
            A list of CSS declarations
        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)dictatomizeparse_update_initial_update_font_size_update_other_units)r   r@   rA   propsr   r   r	   __call__X   s   *
zCSSResolver.__call__rK   c                 C  sl   |  D ]\}}||vr|||< q| }|  D ]\}}|dkr'||d}|dv r/||= q|||< q|S )Ninheritinitial)rN   N)itemscopyget)r   rK   rA   r   val	new_propsr   r   r	   rH      s   
zCSSResolver._update_initialc                 C  s.   | dr| j|d | || jd|d< |S )N	font-sizeconversions)rQ   
size_to_pt_get_font_sizeFONT_SIZE_RATIOS)r   rK   rA   r   r   r	   rI      s   

zCSSResolver._update_font_sizefloat | Nonec                 C  s    | dr|d }| |S d S )NrT   )rQ   _get_float_font_size_from_pt)r   rK   font_size_stringr   r   r	   rX      s   

zCSSResolver._get_font_sizer\   floatc                 C  s   | dsJ t|dS )Nr!   )endswithr]   rstrip)r   r\   r   r   r	   r[      s   z(CSSResolver._get_float_font_size_from_ptc                 C  s   |  |}| jD ]7}d| d}||v r!| j|| || jd||< d| d| fD ]}||v r>| j|| || jd||< q+q|S )Nzborder-z-width)em_ptrV   zmargin-zpadding-)rX   r   rW   BORDER_WIDTH_RATIOSMARGIN_RATIOS)r   rK   	font_sizesider   r   r   r	   rJ      s&   



zCSSResolver._update_other_unitsc           
        s
   fdd}t d}|d u r| S | \}}|dkr"d}nzt|}W n ty4   |  Y S w |dkrh|dkrK|d u rDd}n||9 }d}q5z | \}}W n ty_   |  Y S w ||9 }|dks9t|d	}t||kr}t|d
d}	|	S |dd}	|	S )Nc                     s$   t dt t jd dS )NzUnhandled size: z
1!!defaultrU   )r   r   reprr   rW   r   rV   in_valr   r   r	   _error   s   z&CSSResolver.size_to_pt.<locals>._errorz^(\S*?)([a-zA-Z%!].*) r/   r!   r#   r(      df)rematchgroupsr]   
ValueErrorr   roundint)
r   rg   r`   rV   rh   rn   rR   unitmulsize_fmtr   rf   r	   rW      s@   


zCSSResolver.size_to_ptc              	   c  sn    |D ]1\}}d| dd }zt| |}W n ty$   ||fV  Y qw |||D ]	\}}||fV  q*qd S )Nexpand_-_)replacegetattrAttributeError)r   declarationsr   r   attrr   r   r   r	   rF      s   zCSSResolver.atomizezborder-{:s}-colorzborder-{:s}-stylezborder-{:s}-widthzmargin-{:s}zpadding-{:s}c                 c  sn    | dD ].}| sq|d\}}}|  }|  }|r)||fV  qtdt| t 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 N)r   strip	partitionlowerr   r   re   r   )r   r@   declr   seprR   r   r   r	   rG     s   
zCSSResolver.parse)N)r@   r   rA   rB   rC   rD   )rK   rD   rA   rD   rC   rD   )rK   rD   rC   rZ   )r\   r   rC   r]   )rK   rD   rC   rD   )r@   r   )r   r   r   r   UNIT_RATIOSrP   rY   updaterb   ra   r   r   rL   rH   rI   rX   r[   rJ   rW   rF   r   expand_border_colorexpand_border_styleexpand_border_widthexpand_marginexpand_paddingrG   r   r   r   r	   r       st    
2



)r    )r
   r   )	r   
__future__r   rm   r   UserWarningr   r   r    r   r   r   r	   <module>   s    
