
    BhB5                     X    S SK Jr  S SKJr  S SKJr  SSKJrJr   " S S5      r	S r
S	 rg
)    )cached_property)warn)ascii_lower   )compile_selector_listsplit_whitespacec                   N   \ rS rSrSr\S S j5       r\S S j5       r\S!S j5       r S S jr	S r
S	 rS
 rS r\S 5       r\S 5       rS rS rS rS rS rS r\S 5       rS rS rS r\S 5       r\S 5       r\S 5       r\S 5       r \S 5       r!\S 5       r"\S 5       r#Sr$g)"ElementWrapper	   a  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                 "    U R                  XSS9$ )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      A/var/www/html/env/lib/python3.13/site-packages/cssselect2/tree.pyfrom_xml_rootElementWrapper.from_xml_root   s    " ~~du~MM    c                 "    U R                  XSS9$ )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_rootElementWrapper.from_html_root(   s     ~~dt~LLr   c           	      X    [        US5      (       a  UR                  5       nU " US SS X2S9$ )Ngetrootr   )parentindexpreviousr   r   )hasattrr   )r   r   r   r   s       r   r   ElementWrapper._from_root2   s5    4##<<>DQ-R 	Rr   c                     Xl         X l        X@l        Ub  UR                  U l        OU/U l        X0l        XPl        X`l        S U l        S U l	        g N)
etree_elementr   r    etree_childrenetree_siblingsr   r   transport_content_language
_ancestors_previous_siblings)selfr%   r   r   r    r   r   s          r   __init__ElementWrapper.__init__:   s\     +  !
 #)"7"7D#0/D 
 0*:' "&r   c                 n    [        U 5      [        U5      L =(       a    U R                  UR                  :H  $ r$   )typer%   r+   others     r   __eq__ElementWrapper.__eq__V   s0    J$u+% 6%"5"55	7r   c                     X:X  + $ r$    r0   s     r   __ne__ElementWrapper.__ne__[   s    ""r   c                 B    [        [        U 5      U R                  45      $ r$   )hashr/   r%   r+   s    r   __hash__ElementWrapper.__hash__^   s    T$Z!3!3455r   c              #   @   #    U R                  5        S h  vN   g  N7fr$   )iter_childrenr:   s    r   __iter__ElementWrapper.__iter__a   s     %%'''s   c                     U R                   c9  U R                  c  SO$/ U R                  R                  QU R                  P7U l         U R                   $ )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.

r5   )r)   r   	ancestorsr:   s    r   rB   ElementWrapper.ancestorsd   sF     ??"kk)/T1F1F/T/T Or   c                     U R                   c9  U R                  c  SO$/ U R                  R                  QU R                  P7U l         U R                   $ )u   Tuple of previous siblings.

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

r5   )r*   r    previous_siblingsr:   s    r   rE    ElementWrapper.previous_siblingsq   sM     ""*mm+A$--11A4==A # &&&r   c              #   X   #    [        S[        5        U R                   Sh  vN   g N7f)uh  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   DeprecationWarningrB   r:   s    r   iter_ancestorsElementWrapper.iter_ancestors   s&      	5	  >>!!    *(*c              #   X   #    [        S[        5        U R                   Sh  vN   g N7f)uo  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   rH   rE   r:   s    r   iter_previous_siblings%ElementWrapper.iter_previous_siblings   s(      	=	  ))))rK   c              #   x   #    U R                   c  U v   gU R                   R                  5        Sh  vN   g N7f)u   Iterate over siblings.

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

N)r   r>   r:   s    r   iter_siblingsElementWrapper.iter_siblings   s,      ;;J{{00222s   0:8:c              #   f   #    SnU R                  5        H  nU(       a  Uv   X :X  d  M  SnM     g7f)u   Iterate over next siblings.

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

FTN)rP   )r+   foundsiblings      r   iter_next_siblings!ElementWrapper.iter_next_siblings   s1      ))+G	 ,s   $11c           	   #      #    Sn[        U R                  5       H$  u  p#[        U 5      " X0X!U R                  S9nUv   M&     g7f)u   Iterate over children.

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

N)r   r   r    r   )	enumerater&   r/   r   )r+   childietree_childs       r   r>   ElementWrapper.iter_children   sF      '(;(;<NAJ!%!6!68E K	 =s   AAc              #      #    [        U /5      /nU(       aP  [        US   S5      nUc  UR                  5         O#Uv   UR                  UR	                  5       5        U(       a  MO  gg7f)ah  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appendr>   )r+   stackelements      r   iter_subtreeElementWrapper.iter_subtree   sV       tf59d+G		W2245 es   A"A(&A(c                     U  VVs/ s HX  n[        US5      (       a  U/O
[        U5        H1  nUR                  b  M  UR                  (       a  M%  UR                  PM3     MZ     snn$ s  snnf )Ntest)r!   r   pseudo_elementnever_matchesrh   )	selectorsselectorcompiled_selectors      r   _compileElementWrapper._compile   sz     &1%%h77
*845 " !// # "// #""5 #%1 	1 1s   4A)A)A)c                 L   ^  [        U 4S jT R                  U5       5       5      $ )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   2   >#    U  H  o" T5      v   M     g 7fr$   r5   ).0rh   r+   s     r   	<genexpr>)ElementWrapper.matches.<locals>.<genexpr>   s     C*B$4::*B   )anyrn   r+   rk   s   ` r   matchesElementWrapper.matches   s     C$--	*BCCCr   c                    ^ U R                  U5      m[        T5      S:X  a  [        TS   U R                  5       5      $ U(       a  U4S jU R                  5        5       $ [	        S5      $ )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   b   >^#    U  H#  m[        U4S  jT 5       5      (       d  M  Tv   M%     g7f)c              3   2   >#    U  H  o" T5      v   M     g 7fr$   r5   )rr   rh   rd   s     r   rs   5ElementWrapper.query_all.<locals>.<genexpr>.<genexpr>  s     7tG}}ru   N)rv   )rr   rd   testss    @r   rs   +ElementWrapper.query_all.<locals>.<genexpr>  s(      9':G777 ':s   /	/r5   )rn   lenfilterre   r_   )r+   rk   r~   s     @r   	query_allElementWrapper.query_all   sa     i(u:?%(D$5$5$7889'+'8'8':9 9 8Or   c                 4    [        U R                  " U6 S5      $ )a2  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   rw   s     r   queryElementWrapper.query  s     DNNI.55r   c                     U R                    Vs/ s H&  n[        UR                  [        5      (       d  M$  UPM(     sn$ s  snf )zChildren 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.

)r%   
isinstancetagstr)r+   rd   s     r   r&   ElementWrapper.etree_children!  s=     $(#5#5-#5'++s+ #5- 	- -s   #??c                 v    [        U R                  R                  5      u  pXR                  [	        S5      '   U$ )z,The local name of this element, as a string.namespace_url_split_etree_tagr%   r   __dict__r   r+   r   
local_names      r   r   ElementWrapper.local_name0  s4     %5T5G5G5K5K$L!.;c/*+r   c                 v    [        U R                  R                  5      u  pX R                  [	        S5      '   U$ )z/The namespace URL of this element, as a string.r   r   r   s      r   r   ElementWrapper.namespace_url7  s4     %5T5G5G5K5K$L!+5c,'(r   c                 8    U R                   R                  S5      $ )z$The ID of this element, as a string.id)r%   getr:   s    r   r   ElementWrapper.id>  s     !!%%d++r   c                 ^    [        [        U R                  R                  SS5      5      5      $ )z:The classes of this element, as a :class:`set` of strings.class )setr   r%   r   r:   s    r   classesElementWrapper.classesC  s(     #D$6$6$:$:7B$GHIIr   c                 j   U R                   R                  S5      nUb  [        U5      $ U R                  =(       d    U R                  S:H  nU(       a)  U R                   R                  S5      nUb  [        U5      $ U R
                  b  U R
                  R                  $ U(       aq  SnU R                   R                  S5      nU H@  nUR                  SS5      n[        U5      S:X  d  M&  [        UR                  S	5      5      nMB     Ub  [        U5      $ [        U R                  5      =(       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)
r%   r   r   r   r   r   r   r_   _parse_content_languager(   )r+   xml_langis_htmlr   r   iteratormeta
http_equivs           r   r   ElementWrapper.langH  s    %%))*VWx((!! A"@@ 	 %%))&1D"4((;;";;####))../STH !XXlB7
z*.@@'>txx	?R'S$ !  +"#344&t'F'FGM2Mr   c                   ^ U R                   c  gSnSmU R                   R                  R                  U:H  =(       aq    U R                   R                  R                  S5      S L=(       aC    U R                  R                  T:g  =(       d#    [	        U4S jU R                  5        5       5      nU=(       d    U R                   R                  $ )NFz&{http://www.w3.org/1999/xhtml}fieldsetz${http://www.w3.org/1999/xhtml}legenddisabledc              3   V   >#    U  H  nUR                   R                  T:H  v   M      g 7fr$   )r%   r   )rr   rT   legends     r   rs   6ElementWrapper.in_disabled_fieldset.<locals>.<genexpr>n  s*      8B#@ ))--7#@s   &))r   r%   r   r   rv   rM   in_disabled_fieldset)r+   fieldsetdisabled_fieldsetr   s      @r   r   #ElementWrapper.in_disabled_fieldsete  s    ;;;7KK%%))X5 CKK%%))*5TAC""&&&0 BC 8B#'#>#>#@8B 5B 	 !DDKK$D$DDr   )	r)   r*   r%   r'   r   r   r   r    r(   r$   )T)%__name__
__module____qualname____firstlineno____doc__classmethodr   r   r   r,   r2   r6   r;   r?   propertyrB   rE   rI   rM   rP   rU   r>   re   staticmethodrn   rx   r   r   r   r&   r   r   r   r   r   r   __static_attributes__r5   r   r   r
   r
   	   sc   
 N N$ M M R R 59'87
#6( 
 
 ' '"(*&
362 1 1D06 - -     , , J J N N8 E Er   r
   c                 f    U R                  S5      nUS:X  a  SU 4$ U S   S:X  d   eU SU XS-   S  4$ )N}r^   r   r   {r   )rfind)r   positions     r   r   r   t  sI    yy~H2~3w1v}}1XQJK 000r   c                 X    U b'  SU ;  a   [        U 5      n[        U5      S:X  a  US   $ g g g )N,r   r   )r   r   )valuepartss     r   r   r   }  s:    S- 'u:?8O  .r   N)	functoolsr   warningsr   webencodingsr   compilerr   r   r
   r   r   r5   r   r   <module>r      s*    %  $ =hE hEV1r   