
    Owg8                         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y)    N)warn)ascii_lower   )compile_selector_listsplit_whitespacecached_propertyc                   *    e Zd ZddZd e       fdZy)r   Nc                     |xs |j                   | _         |j                  | _        |xs |j                  | _        || _        y N)__name__
__module____doc__func)selfr   namedocs       F/var/www/horilla/myenv/lib/python3.12/site-packages/cssselect2/tree.py__init__zcached_property.__init__   s4     1DMMDM"ooDO.$,,DLDI    c                     || S |j                   j                  | j                  |      }||u r*| j                  |      }||j                   | j                  <   |S r   )__dict__getr   r   )r   objtype_cached_property__missingvalues        r   __get__zcached_property.__get__   sR    {LL$$T]]I>E	!		#.3T]]+Lr   )NN)r   r   __qualname__r   objectr    r   r   r   r      s    	 %)FH 	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"y) 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                 *    | j                  ||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Mr   c                 *    | j                  ||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Lr   c                 V    t        |d      r|j                         } | |d dd ||      S )Ngetrootr   )parentindexpreviousr%   r+   )hasattrr0   )r)   r*   r+   r%   s       r   r'   zElementWrapper._from_rootJ   s3    4#<<>DQ--/ 	/r   c                     || _         || _        || _        ||j                  | _        n|g| _        || _        || _        || _        d | _        d | _	        y 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   sh     +  !
 #)"7"7D#0/D 
 0*:' "&r   c                 f    t        |       t        |      k(  xr | j                  |j                  k(  S r   )r   r6   r   others     r   __eq__zElementWrapper.__eq__o   s0    J$u+% 6%"5"55	7r   c                     | |k(   S r   r    r=   s     r   __ne__zElementWrapper.__ne__t   s    EM""r   c                 B    t        t        |       | j                  f      S r   )hashr   r6   r   s    r   __hash__zElementWrapper.__hash__w   s    T$Z!3!3455r   c              #   @   K   | j                         E d {    y 7 wr   )iter_childrenrD   s    r   __iter__zElementWrapper.__iter__z   s     %%'''s   c                     | j                   7| 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.

        r    )r:   r1   	ancestorsrD   s    r   rJ   zElementWrapper.ancestors}   sE     ??"kk)%%6 O r   c                     | j                   7| 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.

        r    )r;   r3   previous_siblingsrD   s    r   rL   z ElementWrapper.previous_siblings   sK     ""*mm+//4==2BB # &&&r   c              #   X   K   t        dt               | j                  E d{    y7 w)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   s'      	5	  >>!!    *(*c              #   X   K   t        dt               | j                  E d{    y7 w)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   s)      	=	  ))))rP   c              #   v   K   | j                   |  y| j                   j                         E d{    y7 w)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   s-      ;;J{{00222s   /979c              #   V   K   d}| j                         D ]  }|r| || k(  sd} yw)u   Iterate over next siblings.

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

        FTN)rT   )r   foundsiblings      r   iter_next_siblingsz!ElementWrapper.iter_next_siblings   s9      ))+ 	G$		s   !))c              #      K   d}t        | j                        D ])  \  }} t        |       || ||| j                        }| + yw)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   sT      '(;(;< 	NA{DJDE!%!6!68E K		s   AAc              #      K   t        | g      g}|rIt        |d   d      }||j                          n#| |j                  |j	                                |rHyyw)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   sU       tf59d+G		W2245 s   AAAc                     | D cg c]E  }t        |d      r|gn
t        |      D ]&  }|j                  |j                  s|j                  ( G c}}S c c}}w )Ntest)r4   r   pseudo_elementnever_matchesrh   )	selectorsselectorcompiled_selectors      r   _compilezElementWrapper._compile  si     &1%h7
*841 " !//7!// ""1"1 	1 1s   A
Ac                 J     t         fd j                  |      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   | ]  } |        y wr   r    ).0rh   r   s     r   	<genexpr>z)ElementWrapper.matches.<locals>.<genexpr>  s     C$4:C   )anyrn   r   rk   s   ` r   matcheszElementWrapper.matches  s     C$--	*BCCCr   c                     | j                  |      t              dk(  rt        d   | j                               S |rfd| j                         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   L   K   | ]  t        fd D              r  yw)c              3   .   K   | ]  } |        y wr   r    )rq   rh   re   s     r   rr   z5ElementWrapper.query_all.<locals>.<genexpr>.<genexpr>*  s     7tG}7rs   N)rt   )rq   re   testss    @r   rr   z+ElementWrapper.query_all.<locals>.<genexpr>(  s'      9#777 9s    $r    )rn   lenfilterrf   r`   )r   rk   rz   s     @r   	query_allzElementWrapper.query_all  sa     i(u:?%(D$5$5$7889'+'8'8':9 9 8Or   c                 4    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)ra   r}   ru   s     r   queryzElementWrapper.query.  s     NDNNI.55r   c                 t    | j                   D cg c]  }t        |j                  t              r|  c}S c c}w )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.

        )r6   
isinstancetagstr)r   re   s     r   r7   zElementWrapper.etree_children;  s8     $(#5#5-'++s+ - 	- -s   #5c                 z    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  s8     %5T5G5G5K5K$L!z.;c/*+r   c                 z    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  s8     %5T5G5G5K5K$L!z+5c,'(r   c                 8    | j                   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                 ^    t        t        | j                  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$6$:$:7B$GHIIr   c                 2   | j                   j                  d      }|t        |      S | j                  xs | j                  dk(  }|r(| j                   j                  d      }|t        |      S | j
                  | j
                  j                  S |rld}| j                   j                  d      }|D ]=  }|j                  dd      }t        |      dk(  s$t        |j                  d	            }? |t        |      S t        | j                        xs 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  s'    %%))8:x((!! A"@@ 	 %%))&1D"4((;;";;####))..46H  -!XXlB7
z*.@@'>+(-$-
  +"#344&t'F'FGM2Mr   c                 p   | j                   yd}d| j                   j                  j                  |k(  xrf | j                   j                  j                  d      d uxr= | j                  j                  k7  xs" t	        fd| j                         D              }|xs | j                   j                  S )NFz&{http://www.w3.org/1999/xhtml}fieldsetz${http://www.w3.org/1999/xhtml}legenddisabledc              3   P   K   | ]  }|j                   j                  k(    y wr   )r6   r   )rq   rW   legends     r   rr   z6ElementWrapper.in_disabled_fieldset.<locals>.<genexpr>  s,      8B ))--78Bs   #&)r1   r6   r   r   rt   rR   in_disabled_fieldset)r   fieldsetdisabled_fieldsetr   s      @r   r   z#ElementWrapper.in_disabled_fieldset  s    ;;;7KK%%))X5 CKK%%))*5TAC""&&&0 BC 8B#'#>#>#@8B 5B 	 !DDKK$D$DDr   r   )T)#r   r   r   r   classmethodr,   r.   r'   r   r?   rA   rE   rH   propertyrJ   rL   rO   rR   rT   rX   rG   rf   staticmethodrn   rv   r}   r   r   r7   r   r   r   r   r   r   r    r   r   r"   r"   !   sa   
 N N$ M M / / 59'87
#6(   ' '"(*&
362 1 1D06 - -     , , J J N N> E Er   r"   c                 d    | j                  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     sK    yy~H2~3w1v}}1XHQJK 000r   c                 P    | $d| vrt        |       }t        |      dk(  r|d   S y y y )N,r   r   )r   r{   )r   partss     r   r   r     s:    S- 'u:?8O  .r   )	functoolswarningsr   webencodingsr   compilerr   r   r4   r   r"   r   r   r    r   r   <module>r      sJ      $ =
9'(//O (mE mE`1r   