o
    e=$                     @   sT   d Z dgZddlmZ ddlmZ ddlmZ ddlZddl	Z
G dd dejZdS )	z5CSSStyleRule implements DOM Level 2 CSS CSSStyleRule.CSSStyleRule   )CSSStyleDeclaration)SelectorList)cssrule    Nc                       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   Z	_readonly)selfr   r   r   r   readonly	__class__ ID:\Projects\ConvertPro\env\Lib\site-packages\cssutils/css/cssstylerule.pyr
      s   
zCSSStyleRule.__init__c                 C   s0   | j r
| j| j f}n| j}d| jj|| jjS )Nz.cssutils.css.{}(selectorText={!r}, style={!r}))_namespacesr   formatr   __name__r   cssText)r   str   r   r   __repr__5   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.)cssutilsZserZdo_CSSStyleRuler   r   r   r   _getCssTextM   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)Zblockstartonly)Z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}ZEOFz6CSSStyleRule: No "}" after style declaration found: %rN)r	   _setCssTextZ_splitNamespacesOffr   
namespacesAttributeErrorZ
_tokenize2Z_tokensupto2Z
_nexttoken_logr!   Z	_valuestrZ_tokenvalue
startswithxmldomZInvalidModificationErrr   r   popr   _typeappendr   r   r   )r   r   r%   Z	tokenizerZselectortokensZstyletokenstrailZnewSelectorListZnewStyleokZ
bracetokenZbraceorEOFtokenvaltypr   r   r   r$   Q   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   Z__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)r5   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)r3   r   
wellformedr5   )r   r   slr   r   r   _setSelectorText   s
   
zCSSStyleRule._setSelectorTextc                 C      | j jS r8   )r5   r   r   r   r   r   r9          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)r3   
isinstancestrr   _styler4   )r   r   r   r   r   	_setStyle   s
   

zCSSStyleRule._setStylec                 C   r7   r8   )rB   r   r   r   r   r9     r:   z-(DOM) The declaration-block of this rule set.c                 C   r7   r8   )Z
STYLE_RULEr   r   r   r   r9   
  r:   z=The type of this rule, as defined by a CSSRule type constant.c                 C   r>   r8   )r   r;   r   r   r   r   r9     r?   c                 C   r>   )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   Z_CSSStyleRule__getNamespacesr   r6   r5   r   r=   r   rC   r   typer;   rE   rD   __classcell__r   r   r   r   r      s`    b		)rH   __all__Zcssstyledeclarationr   Zselectorlistr    r   r   Zxml.domr)   ZCSSRuler   r   r   r   r   <module>   s    