
     h                         d dl Z d dlZd dlmZ d dlmZ d Z e       dd       Z ej                         e_	        ddZ
y)	    N)OrderedDict)function_cachec                     | j                   dk(  r'| j                  j                  j                         dz   S | j                  j                  j                         S )N	importantz !important)prioritypropertyValuecssTextstrip)props    U/var/www/api/v1/venv_getwork_v1/lib/python3.12/site-packages/premailer/merge_style.pyformat_valuer      sI    }}#!!))//1MAA!!))//11    c                     t         j                  5  t        j                  | |      D cg c]'  }|j                  j                         t        |      f) c}cddd       S c c}w # 1 sw Y   yxY w)zX
    csstext_to_pairs takes css text and make it to list of
    tuple of key,value.
    )validateN)csstext_to_pairs_lockcssutils
parseStylenamer
   r   )csstextr   r   s      r   r   r      sb     
		 !++GhG
G YY__T 23G
 
 	
 
 	s   A(,A#A(#A((A1c           
         t        dt               fg      }t        |      D ]  }t               ||<    t        |      D ]  \  }}|D ]  \  }}	|	|||      |<     | rt        |       D ]  \  }}	|	|d   |<    g }
g }|j	                         D ]  \  }}|r t        d |j	                         D              }|s+|r<|j                  |ddj                  d |j	                         D              d       i|
j                  dj                  d |j	                         D                      |r|
rddj                  |
      z  g|z   n|}n|
}d	j                  |      j                         S )
a  
    This will merge all new styles where the order is important
    The last one will override the first
    When that is done it will apply old inline style again
    The old inline style is always important and override
    all new ones. The inline style must be valid.

    Args:
        inline_style(str): the old inline style of the element if there
            is one
        new_styles: a list of new styles, each element should be
            a list of tuple
        classes: a list of classes which maps new_styles, important!
        remove_unset_properties(bool): Allow us to remove certain CSS
            properties with rules that set their value to 'unset'

    Returns:
        str: the final style
     c              3   R   K   | ]  \  }}|j                         d k(  r||f ! yw)unsetN)lower.0kvs      r   	<genexpr>zmerge_styles.<locals>.<genexpr>L   s)      %/6AqqwwyG7KAZs   '	'{z; c              3   0   K   | ]  \  }}|d |  yw:N r   s      r   r    zmerge_styles.<locals>.<genexpr>T   s     )Rztq!Q*:z   }c              3   0   K   | ]  \  }}|d |  ywr#   r%   r   s      r   r    zmerge_styles.<locals>.<genexpr>W   s     *S
1a+;
r&   z{%s} )r   set	enumerater   itemsappendjoinr
   )inline_style
new_stylesclassesremove_unset_propertiesstylespcistyler   r   normal_stylespseudo_stylespseudoclasskv
all_styless                  r   merge_stylesr<   !   sz   * 2{}-./F'l ]r
  j)5DAq$%F71:q!  *
  %\2DAqF2JqM 3 MM!<<>R"  %'XXZ B   		)Rrxxz)R RT
   *S
*S!ST! *$ 
  rww}--.> 	 #
88J%%''r   )T)F)r   	threadingcollectionsr   premailer.cacher   r   r   RLockr   r<   r%   r   r   <module>rA      sG      # *2 
 
 )*  C(r   