o
    /h                      @   s<   d Z dgZddlZddlmZ G dd dejjejjZdS )a  SelectorList is a list of CSS Selector objects.

TODO
    - remove duplicate Selectors. -> CSSOM canonicalize

    - ??? CSS2 gives a special meaning to the comma (,) in selectors.
        However, since it is not known if the comma may acquire other
        meanings in future versions of CSS, the whole statement should be
        ignored if there is an error anywhere in the selector, even though
        the rest of the selector may look reasonable in CSS2.

        Illegal example(s):

        For example, since the "&" is not a valid token in a CSS2 selector,
        a CSS2 user agent must ignore the whole second line, and not set
        the color of H3 to red:
SelectorList    N   )Selectorc                       s   e Zd ZdZd# fdd	Zdd Zdd	 Zd
d Zd$ddZdd Z	dd Z
ee	ddZdd Zdd Zdd Zdd ZeeeddZedd ddZed d d!dZed"d Z  ZS )%r   z_A list of :class:`~cssutils.css.Selector` objects
    of a :class:`~cssutils.css.CSSStyleRule`.NFc                    s$   t    || _|r|| _|| _dS )z
        :Parameters:
            selectorText
                parsable list of Selectors
            parentRule
                the parent CSSRule if available
        N)super__init___parentRuleselectorText	_readonly)selfr   
parentRulereadonly	__class__ M/var/www/html/myenv/lib/python3.10/site-packages/cssutils/css/selectorlist.pyr      s
   

zSelectorList.__init__c                 C   s0   | j r
| j| j f}n| j}d| jj d|dS )Nzcssutils.css.z(selectorText=))_namespacesr   r   __name__)r
   str   r   r   __repr__/   s   zSelectorList.__repr__c                 C   s   d| j j| j| jt| f S )Nz?<cssutils.css.%s object selectorText=%r _namespaces=%r at 0x%x>)r   r   r   r   idr
   r   r   r   __str__6   s   zSelectorList.__str__c                 C   s    |  |}|r|| j|< dS dS )z\Overwrite ListSeq.__setitem__

        Any duplicate Selectors are **not** removed.
        N)_SelectorList__preparesetseq)r
   indexnewSelectorr   r   r   __setitem__>   s   
zSelectorList.__setitem__c                 C   s>   |si }|    t|tst||f| d}|jr| |_|S dS )z&Used by appendSelector and __setitem__parentN)_checkReadonly
isinstancer   
wellformed_parent)r
   r   
namespacesr   r   r   __preparesetG   s   
zSelectorList.__preparesetc                 C   s@   z| j jjW S  ty   i }| jD ]}||j q| Y S w )z[Use children namespaces if not attached to a sheet, else the sheet's
        ones.
        )r   parentStyleSheetr$   AttributeErrorr   updater   )r
   r$   selectorr   r   r   __getNamespacesR   s   
zSelectorList.__getNamespacesc                 C   s"   t  }| D ]	}||  q|S )z=Used by CSSStyleSheet to check if @namespace rules are needed)setr(   _getUsedUris)r
   urissr   r   r   r,   ^   s   zSelectorList._getUsedUriszIf this SelectorList is
        attached to a CSSStyleSheet the namespaces of that sheet are mirrored
        here. While the SelectorList (or parentRule(s) are
        not attached the namespaces of all children Selectors are used.)docc                 C   s   |  | dS )zSame as :meth:`appendSelector`.N)appendSelector)r
   r   r   r   r   appendm   s   zSelectorList.appendc                 C   s   |    | |\}}z| jjj}W n ty%   | j}|| |}Y nw | ||}|rT| j	dd }| j	dd= |D ]}|j
|j
krK| j	| q=| j	| |S dS )a)  
        Append `newSelector` to this list (a string will be converted to a
        :class:`~cssutils.css.Selector`).

        :param newSelector:
            comma-separated list of selectors (as a single string) or a tuple of
            `(newSelector, dict-of-namespaces)`
        :returns: New :class:`~cssutils.css.Selector` or ``None`` if
            `newSelector` is not wellformed.
        :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.
        N)r    _splitNamespacesOffr   r&   r$   r'   r   r(   r   r   r   r1   )r
   r   r$   r   r   r.   r   r   r   r0   q   s(   
zSelectorList.appendSelectorc                 C   s   t j| S )zReturn serialized format.)cssutilsserdo_css_SelectorListr   r   r   r   _getSelectorText   s   zSelectorList._getSelectorTextc           	      C   s  |    | |\}}z| jjj}W n	 ty   Y nw d}| |}g }d}	 | j|dd}|r`| |d dkr?|	 }nd}t
||f| d}|jrR|| nd}| jd| |  nnq(d|krtd}| jd	| |  n|rd}| jd
| |  |r|| _dS dS )a,  
        :param selectorText:
            comma-separated list of selectors or a tuple of
            (selectorText, 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.NoModificationAllowedErr`:
              Raised if this rule is readonly.
        T)listseponly,Nr   Fz"SelectorList: Invalid Selector: %sz%SelectorList: Cannot end with ",": %rz SelectorList: Unknown Syntax: %r)r    r2   r   r&   r$   r'   
_tokenize2_tokensupto2_tokenvaluepopr   r"   r1   _logerror	_valuestrr   )	r
   r   r$   r"   	tokenizernewseqexpectedselectortokensr)   r   r   r   _setSelectorText   sR   


zSelectorList._setSelectorTextzE(cssutils) The textual representation of the selector for a rule set.c                 C   s   t | S N)lenr   r   r   r   <lambda>   s    zSelectorList.<lambda>zBThe number of :class:`~cssutils.css.Selector` objects in the list.c                 C   s   | j S rF   )r   r   r   r   r   rH      s    zq(DOM) The CSS rule that contains this SelectorList or ``None`` if this SelectorList is not attached to a CSSRule.c                 C   s   t t| jS rF   )boolrG   r   r   r   r   r   rH      s    )NNFrF   )r   
__module____qualname____doc__r   r   r   r   r   _SelectorList__getNamespacesr,   propertyr   r1   r0   r6   rE   r   lengthr   r"   __classcell__r   r   r   r   r      s>    
	+A)	rL   __all__r3   r)   r   utilBaseListSeqr   r   r   r   r   <module>   s
    