o
    /h%,                     @   sB   d Z dgZddlZddlZG dd dejjZG dd deZ	dS )z+CSSRule implements DOM Level 2 CSS CSSRule.CSSRule    Nc                       s*  e Zd ZdZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ		 dZ
	 d	Z	 d
Z	 dZ	 dZ	 ededededede	de
dedededediZd3 f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' Zed(d d)d!Zd*d+ Zeed,d!Zed-d d.d!Zed/d d0d!Zed1d d2d!Z  ZS )4r   aG  Abstract base interface for any type of CSS statement. This includes
    both rule sets and at-rules. An implementation is expected to preserve
    all rules specified in a CSS style sheet, even if the rule is not
    recognized by the parser. Unrecognized rules are represented using the
    ``CSSUnknownRule`` interface.
    r                     
   i  i  i  UNKNOWN_RULE
STYLE_RULECHARSET_RULEIMPORT_RULE
MEDIA_RULEFONT_FACE_RULE	PAGE_RULENAMESPACE_RULECOMMENTVARIABLES_RULEMARGIN_RULENFc                    s4   t    || _|| _|| _| |   d| _dS )z$Set common attributes for all rules.FN)super__init___parent_parentRule_parentStyleSheet_setSeq_tempSeq	_readonly)self
parentRuleparentStyleSheetreadonly	__class__ H/var/www/html/myenv/lib/python3.10/site-packages/cssutils/css/cssrule.pyr   @   s   

zCSSRule.__init__c                 C   sN   |  |}| jr| j|kr|| _|| _dS | jj| j d|tjjd dS )z2Check if new keyword fits the rule it is used for.z#: Invalid atkeyword for this rule: )errorN)	
_normalize	atkeyword
_atkeyword_keyword_logr%   xmldomInvalidModificationErr)r   keywordr'   r#   r#   r$   _setAtkeywordK   s   


zCSSRule._setAtkeywordc                 C      | j S N)r(   r   r#   r#   r$   <lambda>X       zCSSRule.<lambda>z3Normalized  keyword of an @rule (e.g. ``@import``).)docc                 C   s   |    dS )a  
        :param cssText:
            A parsable DOMString.
        :exceptions:
            - :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.
        N)_checkReadonly)r   cssTextr#   r#   r$   _setCssText]   s   zCSSRule._setCssTextc                 C      dS )N r#   r2   r#   r#   r$   r3   q       z}(DOM) The parsable textual representation of the rule. This reflects the current state of the rule and not its initial value.c                 C   r0   )z(The Parent Node of this CSSRule or None.)r   r2   r#   r#   r$   parentx   s   zCSSRule.parentc                 C   r0   r1   )r   r2   r#   r#   r$   r3   ~   r4   zIf this rule is contained inside another rule (e.g. a style rule inside an @media block), this is the containing rule. If this rule is not nested inside any other rules, this returns None.c                 C   s   | j r| j jS | jS r1   )r   r   r2   r#   r#   r$   _getParentStyleSheet   s   zCSSRule._getParentStyleSheetz(The style sheet that contains this rule.c                 C   r0   r1   )r
   r2   r#   r#   r$   r3      r4   z=The type of this rule, as defined by a CSSRule type constant.c                 C   s   t j| j S r1   )r   _typestringstyper2   r#   r#   r$   r3      s    z%Descriptive name of this rule's type.c                 C   r9   )NFr#   r2   r#   r#   r$   r3      r;   zIf the rule is wellformed.)NNF)__name__
__module____qualname____doc__r
   r   r   r   r   r   r   r   r   r   r   r>   r   r/   propertyr'   r8   r7   r<   r   r=   r   r?   
typeString
wellformed__classcell__r#   r#   r!   r$   r   
   s    
c                       sn   e Zd ZdZd fdd	Zdd Zdd Zed	d
 edZdd Z	dddZ
dd Zdd ZdddZ  ZS )CSSRuleRuleszAbstract base interface for rules that contain other rules
    like @media or @page. Methods may be overwritten if a rule
    has specific stuff to do like checking the order of insertion like
    @media does.
    Nc                    s    t  j||d tj | _d S )N)r   r   )r   r   cssutilscssCSSRuleListcssRules)r   r   r   r!   r#   r$   r      s   zCSSRuleRules.__init__c                 c   s    | j E dH  dS )z/Generator iterating over these rule's cssRules.N	_cssRulesr2   r#   r#   r$   __iter__   s   zCSSRuleRules.__iter__c                 C   s8   | j |_| j |_| j|_|D ]}| |_d|_q|| _dS )z1Set new cssRules and update contained rules refs.N)
insertRuleappendextend
deleteRule__delitem__r   r   rN   )r   rL   ruler#   r#   r$   _setCssRules   s   
zCSSRuleRules._setCssRulesc                 C   r0   r1   rM   r2   r#   r#   r$   r3      r4   zCSSRuleRules.<lambda>zDAll Rules in this style sheet, a :class:`~cssutils.css.CSSRuleList`.c              
   C   s   |    t|tr't| jD ]\}}||kr|} nqtjd| jj	|f zd| j
| _| j
|= W dS  tyP } ztjd| jj	|| j
jf |d}~ww )a  
        Delete the rule at `index` from rules ``cssRules``.

        :param index:
            The `index` of the rule to be removed from the rules cssRules
            list. For an `index` < 0 **no** :exc:`~xml.dom.IndexSizeErr` is
            raised but rules for normal Python lists are used. E.g.
            ``deleteRule(-1)`` removes the last rule in cssRules.

            `index` may also be a CSSRule object which will then be removed.

        :Exceptions:
            - :exc:`~xml.dom.IndexSizeErr`:
              Raised if the specified index does not correspond to a rule in
              the media rule list.
            - :exc:`~xml.dom.NoModificationAllowedErr`:
              Raised if this media rule is readonly.
        z/%s: Not a rule in this rule'a cssRules list: %sNz8%s: %s is not a valid index in the rulelist of length %i)r6   
isinstancer   	enumeraterL   r+   r,   IndexSizeErrr"   r@   rN   r   
IndexErrorlength)r   indexirerrr#   r#   r$   rS      s2   

zCSSRuleRules.deleteRulec                 C   s(  |    |du rt| j}n|dk s|| jjkr'tjd| jj|| jjf t	|t
r`tj }||_t|jdksH|jrWt	|jd tjjsW| j| jj d|  dS |jd }||fS t	|tjjrzt|D ]\}}| |||  qkdS t	|tjjs| j| d| jj  dS ||fS )	z1return checked `index` and optional parsed `rule`Nr   z9%s: Invalid index %s for CSSRuleList with a length of %s.r   z: Invalid Rule: )FF)TTz: Not a CSSRule: )r6   lenrN   r[   r+   r,   rY   r"   r@   rW   strrI   rJ   CSSStyleSheetr7   rL   r   r*   r%   rK   rX   rP   )r   rU   r\   	tempsheetr]   r^   r#   r#   r$   _prepareInsertRule   s:   


zCSSRuleRules._prepareInsertRulec                 C   s   | |_ d|_| j|| |S )zadd `rule` at `index`N)r   r   rN   insertr   rU   r\   r#   r#   r$   _finishInsertRule  s   zCSSRuleRules._finishInsertRulec                 C   s
   |  |S )z6Add `rule` to page rule. Same as ``insertRule(rule)``.)rP   )r   rU   r#   r#   r$   add  s   
zCSSRuleRules.addc                 C   s   |  ||S )a  
        Insert `rule` into the rules ``cssRules``.

        :param rule:
            the parsable text representing the `rule` to be inserted. For rule
            sets this contains both the selector and the style declaration.
            For at-rules, this specifies both the at-identifier and the rule
            content.

            cssutils also allows rule to be a valid
            :class:`~cssutils.css.CSSRule` object.

        :param index:
            before the `index` the specified `rule` will be inserted.
            If the specified `index` is equal to the length of the rules
            rule collection, the rule will be added to the end of the rule.
            If index is not given or None rule will be appended to rule
            list.

        :returns:
            the index of the newly inserted rule.

        :exceptions:
            - :exc:`~xml.dom.HierarchyRequestErr`:
              Raised if the `rule` cannot be inserted at the specified `index`,
              e.g., if an @import rule is inserted after a standard rule set
              or other at-rule.
            - :exc:`~xml.dom.IndexSizeErr`:
              Raised if the specified `index` is not a valid insertion point.
            - :exc:`~xml.dom.NoModificationAllowedErr`:
              Raised if this rule is readonly.
            - :exc:`~xml.dom.SyntaxErr`:
              Raised if the specified `rule` has a syntax error and is
              unparsable.
        )rd   rf   r#   r#   r$   rP     s   $zCSSRuleRules.insertRule)NNr1   )r@   rA   rB   rC   r   rO   rV   rD   rL   rS   rd   rg   rh   rP   rG   r#   r#   r!   r$   rH      s    
,'rH   )
rC   __all__xml.domr+   cssutils.utilrI   utilBase2r   rH   r#   r#   r#   r$   <module>   s     