o
    %e]                     @   sb   d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	 d Z
ZG d	d
 d
ZeddZdS )zCSS4 selectors for Python.

cssselect2 is a straightforward implementation of CSS4 Selectors for markup
documents (HTML, XML, etc.) that can be read by ElementTree-like parsers
(including cElementTree, lxml, html5lib, etc.)

    N)ascii_lower   )compile_selector_list)SelectorError)ElementWrapperz0.7.0c                   @   s4   e Zd ZdZdd Zdd Zdd Zedd	 Zd
S )Matcherz=A CSS selectors storage that can match against HTML elements.c                 C   s.   i | _ i | _i | _i | _g | _g | _d| _d S )Nr   )id_selectorsclass_selectorslower_local_name_selectorsnamespace_selectorslang_attr_selectorsother_selectorsorder)self r   F/var/www/html/venv/lib/python3.10/site-packages/cssselect2/__init__.py__init__   s   
zMatcher.__init__c                 C   s   |  j d7  _ |jrdS |j|j| j |j|f}|jdur)| j|jg | dS |j	dur;| j
|j	g | dS |jdurM| j|jg | dS |jdur_| j|jg | dS |jrj| j| dS | j| dS )a  Add a selector and its payload to the matcher.

        :param selector:
            A :class:`compiler.CompiledSelector` object.
        :param payload:
            Some data associated to the selector,
            such as :class:`declarations <tinycss2.ast.Declaration>`
            parsed from the :attr:`tinycss2.ast.QualifiedRule.content`
            of a style rule.
            It can be any Python object,
            and will be returned as-is by :meth:`match`.

        r   N)r   never_matchestestspecificitypseudo_elementidr   
setdefaultappend
class_namer	   
local_namer
   lower_local_name	namespacer   requires_lang_attrr   r   )r   selectorpayloadentryr   r   r   add_selector    s4   



zMatcher.add_selectorc                 C   s   g }|j dur|j | jv r| || j|j  | |jD ]}|| jv r,| || j| | qt|j}|| jv rA| || j| | |j| j	v rR| || j	|j | d|j
jv r`| || j| | || j| |jtd |S )a  Match selectors against the given element.

        :param element:
            An :class:`ElementWrapper`.
        :returns:
            A list of the payload objects associated to selectors that match
            element, in order of lowest to highest
            :attr:`compiler.CompiledSelector` specificity and in order of
            addition with :meth:`add_selector` among selectors of equal
            specificity.

        Nlang)key)r   r   add_relevant_selectorsclassesr	   r   r   r
   namespace_urlr   etree_elementattribr   r   sortSORT_KEY)r   elementrelevant_selectorsr   
lower_namer   r   r   matchF   s@   





zMatcher.matchc                 C   s2   |D ]\}}}}}|| r| ||||f qd S )N)r   )r,   	selectorsr-   r   r   r   pseudor    r   r   r   r%   s   s   
zMatcher.add_relevant_selectorsN)	__name__
__module____qualname____doc__r   r"   r/   staticmethodr%   r   r   r   r   r      s    	&-r   )r5   operatorwebencodingsr   compilerr   parserr   treer   VERSION__version__r   
itemgetterr+   r   r   r   r   <module>   s    f