
     h8                         d dl Z d dlmZ d dlmZ ddlmZmZ  ee d          re j	        Z	n G d d          Z	 G d d	          Z
d
 Zd ZdS )    N)warn)ascii_lower   )compile_selector_listsplit_whitespacecached_propertyc                   2    e Zd ZddZd e            fdZdS )r   Nc                 d    |p|j         | _         |j        | _        |p|j        | _        || _        d S N)__name__
__module____doc__func)selfr   namedocs       K/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/cssselect2/tree.py__init__zcached_property.__init__   s2     1DMDM"oDO.$,DLDIII    c                     || S |j                             | j        |          }||u r$|                     |          }||j         | j        <   |S r   )__dict__getr   r   )r   objtype_cached_property__missingvalues        r   __get__zcached_property.__get__   sR    {L$$T]I>>E	!!		#.3T]+Lr   )NN)r   r   __qualname__r   objectr    r   r   r   r      sI        	 	 	 	 %)FFHH 	 	 	 	 	 	r   c                      e Zd ZdZedd            Zedd            Zed d            Z	 ddZd Z	d	 Z
d
 Zd Zed             Zed             Zd Zd Zd Zd Zd Zd Zed             Zd Zd Zd Zed             Zed             Zed             Zed             Zed             Z ed             Z!ed             Z"dS )!ElementWrappera  Wrapper of :class:`xml.etree.ElementTree.Element` for Selector matching.

    This class should not be instanciated directly. :meth:`from_xml_root` or
    :meth:`from_html_root` should be used for the root element of a document,
    and other elements should be accessed (and wrappers generated) using
    methods such as :meth:`iter_children` and :meth:`iter_subtree`.

    :class:`ElementWrapper` objects compare equal if their underlying
    :class:`xml.etree.ElementTree.Element` do.

    Nc                 2    |                      ||d          S )a.  Wrap for selector matching the root of an XML or XHTML document.

        :param root:
            An ElementTree :class:`xml.etree.ElementTree.Element`
            for the root element of a document.
            If the given element is not the root,
            selector matching will behave is if it were.
            In other words, selectors will be not be `scoped`_
            to the subtree rooted at that element.
        :returns:
            A new :class:`ElementWrapper`

        .. _scoped: https://drafts.csswg.org/selectors-4/#scoping

        Fin_html_document
_from_rootclsrootcontent_languages      r   from_xml_rootzElementWrapper.from_xml_root-   s    " ~~d$4u~MMMr   c                 2    |                      ||d          S )zSame as :meth:`from_xml_root` with case-insensitive attribute names.

        Useful for documents parsed with an HTML parser like html5lib, which
        should be the case of documents with the ``text/html`` MIME type.

        Tr$   r&   r(   s      r   from_html_rootzElementWrapper.from_html_root@   s     ~~d$4t~LLLr   Tc                 l    t          |d          r|                                } | |d dd ||          S )Ngetrootr   )parentindexpreviousr%   r+   )hasattrr0   )r)   r*   r+   r%   s       r   r'   zElementWrapper._from_rootJ   sI    4## 	"<<>>DsQ--/ / / 	/r   c                     || _         || _        || _        ||j        | _        n|g| _        || _        || _        || _        d | _        d | _	        d S r   )
etree_elementr1   r3   etree_childrenetree_siblingsr2   r%   transport_content_language
_ancestors_previous_siblings)r   r6   r1   r2   r3   r%   r+   s          r   r   zElementWrapper.__init__S   sn     +  !
 #)"7D#0/D 
 0*:' "&r   c                 b    t          |           t          |          k    o| j        |j        k    S r   )r   r6   r   others     r   __eq__zElementWrapper.__eq__o   s.    JJ$u++% 6%"55	7r   c                     | |k     S r   r    r=   s     r   __ne__zElementWrapper.__ne__t   s    EM""r   c                 H    t          t          |           | j        f          S r   )hashr   r6   r   s    r   __hash__zElementWrapper.__hash__w   s    T$ZZ!34555r   c              #   >   K   |                                  E d {V  d S r   )iter_childrenrD   s    r   __iter__zElementWrapper.__iter__z   s0      %%'''''''''''r   c                 d    | j         #| j        dn| j        j        | j        fz   | _         | j         S )u   Tuple of existing ancestors.

        Tuple of existing :class:`ElementWrapper` objects for this element’s
        ancestors, in reversed tree order, from :attr:`parent` to the root.

        Nr    )r:   r1   	ancestorsrD   s    r   rJ   zElementWrapper.ancestors}   s:     ?"k)%6 O r   c                 d    | j         #| j        dn| j        j        | j        fz   | _         | j         S )u   Tuple of previous siblings.

        Tuple of existing :class:`ElementWrapper` objects for this element’s
        previous siblings, in reversed tree order.

        Nr    )r;   r3   previous_siblingsrD   s    r   rL   z ElementWrapper.previous_siblings   s>     "*m+/4=2BB # &&r   c              #   N   K   t          dt                     | j        E d{V  dS )u  Iterate over ancestors.

        Return an iterator of existing :class:`ElementWrapper` objects for this
        element’s ancestors, in reversed tree order (from :attr:`parent` to the
        root).

        The element itself is not included, this is an empty sequence for the
        root element.

        This method is deprecated and will be removed in version 0.7.0. Use
        :attr:`ancestors` instead.

        zfThis method is deprecated and will be removed in version 0.7.0. Use the "ancestors" attribute instead.N)r   DeprecationWarningrJ   rD   s    r   iter_ancestorszElementWrapper.iter_ancestors   sD       	5	  	  	  >!!!!!!!!!r   c              #   N   K   t          dt                     | j        E d{V  dS )u  Iterate over previous siblings.

        Return an iterator of existing :class:`ElementWrapper` objects for this
        element’s previous siblings, in reversed tree order.

        The element itself is not included, this is an empty sequence for a
        first child or the root element.

        This method is deprecated and will be removed in version 0.7.0. Use
        :attr:`previous_siblings` instead.

        znThis method is deprecated and will be removed in version 0.7.0. Use the "previous_siblings" attribute instead.N)r   rN   rL   rD   s    r   iter_previous_siblingsz%ElementWrapper.iter_previous_siblings   sE       	=	  	  	  ))))))))))r   c              #   b   K   | j         | V  dS | j                                         E d{V  dS )u   Iterate over siblings.

        Return an iterator of newly-created :class:`ElementWrapper` objects for
        this element’s siblings, in tree order.

        N)r1   rG   rD   s    r   iter_siblingszElementWrapper.iter_siblings   sI       ;JJJJJ{0022222222222r   c              #   X   K   d}|                                  D ]}|r|V  || k    rd}dS )u   Iterate over next siblings.

        Return an iterator of newly-created :class:`ElementWrapper` objects for
        this element’s next siblings, in tree order.

        FTN)rS   )r   foundsiblings      r   iter_next_siblingsz!ElementWrapper.iter_next_siblings   sR       ))++ 	 	G $		 	r   c              #      K   d}t          | j                  D ]+\  }} t          |           || ||| j                  }|V  ,dS )u   Iterate over children.

        Return an iterator of newly-created :class:`ElementWrapper` objects for
        this element’s child elements, in tree order.

        N)r1   r2   r3   r%   )	enumerater7   r   r%   )r   childietree_childs       r   rG   zElementWrapper.iter_children   sm       '(;<< 	 	NA{DJJDE!%!68 8 8E KKKK		 	r   c              #      K   t          | g          g}|r\t          |d         d          }||                                 n+|V  |                    |                                           |ZdS dS )a  Iterate over subtree.

        Return an iterator of newly-created :class:`ElementWrapper` objects for
        the entire subtree rooted at this element, in tree order.

        Unlike in other methods, the element itself *is* included.

        This loops over an entire document:

        .. code-block:: python

            for element in ElementWrapper.from_root(root_etree).iter_subtree():
                ...

        N)iternextpopappendrG   )r   stackelements      r   iter_subtreezElementWrapper.iter_subtree   s        tf 	659d++G		W2244555  	6 	6 	6 	6 	6r   c                     d | D             S )Nc                     g | ]<}t          |d           r|gnt          |          D ]}|j        	|j        |j        =S )test)r4   r   pseudo_elementnever_matchesrh   ).0selectorcompiled_selectors      r   
<listcomp>z+ElementWrapper._compile.<locals>.<listcomp>  sr     1 1 1%h77 5

*8441 1 " !/7!/ 8 "
 8777r   r    )	selectorss    r   _compilezElementWrapper._compile  s#    1 1%1 1 1 	1r   c                 `     t           fd                     |          D                       S )zReturn wether this elememt matches any of the given selectors.

        :param selectors:
            Each given selector is either a :class:`compiler.CompiledSelector`,
            or an argument to :func:`compile_selector_list`.

        c              3   .   K   | ]} |          V  d S r   r    )rk   rh   r   s     r   	<genexpr>z)ElementWrapper.matches.<locals>.<genexpr>  s+      CC$44::CCCCCCr   )anyrp   r   ro   s   ` r   matcheszElementWrapper.matches  s4     CCCC$--	*B*BCCCCCCr   c                    |                      |          t                    dk    r(t          d         |                                           S |r fd|                                 D             S t	          d          S )a  Return elements, in tree order, that match any of given selectors.

        Selectors are `scoped`_ to the subtree rooted at this element.

        .. _scoped: https://drafts.csswg.org/selectors-4/#scoping

        :param selectors:
            Each given selector is either a :class:`compiler.CompiledSelector`,
            or an argument to :func:`compile_selector_list`.
        :returns:
            An iterator of newly-created :class:`ElementWrapper` objects.

        r   r   c              3   T   K   | ]!t          fd D                       V  "dS )c              3   .   K   | ]} |          V  d S r   r    )rk   rh   rd   s     r   rs   z5ElementWrapper.query_all.<locals>.<genexpr>.<genexpr>*  s+      77ttG}}777777r   N)rt   )rk   rd   testss    @r   rs   z+ElementWrapper.query_all.<locals>.<genexpr>(  s[       9 9#77777777799 9 9 9 9 9r   r    )rp   lenfilterre   r_   )r   ro   rz   s     @r   	query_allzElementWrapper.query_all  s     i((u::??%(D$5$5$7$7888 	9 9 9 9'+'8'8':':9 9 9 9 88Or   c                 2    t           | j        | d          S )aj  Return first element that matches any of given selectors.

        :param selectors:
            Each given selector is either a :class:`compiler.CompiledSelector`,
            or an argument to :func:`compile_selector_list`.
        :returns:
            A newly-created :class:`ElementWrapper` object,
            or :obj:`None` if there is no match.

        N)r`   r}   ru   s     r   queryzElementWrapper.query.  s     NDNI.555r   c                 $    d | j         D             S )a%  Children as a list of :class:`xml.etree.ElementTree.Element`.

        Other ElementTree nodes such as
        :func:`comments <xml.etree.ElementTree.Comment>` and
        :func:`processing instructions
        <xml.etree.ElementTree.ProcessingInstruction>`
        are not included.

        c                 F    g | ]}t          |j        t                    |S r    )
isinstancetagstr)rk   rd   s     r   rn   z1ElementWrapper.etree_children.<locals>.<listcomp>F  s:     - - -'+s++-- - -r   )r6   rD   s    r   r7   zElementWrapper.etree_children;  s&    - -#'#5- - - 	-r   c                 l    t          | j        j                  \  }}|| j        t	          d          <   |S )z,The local name of this element, as a string.namespace_url_split_etree_tagr6   r   r   r   r   r   
local_names      r   r   zElementWrapper.local_nameJ  s6     %5T5G5K$L$L!z.;c/**+r   c                 l    t          | j        j                  \  }}|| j        t	          d          <   |S )z/The namespace URL of this element, as a string.r   r   r   s      r   r   zElementWrapper.namespace_urlQ  s6     %5T5G5K$L$L!z+5c,''(r   c                 6    | j                             d          S )z$The ID of this element, as a string.id)r6   r   rD   s    r   r   zElementWrapper.idX  s     !%%d+++r   c                 l    t          t          | j                            dd                              S )z:The classes of this element, as a :class:`set` of strings.class )setr   r6   r   rD   s    r   classeszElementWrapper.classes]  s.     #D$6$:$:7B$G$GHHIIIr   c                 &   | j                             d          }|t          |          S | j        p
| j        dk    }|r+| j                             d          }|t          |          S | j        | j        j        S |r}d}| j                             d          }|D ]M}|                    dd          }t          |          dk    r"t          |                    d	                    }N|t          |          S t          | j	                  pdS )
z*The language of this element, as a string.z*{http://www.w3.org/XML/1998/namespace}langNzhttp://www.w3.org/1999/xhtmllangz"{http://www.w3.org/1999/xhtml}metaz
http-equivr   zcontent-languagecontent)
r6   r   r   r%   r   r1   r   r_   _parse_content_languager9   )r   xml_langis_htmlr   r+   iteratormeta
http_equivs           r   r   zElementWrapper.langb  sA    %))8: :x(((! A"@@ 	  	)%))&11D"4(((;";## 
	5#)..46 6H  - -!XXlB77
z**.@@@'>++(- (-$+"#3444&t'FGGM2Mr   c                     | j         dS d}d| j         j        j        |k    o]| j         j                            d          d uo<| j        j        k    p,t	          fd|                                 D                       }|p| j         j        S )NFz&{http://www.w3.org/1999/xhtml}fieldsetz${http://www.w3.org/1999/xhtml}legenddisabledc              3   8   K   | ]}|j         j        k    V  d S r   )r6   r   )rk   rV   legends     r   rs   z6ElementWrapper.in_disabled_fieldset.<locals>.<genexpr>  sJ       8B 8B )-78B 8B 8B 8B 8B 8Br   )r1   r6   r   r   rt   rQ   in_disabled_fieldset)r   fieldsetdisabled_fieldsetr   s      @r   r   z#ElementWrapper.in_disabled_fieldset  s    ;5;7K%)X5 CK%))*55TAC"&&0 BC 8B 8B 8B 8B#'#>#>#@#@8B 8B 8B 5B 5B 	 !DDK$DDr   r   )T)#r   r   r   r   classmethodr,   r.   r'   r   r?   rA   rE   rH   propertyrJ   rL   rO   rQ   rS   rW   rG   re   staticmethodrp   rv   r}   r   r   r7   r   r   r   r   r   r   r    r   r   r"   r"   !   s~       
 
 N N N [N$ M M M [M / / / [/ 59' ' ' '87 7 7
# # #6 6 6( ( (   X ' ' X'" " "(* * *&
3 
3 
3    6 6 62 1 1 \1D D D  06 6 6 - - _-   _   _ , , _, J J _J N N _N> E E _E E Er   r"   c                     |                      d          }|dk    rd| fS | d         dk    sJ | d|         | |dz   d          fS )N}r^   r   r   {r   )rfind)r   positions     r   r   r     sT    yy~~H2~~3w1v}}}}1X:HQJKK 000r   c                 n    | .d| vr,t          |           }t          |          dk    r|d         S d S d S d S )N,r   r   )r   r{   )r   partss     r   r   r     sJ    S-- ''u::??8O --?r   )	functoolswarningsr   webencodingsr   compilerr   r   r4   r   r"   r   r   r    r   r   <module>r      s              $ $ $ $ $ $ = = = = = = = =
79'(( /OO       (mE mE mE mE mE mE mE mE`1 1 1    r   