HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/cssselect2/__pycache__/tree.cpython-310.pyc
o

%we�8�@srddlZddlmZddlmZddlmZmZeed�r!ej	Z	nGdd�d�Z	Gdd	�d	�Z
d
d�Zdd
�ZdS)�N)�warn)�ascii_lower�)�compile_selector_list�split_whitespace�cached_propertyc@s&eZdZddd�Zde�fdd�ZdS)rNcCs*|p|j|_|j|_|p|j|_||_dS�N)�__name__�
__module__�__doc__�func)�selfr�name�doc�r�H/home/arjun/projects/env/lib/python3.10/site-packages/cssselect2/tree.py�__init__s
zcached_property.__init__cCs>|dur|S|j�|j|�}||ur|�|�}||j|j<|Sr)�__dict__�getr	r)r
�obj�type�_cached_property__missing�valuerrr�__get__s
zcached_property.__get__)NN)r	r
�__qualname__r�objectrrrrrr
s
c@s&eZdZdZed:dd��Zed:dd��Zed;dd	��Z	d:d
d�Zdd
�Z	dd�Z
dd�Zdd�Ze
dd��Ze
dd��Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zed$d%��Zd&d'�Zd(d)�Zd*d+�Zed,d-��Zed.d/��Zed0d1��Zed2d3��Zed4d5��Z ed6d7��Z!ed8d9��Z"dS)<�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.

    NcC�|j||dd�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_languagerrr�
from_xml_root-szElementWrapper.from_xml_rootcCr)z�Same 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.

        Trr r"rrr�from_html_root@szElementWrapper.from_html_rootTcCs&t|d�r	|��}||ddd||d�S)N�getrootr)�parent�index�previousrr%)�hasattrr()r#r$r%rrrrr!Js
�zElementWrapper._from_rootcCsN||_||_||_|dur|j|_n|g|_||_||_||_d|_d|_	dSr)
�
etree_elementr)r+�etree_children�etree_siblingsr*r�transport_content_language�
_ancestors�_previous_siblings)r
r-r)r*r+rr%rrrrSs

zElementWrapper.__init__cCst|�t|�ko
|j|jkSr)rr-�r
�otherrrr�__eq__os
�zElementWrapper.__eq__cCs
||kSrrr3rrr�__ne__ts
zElementWrapper.__ne__cCstt|�|jf�Sr)�hashrr-�r
rrr�__hash__wszElementWrapper.__hash__ccs�|��EdHdSr)�
iter_childrenr8rrr�__iter__zs�zElementWrapper.__iter__cC�0|jdur|jdurdn|jj|jf|_|jS)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)r1r)�	ancestorsr8rrrr=}�

�zElementWrapper.ancestorscCr<)u�Tuple of previous siblings.

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

        Nr)r2r+�previous_siblingsr8rrrr?�r>z ElementWrapper.previous_siblingscc��tdt�|jEdHdS)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�DeprecationWarningr=r8rrr�iter_ancestors�s��zElementWrapper.iter_ancestorsccr@)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)rrAr?r8rrr�iter_previous_siblings�s�
�z%ElementWrapper.iter_previous_siblingsccs*�|jdur|VdS|j��EdHdS)u�Iterate over siblings.

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

        N)r)r:r8rrr�
iter_siblings�s�

zElementWrapper.iter_siblingsccs.�d}|��D]
}|r|V||krd}qdS)u�Iterate over next siblings.

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

        FTN)rD)r
�found�siblingrrr�iter_next_siblings�s���z!ElementWrapper.iter_next_siblingsccs<�d}t|j�D]\}}t|�|||||jd�}|VqdS)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.rr)r
�child�i�etree_childrrrr:�s���zElementWrapper.iter_childrenccsR�t|g�g}|r't|dd�}|dur|��n
|V|�|���|s	dSdS)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�appendr:)r
�stack�elementrrr�iter_subtree�s�
�zElementWrapper.iter_subtreecCsdd�|D�S)NcSs@g|]}t|d�r|gnt|�D]
}|jdur|js|j�qqS)�testN)r,r�pseudo_element�
never_matchesrT)�.0�selector�compiled_selectorrrr�
<listcomp>s�
��z+ElementWrapper._compile.<locals>.<listcomp>r)�	selectorsrrr�_compiles�zElementWrapper._compilecst�fdd���|�D��S)z�Return 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`.

        c3��|]}|��VqdSrr�rWrTr8rr�	<genexpr>��z)ElementWrapper.matches.<locals>.<genexpr>)�anyr\�r
r[rr8r�matchesszElementWrapper.matchescsJ|�|��t��dkrt�d|���S|r!�fdd�|��D�Std�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.

        rrc3s*�|]�t�fdd��D��r�VqdS)c3r]rrr^�rRrrr_*r`z5ElementWrapper.query_all.<locals>.<genexpr>.<genexpr>N)ra)rW��testsrdrr_(s��
�z+ElementWrapper.query_all.<locals>.<genexpr>r)r\�len�filterrSrMrbrrer�	query_alls

�zElementWrapper.query_allcGst|j|�d�S)ajReturn 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)rNrirbrrr�query.szElementWrapper.querycCsdd�|jD�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.

        cSsg|]
}t|jt�r|�qSr)�
isinstance�tag�str)rWrRrrrrZFs
��z1ElementWrapper.etree_children.<locals>.<listcomp>)r-r8rrrr.;s�zElementWrapper.etree_childrencCs"t|jj�\}}||jtd�<|S)z,The local name of this element, as a string.�
namespace_url��_split_etree_tagr-rlrrm�r
rn�
local_namerrrrrJ�zElementWrapper.local_namecCs"t|jj�\}}||jtd�<|S)z/The namespace URL of this element, as a string.rrrorqrrrrnQrszElementWrapper.namespace_urlcCs|j�d�S)z$The ID of this element, as a string.�id)r-rr8rrrrtXszElementWrapper.idcCstt|j�dd���S)z:The classes of this element, as a :class:`set` of strings.�class�)�setrr-rr8rrr�classes]szElementWrapper.classescCs�|j�d�}|durt|�S|jp|jdk}|r&|j�d�}|dur&t|�S|jdur/|jjS|rYd}|j�d�}|D]}|�dd�}t|�dkrPt|�d	��}q;|durYt|�St|j	�p_dS)
z*The language of this element, as a string.z*{http://www.w3.org/XML/1998/namespace}langNzhttp://www.w3.org/1999/xhtml�langz"{http://www.w3.org/1999/xhtml}metaz
http-equivrvzcontent-language�content)
r-rrrrnr)ryrM�_parse_content_languager0)r
�xml_lang�is_htmlryr%�iterator�meta�
http_equivrrrrybs:��
���zElementWrapper.langcsh|jdurdSd}d�|jjj|ko-|jj�d�duo-|jj�kp-t�fdd�|��D��}|p3|jjS)NFz&{http://www.w3.org/1999/xhtml}fieldsetz${http://www.w3.org/1999/xhtml}legend�disabledc3s�|]	}|jj�kVqdSr)r-rl)rWrF��legendrrr_�s
�
�
�z6ElementWrapper.in_disabled_fieldset.<locals>.<genexpr>)r)r-rlrrarC�in_disabled_fieldset)r
�fieldset�disabled_fieldsetrr�rr��s
���z#ElementWrapper.in_disabled_fieldsetr)T)#r	r
rr�classmethodr&r'r!rr5r6r9r;�propertyr=r?rBrCrDrGr:rS�staticmethodr\rcrirjrr.rrrnrtrxryr�rrrrr!sV		
�











rcCsF|�d�}|dkr
d|fS|ddksJ�|d|�||dd�fS)N�}rLrvr�{r)�rfind)rl�positionrrrrp�s

rpcCs8|durd|vrt|�}t|�dkr|dSdSdSdS)N�,rr)rrg)r�partsrrrr{�s�r{)
�	functools�warningsr�webencodingsr�compilerrrr,rrrpr{rrrr�<module>s
r