o
    Zh0hÁ  ã                   @   sN   d 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d
S )záCSS4 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.)

é    )Úascii_loweré   )Úcompile_selector_list)ÚSelectorError)ÚElementWrapperz0.8.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   úI/var/www/html/rh/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   s(   þ


ÿ
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|¡ | ¡  |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)r   r   Úadd_relevant_selectorsÚclassesr	   r   r   r
   Únamespace_urlr   Úetree_elementÚattribr   r   Úsort)r   ÚelementÚrelevant_selectorsr   Ú
lower_namer   r   r   ÚmatchB   s:   ÿ

ÿ€


þþÿzMatcher.matchc                 C   s2   |D ]\}}}}}|| ƒr|  ||||f¡ qd S )N)r   )r*   Ú	selectorsr+   r   r   r   Úpseudor    r   r   r   r$   m   s
   €þzMatcher.add_relevant_selectorsN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r"   r-   Ústaticmethodr$   r   r   r   r   r      s    	$+r   N)r3   Úwebencodingsr   Úcompilerr   Úparserr   Útreer   ÚVERSIONÚ__version__r   r   r   r   r   Ú<module>   s    