
     hG                     l    d Z dgZddlZddlmZ ddlmZ  G d dej                  j                        Z	y)z;Property is a single CSS property in a CSSStyleDeclaration.Property    N)
Deprecated   )PropertyValuec                       e Zd ZdZ	 d# fd	Zd Zd Zd Zd Zd Z	 e
ee	d	      Zd
 Z e
d ed      Z e
d d      Zd Z e
d ed      Zd Zd Z e
eed      Zd Ze
d        Zej,                  d        Z e
d d      Ze
d        Zej,                  d        Zd Z e
ed      Z ed      d         Z ed      d!        Z e
eed"      Z xZS )$r   a:  A CSS property in a StyleDeclaration of a CSSStyleRule (cssutils).

    Format::

        property = name
          : IDENT S*
          ;

        expr = value
          : term [ operator term ]*
          ;
        term
          : unary_operator?
            [ NUMBER S* | PERCENTAGE S* | LENGTH S* | EMS S* | EXS S* |
              ANGLE S* | TIME S* | FREQ S* | function ]
          | STRING S* | IDENT S* | URI S* | hexcolor
          ;
        function
          : FUNCTION S* expr ')' S*
          ;
        /*
         * There is a constraint on the color that it must
         * have either 3 or 6 hex-digits (i.e., [0-9a-fA-F])
         * after the "#"; e.g., "#000" is OK, but "#abcd" is not.
         */
        hexcolor
          : HASH S*
          ;

        prio
          : IMPORTANT_SYM S*
          ;

    c                    t         |           g dg g| _        d| _        || _        || _        d| _        d| _        d| _        t        |       | j                  d<   |r|| _
        || _        d| _        d| _        |r|| _        yy)a  
        :param name:
            a property name string (will be normalized)
        :param value:
            a property value string
        :param priority:
            an optional priority string which currently must be u'',
            u'!important' or u'important'
        :param _mediaQuery:
            if ``True`` value is optional (used by MediaQuery)
        :param parent:
            the parent object, normally a
            :class:`cssutils.css.CSSStyleDeclaration`
        NF parentr   )super__init__seqs
wellformed_mediaQueryr   _Property__nametoken_name_literalnamer   namepropertyValue	_priority_literalprioritypriority)selfr   valuer   r   r   	__class__s         U/var/www/api/v1/venv_getwork_v1/lib/python3.12/site-packages/cssutils/css/property.pyr   zProperty.__init__/   s    " 	rN	&
$D1		!DI!&D "$DM     c           	          d| j                   j                   d| j                  d| j                  j                  d| j
                  d	S )Nzcssutils.css.z(name=z, value=z, priority=))r   __name__literalnamer   cssTextr   r   s    r   __repr__zProperty.__repr__S   sl    t~~667vd>N>N=QQYZ^ZlZlZtZtYw  xC  DH  DQ  DQ  CT  TU  V  	Vr   c                     d| j                   j                   d| j                   j                   d| j                  d| j                  j
                  d| j                  d| j                  dt        |       dd	S )
N<.z object name=z value=z
 priority=z valid=z at 0xx>)	r   
__module__r    r   r   r"   r   valididr#   s    r   __str__zProperty.__str__V   s    4>>,,-Qt~~/F/F.G}UYU^U^Taahimi{i{  jD  jD  iG  GQ  RV  R_  R_  Qb  bi  jn  jt  jt  iw  w}  ~@  AE  ~F  GH  }I  IJ  K  	Kr   c                 N    	 | j                   j                  S # t        $ r Y yw xY w)z%Return True if validation is enabled.T)r   
validatingAttributeErrorr#   s    r   _isValidatingzProperty._isValidatingY   s)    	;;))) 		s    	$$c                 @    t         j                  j                  |       S )z#Return serialized property cssText.)cssutilsserdo_Propertyr#   s    r   _getCssTextzProperty._getCssTexta   s    ||''--r   c                    | j                  |      }| j                  |d      }|rd}| j                  |d      }| j                  |d      }| j                  r|s|| _        d| _        d| _        y|j                         }| j                  |      dk7  r1d}| j                  j                  d| j                  |      z  |       n2|s0d}| j                  j                  d	| j                  |      z  |       |r9| j                  |d
         dk(  rR|j                  d|j                  d
             n0d}| j                  j                  d| j                  |      z  |       |r>d| _        || _        || _        || _        | j                         r| j                          yyy| j                  j                  d	| j                  |      z         y)a  
        :exceptions:
            - :exc:`~xml.dom.SyntaxErr`:
              Raised if the specified CSS string value has a syntax error and
              is unparsable.
            - :exc:`~xml.dom.NoModificationAllowedErr`:
              Raised if the rule is readonly.
        T)propertynameendonly)propertyvalueendonly)propertypriorityendonlyN:Fz%Property: No ":" after name found: %sz$Property: No property name found: %s!r   z%Property: No property value found: %s)
_tokenize2_tokensupto2r   r   r   r   pop_tokenvalue_logerror	_valuestrinsertr   r1   validate)r   r"   	tokenizer
nametokensr   valuetokensprioritytokens
colontokens           r   _setCssTextzProperty._setCssTexte   s    OOG,	&&yd&K
J++ID+QK!..yRV.WN&	%)" $ $)J
+s2"
		;dnnW>UU  "
		:T^^G=TT
 ##KO4;"))![__R-@A"
		;dnnW>UU
 "&&	%0" . %%'MMO (  IIOO69PPr   z"A parsable textual representation.)fgetfsetdocc                 p    dddd fd	}g } j                  d| j                  |      d|i      \  }}|xr d   }t        |t              r|d	   }| _        nd}d
   s1d} j
                  j                  d j                  |      z  |       |rd _        d
    _	         j                   j                         _        | j                  d	<    j                         rE j                  t        j                  j                   vr j
                  j#                  d|d       yyd _        y)z
        :exceptions:
            - :exc:`~xml.dom.SyntaxErr`:
              Raised if the specified name has a syntax error and is
              unparsable.
        NT)r!   r   c                     d| k(  r7j                  |      j                         d<   |j                  d          ydd<   j                  j	                  d|       | S )Nr   r!   EOFFr   Property: Unexpected ident.)rA   lowerappendrB   rC   )expectedseqtokenrG   newr   s       r   _identz!Property._setName.<locals>._ident   s_    !%)%5%5e%<%B%B%DM"

3}-.$)L!		 =uEr   r   IDENTrV   rW   rG   productionsr   r   r!   FzProperty: No name found: %s)rX   z Property: Unknown Property name.rX   
neverraiseN)_parser>   
isinstancelistr   rB   rC   rD   r   r   
_normalizer   r   r1   r3   profile
knownNameswarn)r   r   rZ   newseqr   rV   rX   rY   s   `      @r   _setNamezProperty._setName   sA    #$7		  #{{ood+ &)	  +  

H  5C$5
 dD!GE$DE=!JIIOO-t0DDE   "DO #M 2D):):;DJ!DIIaL !!#

(:J:J:U:U(U		6ePT    $DOr   c                     | j                   S r`   )r   r#   s    r   <lambda>zProperty.<lambda>   s    r   zName of this property.)rO   c                     | j                   S r`   )r   r#   s    r   rk   zProperty.<lambda>   s
    T&&r   z7Readonly literal (not normalized) name of this propertyc                     | j                   r|st        |       | j                  d<   y|| j                  d   _        | j                  xr | j                  d   j                  | _        y)a  
        See css.PropertyValue

        :exceptions:
        - :exc:`~xml.dom.SyntaxErr`:
          Raised if the specified CSS string value has a syntax error
          (according to the attached property) or is unparsable.
        - :exc:`~xml.dom.InvalidModificationErr`:
          TODO: Raised if the specified CSS string value represents a different
          type of values than the values allowed by the CSS property.
        r
   r   N)r   r   r   r"   r   r   r"   s     r   _setPropertyValuezProperty._setPropertyValue   sO     G(5DIIaL#*DIIaL "ooI$))A,2I2IDOr   c                      | j                   d   S )Nr   )r   r#   s    r   rk   zProperty.<lambda>  s    TYYq\r   z+(cssutils) PropertyValue object of propertyc                 H    | j                   r| j                   j                  S y)Nr	   )r   r   r#   s    r   	_getValuezProperty._getValue  s     %%+++r   c                 &    | j                  |       y r`   ro   )r   r   s     r   	_setValuezProperty._setValue  s    u%r   z3The textual value of this Properties propertyValue.c                     || _         y r`   )r   )r   r   s     r   _setPriorityzProperty._setPriority  s	     r   c                     | j                   S )zPriority of this property.)r   r#   s    r   r   zProperty.priority  s     ~~r   c                      j                   r,d _        d _        |r j                  j	                  d       yt        |t              rd j                  |      k(  rd|z  }dddd fd	}d fd		}g } j                  d
| j                  |      ||d      \  }}|xr d   }|r4d   s/d} j                  j                  d j                  |      z         |r j                  xr | _        d    _         j                   j                         _        | j                  d<    j                  dvr) j                  j	                  d j                  z         yyy)a  
        priority
            a string, currently either u'', u'!important' or u'important'

        Format::

            prio
              : IMPORTANT_SYM S*
              ;

            "!"{w}"important"   {return IMPORTANT_SYM;}

        :exceptions:
            - :exc:`~xml.dom.SyntaxErr`:
              Raised if the specified priority has a syntax error and is
              unparsable.
              In this case a priority not equal to None, "" or "!{w}important".
              As CSSOM defines CSSStyleDeclaration.getPropertyPriority resulting
              in u'important' this value is also allowed to set a Properties
              priority
        r	   z0Property: No priority in a MediaQuery - ignored.N	importantz!%sT)literalpriorityr   c                     j                  |      }d| cxk(  r|k(  rn n|j                  |       ydd<   j                  j                  d|       | S )Nr=   rz   Fr   zProperty: Unexpected char.rA   rU   rB   rC   rV   rW   rX   rG   valrY   r   s        r   _charz Property.priority.<locals>._charF  sP    ""5)Ch%#%

3"$)L!		 <eDr   c                     j                  |      }d| k(  r|d<   |j                  |       ydd<   j                  j                  d|       | S )Nrz   r{   rR   Fr   rS   r}   r~   s        r   rZ   z!Property.priority.<locals>._identQ  sV    ""5)Ch&),%&

3$)L!		 =uEr   r=   )CHARr[   r\   r   r{   FzProperty: Invalid priority: %s   r	   rz   z#Property: No CSS priority value: %sr`   )r   r   r   rB   rC   rb   strrd   ra   r>   inforD   r   r{   r   )r   r   r   rZ   rh   r   rV   rY   s   `      @r   r   zProperty.priority"  s^   . DN$&D!		 UVh$8Q)Qx'H #%D9		 
	  #{{ooh/!&8	  +  

H  5C$5
 C 12JIINN;dnnX>VVW"oo<*DO$'(9$:D!!__T-A-ABDN!DIIaL~~%66		 E VW 7 r   c                     | j                   S r`   )r   r#   s    r   rk   zProperty.<lambda>u  s
    T**r   z;Readonly literal (not normalized) priority of this propertyc                     | j                   S )zAThe Parent Node (normally a CSSStyledeclaration) of this Property_parentr#   s    r   r   zProperty.parenty  s     ||r   c                     || _         y r`   r   )r   r   s     r   r   zProperty.parent~  s	    r   c           	         d}d}	 | j                   j                  }|5|j                  |j                  k(  rt        j
                  j                  g}	 | j                  r| j                  rs| j                  t        j
                  j                  v rLt        j
                  j                  | j                  | j                  |      \  }}}|sH| j                  j                  ddj                  |      d| j                  | j                  d       n|r~|s||s*dj                  t        j
                  j                         }n|}| j                  j#                  d|d	dj                  |      d
| j                  d| j                  d       d}nI|rG| j                  j%                  ddj                  |      d
| j                  | j                  d       | j&                  dvrd}|S # t        $ r Y w xY w)aC	  Validate value against `profiles` which are checked dynamically.
        properties in e.g. @font-face rules are checked against
        ``cssutils.profile.CSS3_FONT_FACE`` only.

        For each of the following cases a message is reported:

        - INVALID (so the property is known but not valid)
            ``ERROR    Property: Invalid value for "{PROFILE-1[/PROFILE-2...]"
            property: ...``

        - VALID but not in given profiles or defaultProfiles
            ``WARNING    Property: Not valid for profile "{PROFILE-X}" but valid
            "{PROFILE-Y}" property: ...``

        - VALID in current profile
            ``DEBUG    Found valid "{PROFILE-1[/PROFILE-2...]" property...``

        - UNKNOWN property
            ``WARNING    Unknown Property name...`` is issued

        so for example::

            cssutils.log.setLevel(logging.DEBUG)
            parser = cssutils.CSSParser()
            s = parser.parseString('''body {
                unknown-property: x;
                color: 4;
                color: rgba(1,2,3,4);
                color: red
            }''')

            # Log output:

            WARNING Property: Unknown Property name. [2:9: unknown-property]
            ERROR   Property: Invalid value for                 "CSS Color Module Level 3/CSS Level 2.1" property: 4 [3:9: color]
            DEBUG   Property: Found valid                 "CSS Color Module Level 3" value: rgba(1, 2, 3, 4) [4:9: color]
            DEBUG   Property: Found valid "CSS Level 2.1" value: red [5:9: color]


        and when setting an explicit default profile::

            cssutils.profile.defaultProfiles = cssutils.profile.CSS_LEVEL_2
            s = parser.parseString('''body {
                unknown-property: x;
                color: 4;
                color: rgba(1,2,3,4);
                color: red
            }''')

            # Log output:

            WARNING Property: Unknown Property name. [2:9: unknown-property]
            ERROR   Property: Invalid value for                 "CSS Color Module Level 3/CSS Level 2.1" property: 4 [3:9: color]
            WARNING Property: Not valid for profile                 "CSS Level 2.1" but valid "CSS Color Module Level 3"                 value: rgba(1, 2, 3, 4)  [4:9: color]
            DEBUG   Property: Found valid "CSS Level 2.1" value: red [5:9: color]
        FNzProperty: Invalid value for "/z" property: Tr^   z!Property: Not valid for profile "z" but valid "z	" value:  zProperty: Found valid "r   )r   
parentRuletypeFONT_FACE_RULEr3   re   CSS3_FONT_FACEr0   r   r   rf   validateWithProfilerB   rC   joinr   defaultProfilesrg   debugr   )r   r+   profilesrulematchingvalidprofilesnotvalidprofiless          r   rF   zProperty.validate  s   | 	A;;))D 99 3 33 ( 0 0 ? ?@H 99 yyH,,777191A1A1U1UIItzz82.x IIOO/2xx/F

T"..#'	 $  (#+.88H4D4D4T4T+U(+3(IINN ,SXXm-DdjjR #..#' #  "EIIOO88M2DJJ@"..#'	 $  >>!22Eu  		s   G2 2	G?>G?zCCheck if value of this property is valid in the properties context.z'Use ``property.propertyValue`` instead.c                     | j                   S r`   )r   r#   s    r   _getCSSValuezProperty._getCSSValue  s    !!!r   c                 &    | j                  |       y r`   rt   rn   s     r   _setCSSValuezProperty._setCSSValue  s    w'r   z4(DEPRECATED) Use ``property.propertyValue`` instead.)NNr	   FN) r    r*   __qualname____doc__r   r$   r-   r1   r6   rL   propertyr"   ri   r   r!   ro   r   rr   ru   r   rw   r   setterr{   r   rF   r+   r   r   r   cssValue__classcell__)r   s   @r   r   r      s~   !H MQ"%HVK.AF {0TG?$B +X;STD&HK
J$ !9M& 9"WE!   __OX OXb *IO
   ]] ~@ TE
 9:" ;" 9:( ;( BHr   )
r   __all__r3   cssutils.helperr   r   r   utilBaser    r   r   <module>r      s0    A,  &  Hx}}!! Hr   