HEX
Server: Apache
System: Linux vps.rockyroadprinting.net 4.18.0 #1 SMP Mon Sep 30 15:36:27 MSK 2024 x86_64
User: rockyroadprintin (1011)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python2.7/site-packages/cssselect/xpath.pyc
�
ǁaWc@s	dZddlZddlZddlmZmZmZejddkr\eZ	e
ZneZ	eZe
d�Zdeefd��YZd	efd
��YZejd�jZejd�jZejd
�jZdefd��YZdefd��YZdS(s
    cssselect.xpath
    ===============

    Translation of parsed CSS selectors to XPath expressions.


    :copyright: (c) 2007-2012 Ian Bicking and contributors.
                See AUTHORS for more details.
    :license: BSD, see LICENSE for more details.

i����N(tparsetparse_seriest
SelectorErroriicCs+|jdd�jd�}t|||�S(Ntasciitreplace(tencodetdecodetgetattr(tobjtnametdefault((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyt_unicode_safe_getattrstExpressionErrorcBseZdZRS(s3Unknown or unsupported selector (eg. pseudo-class).(t__name__t
__module__t__doc__(((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyR#st	XPathExprcBsSeZddded�Zd�Zd�Zd�Zd�Zd�Zd�Z	RS(	tt*cCs||_||_||_dS(N(tpathtelementt	condition(tselfRRRtstar_prefix((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyt__init__+s		cCs=t|j�t|j�}|jr9|d|j7}n|S(Ns[%s](t_unicodeRRR(RR((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyt__str__0s	cCsd|jj|fS(Ns%s[%s](t	__class__R
(R((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyt__repr__6scCs/|jr"d|j|f|_n	||_|S(Ns%s and (%s)(R(RR((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyt
add_condition9s		cCs=|jdkrdS|jdtj|j��d|_dS(NRsname() = %s(RRtGenericTranslatort
xpath_literal(R((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyt
add_name_test@s
cCs|jd7_dS(se
        Append '*/' to the path to keep the context constrained
        to a single parent.
        s*/N(R(R((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytadd_star_prefixHscCsTt|�|}|jdkr/||j7}n||_|j|_|j|_|S(Ns*/(RRRR(RtcombinertotherR((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytjoinOs	(
R
RtFalseRRRRR R!R$(((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyR)s					s('+)s^[a-zA-Z_][a-zA-Z0-9_.-]*$s^[^ \t\r\n\f]+$RcBsEeZdZidd6dd6dd6dd6Zid	d	6d
d6dd
6dd6dd6dd6dd6dd6ZdZdZeZeZ	eZ
eZdd�Z
ded�Zd�Zed��Zd�Zd �Zd!�Zd"�Zd#�Zd$�Zd%�Zd&�Zd'�Zd(�Zd)�Zd*�Zd+�Zeed,�Z d-�Z!d.�Z"d/�Z#d0�Z$d1�Z%d2�Z&d3�Z'd4�Z(d5�Z)d6�Z*d7�Z+d8�Z,d9�Z-d:�Z.e.Z/e.Z0e.Z1e.Z2e.Z3e.Z4e.Z5e.Z6e.Z7d;�Z8d<�Z9d=�Z:d>�Z;d?�Z<d@�Z=dA�Z>dB�Z?RS(Cs�
    Translator for "generic" XML documents.

    Everything is case-sensitive, no assumption is made on the meaning
    of element names and attribute names.

    t
descendantt tchildt>tdirect_adjacentt+tindirect_adjacentt~texiststequalst=tincludess~=t	dashmatchs|=tprefixmatchs^=tsuffixmatchs$=tsubstringmatchs*=t	differents!=tidsxml:langsdescendant-or-self::cs&dj��fd�t|�D��S(s�Translate a *group of selectors* to XPath.

        Pseudo-elements are not supported here since XPath only knows
        about "real" elements.

        :param css:
            A *group of selectors* as an Unicode string.
        :param prefix:
            This string is prepended to the XPath expression for each selector.
            The default makes selectors scoped to the context node’s subtree.
        :raises:
            :class:`SelectorSyntaxError` on invalid selectors,
            :class:`ExpressionError` on unknown/unsupported selectors,
            including pseudo-elements.
        :returns:
            The equivalent XPath 1.0 expression as an Unicode string.

        s | c3s'|]}�j|�dt�VqdS(ttranslate_pseudo_elementsN(tselector_to_xpathtTrue(t.0tselector(tprefixR(s3/usr/lib/python2.7/site-packages/cssselect/xpath.pys	<genexpr>�s(R$R(RtcssR=((R=Rs3/usr/lib/python2.7/site-packages/cssselect/xpath.pytcss_to_xpath�scCs�t|dd�}|s.td|f��n|j|�}t||j�sUt�|r||jr||j||j�}n|p�dt	|�S(s4Translate a parsed selector to XPath.


        :param selector:
            A parsed :class:`Selector` object.
        :param prefix:
            This string is prepended to the resulting XPath expression.
            The default makes selectors scoped to the context node’s subtree.
        :param translate_pseudo_elements:
            Unless this is set to ``True`` (as :meth:`css_to_xpath` does),
            the :attr:`~Selector.pseudo_element` attribute of the selector
            is ignored.
            It is the caller's responsibility to reject selectors
            with pseudo-elements, or to account for them somehow.
        :raises:
            :class:`ExpressionError` on unknown/unsupported selectors.
        :returns:
            The equivalent XPath 1.0 expression as an Unicode string.

        tparsed_trees"Expected a parsed selector, got %rRN(
RtNonet	TypeErrortxpatht
isinstancet
xpathexpr_clstAssertionErrortpseudo_elementtxpath_pseudo_elementR(RR<R=R8ttreeRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyR9�scCstd��dS(s�Translate a pseudo-element.

        Defaults to not supporting pseudo-elements at all,
        but can be overridden by sub-classes.

        s"Pseudo-elements are not supported.N(R(RRCRG((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyRH�scCs�t|�}d|kr%d|}nad|kr>d|}nHddjgt|�D](}|rTd|krrdpud|^qT�}|S(Nt's'%s't"s"%s"s
concat(%s)t,(RR$tsplit_at_single_quotes(tstpart((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyR�s

	<cCsTt|�j}t|d|j�d�}|dkrJtd|��n||�S(s%Translate any parsed selector object.sxpath_%ss%s is not supported.N(ttypeR
RtlowerRAR(Rtparsed_selectort	type_nametmethod((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyRC�s
cCsH|j|j}t|d|�}||j|j�|j|j��S(sTranslate a combined selector.sxpath_%s_combinator(tcombinator_mappingt
combinatorRRCR<tsubselector(RtcombinedRVRT((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_combinedselectorscCs\|j|j�}|j|j�}|j�|jrK|jd|j�S|jd�SdS(Nsnot(%s)t0(RCR<RWR RR(RtnegationRCt	sub_xpath((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_negation
s
	cCs`d|jjdd�}t||d�}|sGtd|j��n||j|j�|�S(s$Translate a functional pseudo-class.sxpath_%s_functiont-t_s!The pseudo-class :%s() is unknownN(R	RRRARRCR<(RtfunctionRT((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_functionscCs]d|jjdd�}t||d�}|sGtd|j��n||j|j��S(sTranslate a pseudo-class.sxpath_%s_pseudoR^R_sThe pseudo-class :%s is unknownN(tidentRRRARRCR<(RtpseudoRT((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_pseudoscCs�|j|j}t|d|�}|jr>|jj�}n	|j}t|�}|jr�d|j|f}|o�t|j�}n|r�d|}nd|j|�}|j	r�|j
j�}n	|j
}||j|j�||�S(s Translate an attribute selector.sxpath_attrib_%ss%s:%st@sattribute::*[name() = %s](
tattribute_operator_mappingtoperatorRtlower_case_attribute_namestattribRQtis_safe_namet	namespaceRtlower_case_attribute_valuestvalueRCR<(RR<RgRTR	tsafeRiRm((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_attrib's 			
		cCs(|j|j�}|j|d|j�S(sTranslate a class selector.s@class(RCR<txpath_attrib_includest
class_name(Rtclass_selectorRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_class=scCs(|j|j�}|j|d|j�S(sTranslate an ID selector.s@id(RCR<txpath_attrib_equalsR7(Rtid_selectorRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyt
xpath_hashDscCs�|j}|sd}t}n$t|�}|jrB|j�}n|jrvd|j|f}|opt|j�}n|jd|�}|s�|j�n|S(s'Translate a type or universal selector.Rs%s:%sR(RR:Rjtlower_case_element_namesRQRkRER (RR<RRnRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyt
xpath_elementIs				
cCs|jd|�S(s;right is a child, grand-child or further descendant of lefts/descendant-or-self::*/(R$(Rtlefttright((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_descendant_combinator`scCs|jd|�S(s#right is an immediate child of leftt/(R$(RRyRz((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_child_combinatordscCs)|jd|�}|j�|jd�S(s)right is a sibling immediately after lefts/following-sibling::sposition() = 1(R$R R(RRyRzRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyt xpath_direct_adjacent_combinatorhs
cCs|jd|�S(s1right is a sibling after left, immediately or nots/following-sibling::(R$(RRyRz((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyt"xpath_indirect_adjacent_combinatornsc	Csbyt|j�\}}Wn$tk
r?td|j��nX|rS|j�n|j�|dkr�|r|d|}n|jd|�S|r�|}|}n|dkr�t|�}nd|}|dkr�d||fg}ng}|dkr|jd|�n&|dkr9|r9|jd	|�nd
j	|�}|r^|j|�n|S(NsInvalid series: '%r'islast() - %ssposition() = %ss+%sis(position() %s) mod %s = 0sposition() >= %ssposition() < (last() %s)s and (
Rt	argumentst
ValueErrorRR R!RtstrtappendR$(	RRCR`tlastR tatbtb_negtexpr((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_nth_child_functionus8




cCs|j||dt�S(NR�(R�R:(RRCR`((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_nth_last_child_function�scCs4|jdkrtd��n|j||dt�S(NRs"*:nth-of-type() is not implementedR (RRR�R%(RRCR`((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_nth_of_type_function�s
cCs:|jdkrtd��n|j||dtdt�S(NRs"*:nth-of-type() is not implementedR�R (RRR�R:R%(RRCR`((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_nth_last_of_type_function�s
cCs^|j�dgdgfkr4td|j��n|jdj}|jd|j|��S(NtSTRINGtIDENTs9Expected a single string or ident for :contains(), got %riscontains(., %s)(targument_typesRR�RmRR(RRCR`Rm((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_contains_function�scCs^|j�dgdgfkr4td|j��n|jdj}|jd|j|��S(NR�R�s5Expected a single string or ident for :lang(), got %rislang(%s)(R�RR�RmRR(RRCR`Rm((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_lang_function�scCs
|jd�S(Nsnot(parent::*)(R(RRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_root_pseudo�scCs!|j�|j�|jd�S(Nsposition() = 1(R!R R(RRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_first_child_pseudo�s

cCs!|j�|j�|jd�S(Nsposition() = last()(R!R R(RRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_last_child_pseudo�s

cCs5|jdkrtd��n|j�|jd�S(NRs"*:first-of-type is not implementedsposition() = 1(RRR!R(RRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_first_of_type_pseudo�s

cCs5|jdkrtd��n|j�|jd�S(NRs!*:last-of-type is not implementedsposition() = last()(RRR!R(RRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_last_of_type_pseudo�s

cCs!|j�|j�|jd�S(Ns
last() = 1(R R!R(RRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_only_child_pseudo�s

cCs+|jdkrtd��n|jd�S(NRs!*:only-of-type is not implementeds
last() = 1(RRR(RRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_only_of_type_pseudo�scCs
|jd�S(Nsnot(*) and not(string-length())(R(RRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_empty_pseudo�scCs
|jd�S(s:Common implementation for pseudo-classes that never match.RZ(R(RRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytpseudo_never_matches�scCs|s
t�|j|�|S(N(RFR(RRCR	Rm((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_attrib_exists�s

cCs$|jd||j|�f�|S(Ns%s = %s(RR(RRCR	Rm((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyRts cCsP|r,|jd|||j|�f�n |jd||j|�f�|S(Nsnot(%s) or %s != %ss%s != %s(RR(RRCR	Rm((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_attrib_differents		cCsKt|�r:|jd|||jd|d�f�n
|jd�|S(Ns:%s and contains(concat(' ', normalize-space(%s), ' '), %s)R'RZ(tis_non_whitespaceRR(RRCR	Rm((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyRps%
c	Cs:|jd|||j|�||j|d�f�|S(Ns'%s and (%s = %s or starts-with(%s, %s))R^(RR(RRCR	Rm((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_attrib_dashmatchs
	cCs=|r,|jd|||j|�f�n
|jd�|S(Ns%s and starts-with(%s, %s)RZ(RR(RRCR	Rm((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_attrib_prefixmatch#s
	
cCsM|r<|jd|||t|�d|j|�f�n
|jd�|S(Ns/%s and substring(%s, string-length(%s)-%s) = %siRZ(RtlenR(RRCR	Rm((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_attrib_suffixmatch+s-
cCs=|r,|jd|||j|�f�n
|jd�|S(Ns%s and contains(%s, %s)RZ(RR(RRCR	Rm((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pytxpath_attrib_substringmatch5s
	
(@R
RRRURftid_attributetlang_attributeR%RwRhRlRRER?R9RHtstaticmethodRRCRYR]RaRdRoRsRvRxR{R}R~RR:R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�txpath_link_pseudotxpath_visited_pseudotxpath_hover_pseudotxpath_active_pseudotxpath_focus_pseudotxpath_target_pseudotxpath_enabled_pseudotxpath_disabled_pseudotxpath_checked_pseudoR�RtR�RpR�R�R�R�(((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyRgs�

																	(																	
					
tHTMLTranslatorcBsMeZdZdZed�Zd�Zd�Zd�Zd�Z	d�Z
RS(s�
    Translator for (X)HTML documents.

    Has a more useful implementation of some pseudo-classes based on
    HTML-specific element names and attribute names, as described in
    the `HTML5 specification`_. It assumes no-quirks mode.
    The API is the same as :class:`GenericTranslator`.

    .. _HTML5 specification: http://www.w3.org/TR/html5/links.html#selectors

    :param xhtml:
        If false (the default), element names and attribute names
        are case-insensitive.

    tlangcCs(||_|s$t|_t|_ndS(N(txhtmlR:RwRh(RR�((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyRRs		cCs
|jd�S(Ns�(@selected and name(.) = 'option') or (@checked and (name(.) = 'input' or name(.) = 'command')and (@type = 'checkbox' or @type = 'radio'))(R(RRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyR�YscCsq|j�dgdgfkr4td|j��n|jdj}|jd|j|j|j�d�f�S(NR�R�s5Expected a single string or ident for :lang(), got %ris�ancestor-or-self::*[@lang][1][starts-with(concat(translate(@%s, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), '-'), %s)]R^(R�RR�RmRR�RRQ(RRCR`Rm((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyR�ascCs
|jd�S(NsA@href and (name(.) = 'a' or name(.) = 'link' or name(.) = 'area')(R(RRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyR�oscCs
|jd�S(Ns�
        (
            @disabled and
            (
                (name(.) = 'input' and @type != 'hidden') or
                name(.) = 'button' or
                name(.) = 'select' or
                name(.) = 'textarea' or
                name(.) = 'command' or
                name(.) = 'fieldset' or
                name(.) = 'optgroup' or
                name(.) = 'option'
            )
        ) or (
            (
                (name(.) = 'input' and @type != 'hidden') or
                name(.) = 'button' or
                name(.) = 'select' or
                name(.) = 'textarea'
            )
            and ancestor::fieldset[@disabled]
        )
        (R(RRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyR�vscCs
|jd�S(Ns'
        (
            @href and (
                name(.) = 'a' or
                name(.) = 'link' or
                name(.) = 'area'
            )
        ) or (
            (
                name(.) = 'command' or
                name(.) = 'fieldset' or
                name(.) = 'optgroup'
            )
            and not(@disabled)
        ) or (
            (
                (name(.) = 'input' and @type != 'hidden') or
                name(.) = 'button' or
                name(.) = 'select' or
                name(.) = 'textarea' or
                name(.) = 'keygen'
            )
            and not (@disabled or ancestor::fieldset[@disabled])
        ) or (
            name(.) = 'option' and not(
                @disabled or ancestor::optgroup[@disabled]
            )
        )
        (R(RRC((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyR��s(R
RRR�R%RR�R�R�R�R�(((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyR�?s				(Rtsystretcssselect.parserRRRtversion_infot
basestringt_basestringtunicodeRR�RARtRuntimeErrorRtobjectRtcompiletsplitRMtmatchRjR�RR�(((s3/usr/lib/python2.7/site-packages/cssselect/xpath.pyt<module>
s"	1��