o
    /hG                     @   sB   d Z dgZddlZddlmZ ddlmZ G dd dejjZ	dS )z;Property is a single CSS property in a CSSStyleDeclaration.Property    N)
Deprecated   )PropertyValuec                       sJ  e Zd ZdZ	d7 fdd	Zdd Zd	d
 Zdd Zdd Zdd Z	e
ee	ddZdd Ze
dd eddZe
dd ddZdd Ze
dd eddZdd  Zd!d" Ze
eed#dZd$d% Ze
d&d' Zejd(d' Ze
d)d d*dZe
d+d, Zejd-d, Zd.d/ Ze
ed0dZed1d2d3 Zed1d4d5 Ze
eed6dZ  ZS )8r   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*
          ;

    N Fc                    sx   t    g dg g| _d| _|| _|| _d| _d| _d| _t	| d| jd< |r-|| _
|| _d| _d| _|r:|| _dS dS )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`
        NFr   parentr   )super__init__seqs
wellformed_mediaQueryr   _Property__nametoken_name_literalnamer   namepropertyValue	_priority_literalprioritypriority)selfr   valuer   r   r   	__class__ I/var/www/html/myenv/lib/python3.10/site-packages/cssutils/css/property.pyr
   /   s"   

zProperty.__init__c              	   C   s*   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   r   r   r   __repr__S   s   *zProperty.__repr__c                 C   sH   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    r   r   r   __str__V   s   HzProperty.__str__c                 C   s    z| j jW S  ty   Y dS w )z%Return True if validation is enabled.T)r   
validatingAttributeErrorr    r   r   r   _isValidatingY   s
   
zProperty._isValidatingc                 C   s   t j| S )z#Return serialized property cssText.)cssutilsserdo_Propertyr    r   r   r   _getCssTexta   s   zProperty._getCssTextc                 C   sH  |  |}| j|dd}|rd}| j|dd}| j|dd}| jr.|s.|| _d| _d| _dS | }| |dkrHd}| j	d| 
| | n|sXd}| j	d	| 
| | |rm| |d
 dkrl|d|d
 nd}| j	d| 
| | |rd| _|| _|| _|| _|  r|   dS dS dS | j	d	| 
|  dS )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   r,   validate)r   r   	tokenizer
nametokensr   valuetokensprioritytokens
colontokenr   r   r   _setCssTexte   sZ   


zProperty._setCssTextz"A parsable textual representation.)fgetfsetdocc                    s   ddd d fdd	}g }j d||d|id\}}|o$ d	 }t|tr2|d
 }|_nd} d sGd}jjd| |d |rvd_ d _	
j	_|jd
<  rsjtjjvrsjjd|dd dS 	 dS d_dS )z
        :exceptions:
            - :exc:`~xml.dom.SyntaxErr`:
              Raised if the specified name has a syntax error and is
              unparsable.
        NT)r   r   c                    sF   d| kr |  d< | d  dS d d< jd| | S )Nr   r   EOFFr   Property: Unexpected ident.)r:   lowerappendr;   r<   )expectedseqtokenr@   newr   r   r   _ident   s   z!Property._setName.<locals>._identr   IDENTrM   rN   r@   productionsr   r   r   FzProperty: No name found: %s)rO   z Property: Unknown Property name.rO   
neverraiseN)_parser7   
isinstancelistr   r;   r<   r=   r   r   
_normalizer   r   r,   r-   profile
knownNameswarn)r   r   rR   newseqr   rM   rO   r   rP   r   _setName   s<   






zProperty._setNamec                 C      | j S rX   )r   r    r   r   r   <lambda>       zProperty.<lambda>zName of this property.)rH   c                 C   rb   rX   )r   r    r   r   r   rc      rd   z7Readonly literal (not normalized) name of this propertyc                 C   sB   | j r|st| d| jd< dS || jd _| jo| jd j| _dS )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   r   r   r   _setPropertyValue   s   
zProperty._setPropertyValuec                 C   s
   | j d S )Nr   )r   r    r   r   r   rc     s   
 z+(cssutils) PropertyValue object of propertyc                 C   s   | j r| j jS dS )Nr   )r   r   r    r   r   r   	_getValue  s   zProperty._getValuec                 C      |  | d S rX   rf   )r   r   r   r   r   	_setValue  s   zProperty._setValuez3The textual value of this Properties propertyValue.c                 C   
   || _ d S rX   )r   )r   r   r   r   r   _setPriority  s   
zProperty._setPriorityc                 C   rb   )zPriority of this property.)r   r    r   r   r   r        zProperty.priorityc                    s"  j rd_d_|rjd dS t|tr#d|kr#d| }ddd d fdd		}d fd
d	}g }jd|	|||dd\}}|oP d }|rd d sdd}j
d|  |rjoj|_ d _j_|jd< jdvrjdj  dS dS dS )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                    sJ    |}d|   kr|krn n|| dS d d< jd| | S )Nr6   rn   Fr   zProperty: Unexpected char.r:   rL   r;   r<   rM   rN   rO   r@   valrP   r   r   _charF  s   

z Property.priority.<locals>._charc                    sB    |}d| kr| d< || dS d d< jd| | S )Nrn   ro   rI   Fr   rJ   rp   rq   rP   r   r   rR   Q  s   

z!Property.priority.<locals>._identr6   )CHARrS   rT   r   ro   FzProperty: Invalid priority: %s   r   rn   z#Property: No CSS priority value: %srX   )r   r   r   r;   r<   rZ   strr\   rY   r7   infor=   r   ro   r   )r   r   rs   rR   r`   r   rM   r   rP   r   r   "  s>   




c                 C   rb   rX   )r   r    r   r   r   rc   u  rd   z;Readonly literal (not normalized) priority of this propertyc                 C   rb   )zAThe Parent Node (normally a CSSStyledeclaration) of this Property_parentr    r   r   r   r   y  rm   zProperty.parentc                 C   rk   rX   ry   )r   r   r   r   r   r   ~  s   
c                 C   s*  d}d}z| j j}W n	 ty   Y nw |dur#|j|jkr#tjjg}| jr| j	r| jtjj
v rtj| j| j	|\}}}|sR| jjdd|| j	f | jdd n:|rx|sx|s`dtjj}n|}| jjd|d|| j	f | jdd d}n|r| jjdd|| j	f | jdd | jd	vrd}|S )
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 "%s" property: %s/TrV   z>Property: Not valid for profile "%s" but valid "%s" value: %s z$Property: Found valid "%s" value: %srv   )r   
parentRuler+   typeFONT_FACE_RULEr-   r]   CSS3_FONT_FACEr   r   r^   validateWithProfiler;   r<   joinr   defaultProfilesr_   debugr   )r   r'   profilesrulematchingvalidprofilesnotvalidprofilesr   r   r   r?     sb   >


	
zProperty.validatezCCheck if value of this property is valid in the properties context.z'Use ``property.propertyValue`` instead.c                 C   rb   rX   )r   r    r   r   r   _getCSSValue  s   zProperty._getCSSValuec                 C   rh   rX   ri   re   r   r   r   _setCSSValue  s   zProperty._setCSSValuez4(DEPRECATED) Use ``property.propertyValue`` instead.)NNr   FN) r   r&   __qualname____doc__r
   r!   r)   r,   r0   rE   propertyr   ra   r   r   rf   r   rg   rj   r   rl   r   setterro   r   r?   r'   r   r   r   cssValue__classcell__r   r   r   r   r      sr    $$CA

Q

 

)
r   __all__r-   cssutils.helperr   r   r   utilBaser   r   r   r   r   <module>   s    