
    Owg]                         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xZ
Z G d	 d
      Z ej                  dd      Zy)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                   2    e Zd ZdZd Zd Zd Zed        Zy)Matcherz=A CSS selectors storage that can match against HTML elements.c                 f    i | _         i | _        i | _        i | _        g | _        g | _        d| _        y )Nr   )id_selectorsclass_selectorslower_local_name_selectorsnamespace_selectorslang_attr_selectorsother_selectorsorder)selfs    J/var/www/horilla/myenv/lib/python3.12/site-packages/cssselect2/__init__.py__init__zMatcher.__init__   s9    !*,'#% #% !
    c                 <   | xj                   dz  c_         |j                  ry|j                  |j                  | j                   |j                  |f}|j
                  6| j                  j                  |j
                  g       j                  |       y|j                  6| j                  j                  |j                  g       j                  |       y|j                  6| j                  j                  |j                  g       j                  |       y|j                  6| j                  j                  |j                  g       j                  |       y|j                   r| j"                  j                  |       y| j$                  j                  |       y)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entrys       r   add_selectorzMatcher.add_selector    sD    	

a
!! MM8//##W. ;;"((b9@@G  ,  ++##R))/  ,++66))2//5ve}+$$//""B((.u(($$++E2  ''.r   c                     g }|j                   B|j                   | j                  v r*| j                  || j                  |j                      |       |j                  D ]1  }|| j                  v s| j                  || j                  |   |       3 t        |j                        }|| j                  v r | j                  || j                  |   |       |j                  | j                  v r*| j                  || j                  |j                     |       d|j                  j                  v r| j                  || j                  |       | j                  || j                  |       |j                  t               |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.

        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_names        r   matchzMatcher.matchF   sw     ::!gjjD4E4E&E''**7::68JL "// 	(JT111++T11*=&(	( !!3!34
888''88D"$   D$<$<<''11'2G2GH"$ W**111''113EG 	##T))+=	? 	H-!!r   c                 Z    |D ]&  \  }}}}} ||       s|j                  ||||f       ( y )N)r   )r1   	selectorsr2   r   r   r   pseudor$   s           r   r*   zMatcher.add_relevant_selectorss   s=    9B 	;5D+ufgG}")) %9;	;r   N)	__name__
__module____qualname____doc__r   r&   r4   staticmethodr*    r   r   r	   r	      s*    G$/L+"Z ; ;r   r	   )r;   operatorwebencodingsr   compilerr   parserr   treer   VERSION__version__r	   
itemgetterr0   r=   r   r   <module>rF      sJ     $ , !   +c; c;L 8q!$r   