o
    /h$                     @   sT   d Z dgZddlZddlZddlmZ ddlmZ ddl	m
Z
 G dd dejZdS )	z5CSSStyleRule implements DOM Level 2 CSS CSSStyleRule.CSSStyleRule    N   )cssrule)CSSStyleDeclaration)SelectorListc                       s   e Zd ZdZ					d& fdd	Zdd Zdd	 Zd
d Z fddZe	eeddZ
dd Ze	eddZdd ZdZe	dd eddZdd Ze	dd eddZdd Ze	dd eddZe	d d d!dZe	d"d Zd#d$ Ze	ed%dZ  ZS )'r   a=  The CSSStyleRule object represents a ruleset specified (if any) in a CSS
    style sheet. It provides access to a declaration block as well as to the
    associated group of selectors.

    Format::

        : selector [ COMMA S* selector ]*
        LBRACE S* declaration [ ';' S* declaration ]* '}' S*
        ;
    NFc                    s@   t  j||d t | _|r|| _|r|| _nt | _|| _dS )a$  
        :Parameters:
            selectorText
                string parsed into selectorList
            style
                string parsed into CSSStyleDeclaration for this CSSStyleRule
            readonly
                if True allows setting of properties in constructor only
        )
parentRuleparentStyleSheetN)super__init__r   selectorListselectorTextstyler   	_readonly)selfr   r   r   r   readonly	__class__ M/var/www/html/myenv/lib/python3.10/site-packages/cssutils/css/cssstylerule.pyr
      s   
zCSSStyleRule.__init__c                 C   s:   | j r
| j| j f}n| j}d| jj d|d| jjdS )Nzcssutils.css.z(selectorText=z, style=))_namespacesr   r   __name__r   cssText)r   str   r   r   __repr__8   s    zCSSStyleRule.__repr__c                 C   s"   d| j j| j| jj| jt| f S )NzH<cssutils.css.%s object selectorText=%r style=%r _namespaces=%r at 0x%x>)r   r   r   r   r   r   idr   r   r   r   __str__?   s   zCSSStyleRule.__str__c                 C   s   t j| S )z#Return serialized property cssText.)cssutilsserdo_CSSStyleRuler   r   r   r   _getCssTextL   s   zCSSStyleRule._getCssTextc                    s  t  | | |\}}z| jj}W n	 ty   Y nw | |}| j|dd}| j|dd}| |}|rF| j	j
d| | |d dS |sU| j	
d| |  dS | |d drp| j	j
d	| | tjjd
 dS t| d}t| d}d}	| }
| |
dkrd}	| j	
d| | |
 n|sd}	| j	
d| | |
 ||f|_|sd}	| j	
d| |  n1| }| || |}}|dkr|dkrd}	| j	
d| |  nd|kr|| ||_|	r|| _|| _dS dS )aR  
        :param cssText:
            a parseable string or a tuple of (cssText, dict-of-namespaces)
        :exceptions:
            - :exc:`~xml.dom.NamespaceErr`:
              Raised if the specified selector uses an unknown namespace
              prefix.
            - :exc:`~xml.dom.SyntaxErr`:
              Raised if the specified CSS string value has a syntax error and
              is unparsable.
            - :exc:`~xml.dom.InvalidModificationErr`:
              Raised if the specified CSS string value represents a different
              type of rule than the current one.
            - :exc:`~xml.dom.HierarchyRequestErr`:
              Raised if the rule cannot be inserted at this point in the
              style sheet.
            - :exc:`~xml.dom.NoModificationAllowedErr`:
              Raised if the rule is readonly.
        T)blockstartonly)blockendonlyz"CSSStyleRule: Trailing content: %s)tokenz#CSSStyleRule: No selector found: %rr   @zCSSStyleRule: No style rule: %r)error)r   {Fz7CSSStyleRule: No start { of style declaration found: %rz$CSSStyleRule: No selector found: %r.z3CSSStyleRule: No style declaration or "}" found: %r}EOFz6CSSStyleRule: No "}" after style declaration found: %rN)r	   _setCssText_splitNamespacesOffr   
namespacesAttributeError
_tokenize2_tokensupto2
_nexttoken_logr&   	_valuestr_tokenvalue
startswithxmldomInvalidModificationErrr   r   popr   _typeappendr   r   r   )r   r   r,   	tokenizerselectortokensstyletokenstrailnewSelectorListnewStyleok
bracetokenbraceorEOFtokenvaltypr   r   r   r*   P   s   








zCSSStyleRule._setCssTextz7(DOM) The parsable textual representation of this rule.)docc                 C   s&   z| j jW S  ty   | jj Y S w )zSUses children namespaces if not attached to a sheet, else the sheet's
        ones.)r   r,   r-   r   r   r   r   r   r   __getNamespaces   s
   
zCSSStyleRule.__getNamespaceszIf this Rule is attached to a CSSStyleSheet the namespaces of that sheet are mirrored here. While the Rule is not attached the namespaces of selectorList are used.c                 C   s   |    | |_|| _dS )zp
        :param selectorList: A SelectorList which replaces the current
            selectorList object
        N)_checkReadonly_parentRule_selectorList)r   r   r   r   r   _setSelectorList   s   
zCSSStyleRule._setSelectorListc                 C      | j S N)rJ   r   r   r   r   <lambda>       zCSSStyleRule.<lambda>zThe SelectorList of this rule.c                 C   s(   |    t|| d}|jr|| _dS dS )aM  
        wrapper for cssutils SelectorList object

        :param selectorText:
            of type string, might also be a comma separated list
            of selectors
        :exceptions:
            - :exc:`~xml.dom.NamespaceErr`:
              Raised if the specified selector uses an unknown namespace
              prefix.
            - :exc:`~xml.dom.SyntaxErr`:
              Raised if the specified CSS string value has a syntax error
              and is unparsable.
            - :exc:`~xml.dom.NoModificationAllowedErr`:
              Raised if this rule is readonly.
        )r   r   N)rH   r   
wellformedrJ   )r   r   slr   r   r   _setSelectorText   s
   
zCSSStyleRule._setSelectorTextc                 C      | j jS rM   )rJ   r   r   r   r   r   rN          zB(DOM) The textual representation of the selector for the rule set.c                 C   s4   |    t|trt|| d| _dS | |_|| _dS )zt
        :param style: A string or CSSStyleDeclaration which replaces the
            current style object.
        )r   r   N)rH   
isinstancestrr   _stylerI   )r   r   r   r   r   	_setStyle   s
   

zCSSStyleRule._setStylec                 C   rL   rM   )rW   r   r   r   r   rN     rO   z-(DOM) The declaration-block of this rule set.c                 C   rL   rM   )
STYLE_RULEr   r   r   r   rN   
  rO   z=The type of this rule, as defined by a CSSRule type constant.c                 C   rS   rM   )r   rP   r   r   r   r   rN     rT   c                 C   rS   )z.Return whether the style declaration is valid.)r   validr   r   r   r   	_getValid  s   zCSSStyleRule._getValidz,``True`` when the style declaration is true.)NNNNF)r   
__module____qualname____doc__r
   r   r   r!   r*   propertyr   _CSSStyleRule__getNamespacesr   rK   rJ   r   rR   r   rX   r   typerP   r[   rZ   __classcell__r   r   r   r   r      s`    c		)r^   __all__xml.domr5   r    r   cssstyledeclarationr   selectorlistr   CSSRuler   r   r   r   r   <module>   s    