https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/genshi/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/genshi/__pycache__/path.cpython-310.pyc
o

!�b8��@s�dZddlmZddlmZddlmZmZddlZddl	Z	ddl
mZddlZddl
mZddlmZmZmZmZdd	lmZmZmZmZmZmZmZmZmZd
dgZdZGd
d�de�Z e j!Z!e j"Z"e j#Z#e j$Z$e j%Z%Gdd�de�Z&Gdd�de�Z'Gdd�de�Z(Gdd
�d
e�Z)Gdd�de*�Z+Gdd�de�Z,dd�Z-dd�Z.dd�Z/dd �Z0d!d"�Z1Gd#d$�d$e�Z2Gd%d&�d&e�Z3Gd'd(�d(e�Z4Gd)d*�d*e�Z5Gd+d,�d,e�Z6Gd-d.�d.e�Z7Gd/d0�d0e�Z8Gd1d2�d2e�Z9e6e7e8e9d3�Z:Gd4d5�d5e�Z;Gd6d7�d7e;�Z<Gd8d9�d9e;�Z=Gd:d;�d;e;�Z>Gd<d=�d=e;�Z?Gd>d?�d?e;�Z@Gd@dA�dAe;�ZAGdBdC�dCe;�ZBGdDdE�dEe;�ZCGdFdG�dGe;�ZDGdHdI�dIe;�ZEGdJdK�dKe;�ZFGdLdM�dMe;�ZGGdNdO�dOe;�ZHGdPdQ�dQe;�ZIGdRdS�dSe;�ZJGdTdU�dUe;�ZKGdVdW�dWe;�ZLGdXdY�dYe;�ZMGdZd[�d[e;�ZNGd\d]�d]e;�ZOGd^d_�d_e;�ZPid`e<�dae=�dbe>�dce?�dde@�deeA�dfeB�dgeC�dheD�dieE�djeG�dkeF�dleH�dmeI�dneJ�doeK�dpeL�eMeNeOePdq��ZQGdrds�dse�ZRGdtdu�dueR�ZSGdvdw�dweR�ZTGdxdy�dyeR�ZUGdzd{�d{e�ZVGd|d}�d}e�ZWGd~d�de�ZXGd�d��d�e�ZYGd�d��d�e�ZZGd�d��d�e�Z[Gd�d��d�e�Z\Gd�d��d�e�Z]eWeXeZe[e\e]d��Z^e$e2d�d�fZ_e%e2d�d�fZ`dS)�aDBasic support for evaluating XPath expressions against streams.

>>> from genshi.input import XML
>>> doc = XML('''<doc>
...  <items count="4">
...       <item status="new">
...         <summary>Foo</summary>
...       </item>
...       <item status="closed">
...         <summary>Bar</summary>
...       </item>
...       <item status="closed" resolution="invalid">
...         <summary>Baz</summary>
...       </item>
...       <item status="closed" resolution="fixed">
...         <summary>Waz</summary>
...       </item>
...   </items>
... </doc>''')
>>> print(doc.select('items/item[@status="closed" and '
...     '(@resolution="invalid" or not(@resolution))]/summary/text()'))
BarBaz

Because the XPath engine operates on markup streams (as opposed to tree
structures), it only implements a subset of the full XPath 1.0 language.
�)�deque)�reduce)�ceil�floorN)�chain)�
IS_PYTHON2)�Stream�Attrs�	Namespace�QName)	�START�END�TEXT�START_NS�END_NS�COMMENT�PI�START_CDATA�	END_CDATA�Path�PathSyntaxErrorzrestructuredtext enc@s0eZdZdZdZdZdZdZdZe	dd��Z
d	S)
�Axisz7Defines constants for the various supported XPath axes.�	attribute�child�
descendantzdescendant-or-self�selfcCst||���dd�d�S)zdReturn the axis constant for the given name, or `None` if no such
        axis was defined.
        �-�_N)�getattr�upper�replace)�cls�name�r#�-/usr/lib/python3/dist-packages/genshi/path.py�fornameDszAxis.fornameN)�__name__�
__module__�__qualname__�__doc__�	ATTRIBUTE�CHILD�
DESCENDANT�DESCENDANT_OR_SELF�SELF�classmethodr%r#r#r#r$r;src@�(eZdZedd��Zdd�Zdd�ZdS)�GenericStrategycC�dS�NTr#�r!�pathr#r#r$�supportsUszGenericStrategy.supportscC�
||_dS�N�r5�rr5r#r#r$�__init__Y�
zGenericStrategy.__init__cs�|j}|r(|ddturtg|�n5t|dd|ddfg|dd��n |ddtus@|ddtus@|ddturFtg|�n|�dggfgg�d��fdd�	}|S)Nr��Fcs�|dd�\}}}d}|tur�r���dS|tus'|tus'|tus'|tur)dStdd��dD��}g}	t���ddtkpBd}
d}|�r\|�	�\}}
}�|\}}}|t
us_|tur||
r||	ru|	dd|kru|	dd�|
�n|	�
||
f�||||||�s�qFt�}t|
�t|�}d}d}|r�|D]U}||||||�}t|�tur�tt|
|��D]+\}}||vr�q�t|�|dkr�|�
d�||d7<||t|�kr�|�|�q�t|�|kr�d}|d7}|s�d}nq�|s�qFg}|d|
k�rd}�d\}}}|tu�r||||||�}|�r|}nD�|dd}|tu�s(|tu�rK|�r6|dd|dk�rB|�|dg|gf�n	|dd	�
|�|tu�rZ|	�
|d|gf�|sI|tu�rf��
|	�|S)
N�cSsg|]	\}}||gf�qSr#r#)�.0�pos�cour#r#r$�
<listcomp>��z7GenericStrategy.test.<locals>._test.<locals>.<listcomp>���rr=TFr>)r
�poprrrrr�lenr*�popleftr,r-�extend�append�set�type�float�	enumerater�int�addr.�
appendleftr)�event�
namespaces�	variables�
updateonly�kind�datarA�retval�	pos_queue�next_pos�real_len�last_checked�x�pcou�mcou�axis�nodetest�
predicates�missed�counters_len�cnum�matched�	predicate�pretval�irB�
child_counter�	next_axis��stack�stepsr#r$�_testss��

��

��
�
Z
z#GenericStrategy.test.<locals>._test�F)r5r*�_DOTSLASHSLASHr-r+r,�	_DOTSLASH)r�ignore_context�pror#rlr$�test\s* 
vzGenericStrategy.testN�r&r'r(r/r6r;rur#r#r#r$r1S�

r1c@s,eZdZdZedd��Zdd�Zdd�ZdS)	�SimplePathStrategyzCStrategy for path with only local names, attributes and text nodes.cCsL|ddtur
dStttf}|D]\}}}|rdSt||�s#dSqdS)NrFT)r*�
LocalNameTest�CommentNodeTest�TextNodeTest�
isinstance)r!r5�
allowed_testsrrarbr#r#r$r6�s

�zSimplePathStrategy.supportscs$g|_d}g}dd���fdd�}|D]n}|dtur<t|�dkr2|d|ddkr1d|_dSqd	}|�|d�q|dturJ|�|d�q|dturc||�}|j�|||d|f�dS||�}|j�||d|f�|dg}|dturd}qd	}q||�}|j�||d|f�dS)
NFcSs0t|�t|�ur
dSt|�tkr|j|jkSdS)z!Tests if two node tests are equalFT)rLryr")�node1�node2r#r#r$�nodes_equals
z0SimplePathStrategy.__init__.<locals>.nodes_equalcs�t|�dkrgSdg}d}tdt|��D]4}|dkr6�||||�s6||d}|dkr6�||||�r#�||||�rC|d7}|�|�q|S)z KMP prefix calculation for tablerr=)rG�rangerJ)�f�pi�sri�r�r#r$�calculate_pis�z1SimplePathStrategy.__init__.<locals>.calculate_pirr=rET)�	fragmentsr.rGrJr+r*r,)rr5�self_beginning�fragmentr�r`r�r#r�r$r;�s8�
zSimplePathStrategy.__init__cs:g��j��j�|j�t���d������fdd�	}|S)NFcs��durdS|dd�\}}}|tur�r��dS|tus*|tus*|tus*|tur,dS�s^d}�|ds@|d7}�|dr6d}�pG|dk}	�|ds]�rT|dkr]�|||	f�dSn�d\}}}	|dur�|	s��|\}
}}}
t|
�}||kr|n|
||||||�r�|d7}nd\}}||kr�|d�kr�|d7}d}d}	|dur�|tur��|||	f�dS|	�r	�|\}
}}}
t|
�}|dkr�||ks�|
||||||�s�||d}|dkr�||ks�|
||||||�r�|
||||||�r�|d7}||k�r|d�k�rn|d7}d}d}	�|d�snnnq�|tu�r=|	�s6|d�k�r6||k�r6�dd|	f�n�|||	f�|d�k�rV||k�rV|�rT||||||�SdSdS)Nr?rr=rE�NNT)r
rrrrrGr)rRrSrTrUrVrWrA�fidrt�ic�fragr��attribr�frag_len��frags�	frags_lenrsrm�	stack_pop�
stack_pushr#r$roJs���
���
��
z&SimplePathStrategy.test.<locals>._testrp)rJrFr�rG�rrsror#r�r$ru?snzSimplePathStrategy.testN)r&r'r(r)r/r6r;rur#r#r#r$rx�s
Drxc@r0)�SingleStepStrategycCst|�dkS�Nr=)rGr4r#r#r$r6��zSingleStepStrategy.supportscCr7r8r9r:r#r#r$r;�r<zSingleStepStrategy.__init__csd|j��ddturtg���ddtur�ddpd�g�dg�d�����fdd�	}|S)NrrEr=Fcs�|dd�\}}}|tur�s�dd8<dS|tus)|tus)|tus)|tur+dS�sg�ddtur;�ddkpV�ddtuoH�ddkpV�ddtuoV�ddk}|turc�dd7<|rgdS�d\}}	}
|	|||||�sxdS|
r�d}|
D]8}||||||�}
t	|
�t
ur�t��|dkr���d��|d7<�|t
|
�kr�d}
|d7}|
s�dSq~�r��|||||�SdS)Nr?rr=FT)r
rrrrr.r+r,rrLrMrGrJrO)rRrSrTrUrVrWrA�outsider`rarbrergrh��counters�depthrs�select_attrrnr#r$ro�sL��
�z&SingleStepStrategy.test.<locals>._testrp)r5r*rrr�r#r�r$ru�s
 /zSingleStepStrategy.testNrvr#r#r#r$r��rwr�c@s@eZdZdZeeefZd
dd�Zdd�Z	ddd	�Z
ddd�ZdS)rz�Implements basic XPath support on streams.
    
    Instances of this class represent a "compiled" XPath expression, and
    provide methods for testing the path against a stream, as well as
    extracting a substream matching that path.
    NrEcCs`||_t|||���|_g|_|jD]}|jD]}|�|�r(|j�||��nqtd��qdS)a)Create the path object from a string.
        
        :param text: the path expression
        :param filename: the name of the file in which the path expression was
                         found (used in error messages)
        :param lineno: the line on which the expression was found
        zNo strategy found for pathN)	�source�
PathParser�parse�paths�
strategies�
STRATEGIESr6rJ�NotImplementedError)r�text�filename�linenor5�strategy_classr#r#r$r;s


���z
Path.__init__cCs|g}|jD],}g}|D]\}}}|�d||f�|D]}|dd|7<qq|�d�|��qdt|�jd�|�fS)Nz%s::%srEz[%s]�/z	<%s "%s">�|)r�rJ�joinrLr&)rr�r5rnr`rarbrgr#r#r$�__repr__s
�z
Path.__repr__csJ|duri}|duri}t|�}|||f�fdd�	}t|�t|dd�d�S)a�Returns a substream of the given stream that matches the path.
        
        If there are no matches, this method returns an empty stream.
        
        >>> from genshi.input import XML
        >>> xml = XML('<root><elem><child>Text</child></elem></root>')
        
        >>> print(Path('.//child').select(xml))
        <child>Text</child>
        
        >>> print(Path('.//child/text()').select(xml))
        Text
        
        :param stream: the stream to select from
        :param namespaces: (optional) a mapping of namespace prefixes to URIs
        :param variables: (optional) a mapping of variable names to values
        :return: the substream matching the path, or an empty stream
        :rtype: `Stream`
        Nc	3s���fdd�}���}�D]H}||||�}|durP|V|dturOd}|dkrO|�}|dtur6|d7}n
|dtur@|d8}|V||||dd�|dks(q
|rU|Vq
dS)Ncst��Sr8)�nextr#��streamr#r$�<lambda>Csz0Path.select.<locals>._generate.<locals>.<lambda>Trr=�rU)rurr
)	r��ns�vs�_nextrurR�resultr��subevent�rr�r$�	_generateBs.�
����zPath.select.<locals>._generate�
serializer)r�)�iterrr)rr�rSrTr�r#r�r$�select)s
�zPath.selectFcs:�fdd�|jD��t��dkr�dSd	�fdd�	}|S)
a1Returns a function that can be used to track whether the path matches
        a specific stream event.
        
        The function returned expects the positional arguments ``event``,
        ``namespaces`` and ``variables``. The first is a stream event, while the
        latter two are a mapping of namespace prefixes to URIs, and a mapping
        of variable names to values, respectively. In addition, the function
        accepts an ``updateonly`` keyword argument that default to ``False``. If
        it is set to ``True``, the function only updates its internal state,
        but does not perform any tests or return a result.
        
        If the path matches the event, the function returns the match (for
        example, a `START` or `TEXT` event.) Otherwise, it returns ``None``.
        
        >>> from genshi.input import XML
        >>> xml = XML('<root><elem><child id="1"/></elem><child id="2"/></root>')
        >>> test = Path('child').test()
        >>> namespaces, variables = {}, {}
        >>> for event in xml:
        ...     if test(event, namespaces, variables):
        ...         print('%s %r' % (event[0], event[1]))
        START (QName('child'), Attrs([(QName('id'), '2')]))
        
        :param ignore_context: if `True`, the path is interpreted like a pattern
                               in XSLT, meaning for example that it will match
                               at any depth
        :return: a function that can be used to test individual events in a
                 stream against the path
        :rtype: ``function``
        csg|]}|����qSr#)ru)r@r�)rsr#r$rCw�zPath.test.<locals>.<listcomp>r=rFcs.d}�D]}|||||d�}|dur|}q|S)Nr�r#)rRrSrTrUrXru�val)�testsr#r$�_multi{s�zPath.test.<locals>._multiNrp)r�rG)rrsr�r#)rsr�r$ruXs
z	Path.test�NrEr�rp)r&r'r(r)r�rxr1r�r;r�r�rur#r#r#r$rs


/c@seZdZdZddd�ZdS)rzEException raised when an XPath expression is syntactically incorrect.NrEcCs4|r	d|||f}t�||�||_||_||_dS)Nz%s (%s, line %d))�	Exceptionr;r�r��offset)r�messager�r�r�r#r#r$r;�s
zPathSyntaxError.__init__)NrErE)r&r'r(r)r;r#r#r#r$r�sc@s�eZdZdZdZdZe�dd�dd�eD��d�d	d�eD��f�j	Z
d0dd
�Zedd��Z
edd��Zdd�Zdd�Zdd�Zdd�Zdd�Zd1dd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd
S)2r�z)Tokenizes and parses an XPath expression.))�'r�)�"r�)�::�:�..�.�//r��[�]�()�(�)�@�=�!=�!r��,�>=�>z<=�<�$z7("[^"]*")|('[^']*')|((?:\d+)?\.\d+)|(%s)|([^%s\s]+)|\s+r�cCsg|]}t�|��qSr#��re�escape�r@�tr#r#r$rC�r�zPathParser.<listcomp>�cCsg|]	}t�|d��qS)rr�r�r#r#r$rC�rDNrEcCs6||_||_dd�dd�|�|�D�D�|_d|_dS)NcSsg|]}|r|�qSr#r#r�r#r#r$rC�s
�z'PathParser.__init__.<locals>.<listcomp>cSs*g|]\}}}}}|p|p|p|p|�qSr#r#)r@�dqstr�sqstr�number�tokenr"r#r#r$rC�s�r)r�r��	_tokenize�tokensrA)rr�r�r�r#r#r$r;�s�
zPathParser.__init__cCs|jt|j�dkSr�)rArGr�r�r#r#r$�at_end�szPathParser.at_endcCs|j|jSr8)r�rAr�r#r#r$�	cur_token�r�zPathParser.cur_tokencCs|jd7_|j|jSr�)rAr�r�r#r#r$�
next_token�szPathParser.next_tokencCs|js|j|jdSdSr�)r�r�rAr�r#r#r$�
peek_token�szPathParser.peek_tokencCsT|��g}|jdkr|��|�|���|jdks
|js(td|j|j|j��|S)a�Parses the XPath expression and returns a list of location path
        tests.
        
        For union expressions (such as `*|text()`), this function returns one
        test for each operand in the union. For patch expressions that don't
        use the union operator, the function always returns a list of size 1.
        
        Each path test in turn is a sequence of tests that correspond to the
        location steps, each tuples of the form `(axis, testfunc, predicates)`
        r�z+Unexpected token %r after end of expression)�_location_pathr�r�rJr�rr�r�)rr�r#r#r$r��s


���zPathParser.parsecCs�g}	|j�d�rJ|s8|jdkr0|��|��\}}}|�t||f�|js,|j�d�s/	|Sqtd|j|j	��|jdkrF|�tt
�gf�|��|��\}}}|sUt}|�|||f�|jsf|j�d�si	|Sq)NTr�r�z%Absolute location paths not supported)r��
startswithr��_location_steprJr-r�rr�r��NodeTestr+)rrnr`rarbr#r#r$r��s:
���
�zPathParser._location_pathcCs�|jdkrt}|��n:|jdkrt}n2|jdkr!td|j|j��|��dkrDt�	|j�}|dur;td||j|j��|��|��nd}|�
|pKt�}g}|jdkr`|�|�
��|jdksT|||fS)Nr�r�r�zUnsupported axis "parent"r�zUnsupport axis "%s"r�)r�r*r�r.rr�r�r�rr%�
_node_testr+rJ�
_predicate)rr`rarbr#r#r$r��s0



��


�
zPathParser._location_stepcCs�d}}|��}|dvr|��}n9|dkr1|j}|��|��}|dkr*t||�}n t|||�}n|jdkr;t|�}n|jdkrDt�}nt||j�}|j	sQ|��|S)N)r�r�r��*r�)
r��
_node_typer�r��QualifiedPrincipalTypeTest�QualifiedNameTest�PrincipalTypeTestr�ryr�)rr`ru�prefixr��	localnamer#r#r$r�s&



zPathParser._node_testcCs�|j}|��g}|jdkr0|��|jdkr0|j}|d|df|jvr+|dd�}|�|�t�|�}|sAtd||j|j��||�S)Nr�r�rrEr=z%s() not allowed here)	r�r��_QUOTESrJ�
_nodetest_map�getrr�r�)rr"�args�stringr!r#r#r$r�s 



�zPathParser._node_typecCsP|jdksJ�|��|��}|jdkrtd|j|j|j��|js&|��|S)Nr�r�z/Expected "]" to close predicate, but found "%s")r�r��_or_exprrr�r�r��r�exprr#r#r$r�3s
��zPathParser._predicatecC�6|��}|jdkr|��t||���}|jdks	|S)N�or)�	_and_exprr�r��
OrOperatorr�r#r#r$r�?�

�zPathParser._or_exprcCr�)N�and)�_equality_exprr�r��AndOperatorr�r#r#r$rFrzPathParser._and_exprcC�@|��}|jdvrt|j}|��|||���}|jdvs	|S)N)r�r�)�_relational_exprr��
_operator_mapr��rr��opr#r#r$rM�


�zPathParser._equality_exprcCr)N)r�r�r�r�)�	_sub_exprr�rr�r	r#r#r$rUrzPathParser._relational_exprcCsR|j}|dkr|��S|��|��}|jdkr#td|j|j|j��|��|S)Nr�r�z4Expected ")" to close sub-expression, but found "%s")r��
_primary_exprr�r�rr�r�)rr�r�r#r#r$r]s
��zPathParser._sub_exprcCs�|j}t|�dkr |d|df|jvr |��t|dd��S|d��s,|ddkr6|��tt|��S|dkrF|��}|��t|�S|j	sT|�
��d�rT|��Sd}|dkr`t
}|��|�|�S)Nr=rrEr�r�r�r�)r�rGr�r��
StringLiteral�isdigit�
NumberLiteral�as_float�VariableReferencer�r�r��_function_callr*r�)rr�r`r#r#r$r
js$"
zPathParser._primary_exprcCs�|j}|��dkrg}n5|jdksJ�|��|��g}|jdkr1|��|�|���|jdks!|jdksAtd|j|j|j��|��t�|�}|sVtd||j|j��||�S)Nr�r�r�r�z<Expected ")" to close function argument list, but found "%s"zUnsupported function "%s")	r�r�r�rJrr�r��
_function_mapr�)rr"r�r!r#r#r$rs.


�
��
�zPathParser._function_callr�r8)r&r'r(r)r��_TOKENSr��compiler��findallr�r;�propertyr�r�r�r�r�r�r�r�r�r�r�rrrrr
rr#r#r#r$r��s<��





r�cCs*t|t�rt|�dks
J�|ddS|S)zConvert value to a scalar. If a single element Attrs() object is passed
    the value of the single attribute will be returned.r=r)r|r	rG��valuer#r#r$�	as_scalar�s
rcC�tt|��Sr8)rMrrr#r#r$r�srcCstrtnt}|t|��Sr8)r�longrOr)r�long_clsr#r#r$�as_long�srcCst|�}|dur
dSt�|�S)NFr�)r�six�	text_typerr#r#r$�	as_string�s
r"cCrr8)�boolrrr#r#r$�as_bool��r$c@�.eZdZdZdgZdd�Zdd�Zdd�Zd	S)
r�z?Node test that matches any event with the given principal type.�principal_typecCr7r8)r')rr'r#r#r$r;�r<zPrincipalTypeTest.__init__cCs&|tur|jtur|dpdSdSdS)Nr=T)rr'r*�rrVrWrArSrTr#r#r$�__call__�s

�zPrincipalTypeTest.__call__cCr2)Nr�r#r�r#r#r$r���zPrincipalTypeTest.__repr__N�r&r'r(r)�	__slots__r;r)r�r#r#r#r$r��sr�c@�0eZdZdZddgZdd�Zdd�Zdd	�Zd
S)r�z[Node test that matches any event with the given principal type in a
    specific namespace.r'r�cC�||_||_dSr8)r'r�)rr'r�r#r#r$r;��
z#QualifiedPrincipalTypeTest.__init__csXt|�|j���|tur*|jtur$|dr$t�fdd�|dD��p#dS|d�vSdS)Nr=cs g|]\}}|�vr||f�qSr#r#)r@r"r��	namespacer#r$rC�s�z7QualifiedPrincipalTypeTest.__call__.<locals>.<listcomp>r)r
r�r�rr'r*r	r(r#r0r$r)�s��z#QualifiedPrincipalTypeTest.__call__cC�
d|jS)Nz%s:*)r�r�r#r#r$r��r<z#QualifiedPrincipalTypeTest.__repr__Nr+r#r#r#r$r��sr�c@r-)ryzWNode test that matches any event with the given principal type and
    local name.
    r'r"cCr.r8)r'r")rr'r"r#r#r$r;�r/zLocalNameTest.__init__cCsP|tur&|jtur|j|dvrt|j|d�|j�fg�S|dj|jkSdS)Nr=r)rr'r*r"r	r�r�r(r#r#r$r)�s
�zLocalNameTest.__call__cC�|jSr8�r"r�r#r#r$r���zLocalNameTest.__repr__Nr+r#r#r#r$ry�sryc@�0eZdZdZgd�Zdd�Zdd�Zdd�Zd	S)
r�z[Node test that matches any event with the given principal type and
    qualified name.
    �r'r�r"cC�||_||_||_dSr8r7)rr'r�r"r#r#r$r;��
zQualifiedNameTest.__init__cCs`td|�|j�|jf�}|tur.|jtur(||dvr(t||d�|�fg�S|d|kSdS)Nz%s}%sr=r)rr�r�r"rr'r*r	)rrVrWrArSrT�qnamer#r#r$r)�s�zQualifiedNameTest.__call__cC�d|j|jfS)Nz%s:%s)r�r"r�r#r#r$r���zQualifiedNameTest.__repr__Nr+r#r#r#r$r���r�c@�$eZdZdZgZdd�Zdd�ZdS)rzz*Node test that matches any comment events.cC�|tuSr8)rr(r#r#r$r)��zCommentNodeTest.__call__cCr2)Nz	comment()r#r�r#r#r$r��r*zCommentNodeTest.__repr__N�r&r'r(r)r,r)r�r#r#r#r$rz��
rzc@r>)r�z Node test that matches any node.cCs|turdS|||fSr3�rr(r#r#r$r)s
zNodeTest.__call__cCr2)Nznode()r#r�r#r#r$r�	r*zNodeTest.__repr__NrAr#r#r#r$r�s
r�c@s0eZdZdZdgZd
dd�Zdd�Zdd	�ZdS)�ProcessingInstructionNodeTestz8Node test that matches any processing instruction event.�targetNcCr7r8�rE)rrEr#r#r$r;r<z&ProcessingInstructionNodeTest.__init__cCs|tuo|jp|d|jkS�Nr)rrEr(r#r#r$r)sz&ProcessingInstructionNodeTest.__call__cCs d}|jrd|jd}d|S)Nr�r�zprocessing-instruction(%s)rF)r�argr#r#r$r�sz&ProcessingInstructionNodeTest.__repr__r8r+r#r#r#r$rDs
rDc@r>)r{z&Node test that matches any text event.cCr?r8)rr(r#r#r$r)r@zTextNodeTest.__call__cCr2)Nztext()r#r�r#r#r$r�r*zTextNodeTest.__repr__NrAr#r#r#r$r{rBr{)�comment�nodezprocessing-instructionr�c@�eZdZdZdS)�Functionz3Base class for function nodes in XPath expressions.N�r&r'r(r)r#r#r#r$rL'�rLc@s2eZdZdZdgZeZdd�Zdd�Zdd�Z	d	S)
�BooleanFunctionzPThe `boolean` function, which converts its argument to a boolean
    value.
    r�cCr7r8�r�r�r#r#r$r;0r<zBooleanFunction.__init__cC�|�|||||�}t|�Sr8)r�r$�rrVrWrArSrTr�r#r#r$r)2�zBooleanFunction.__call__cCr2)Nzboolean(%r)rPr�r#r#r$r�5r<zBooleanFunction.__repr__N)
r&r'r(r)r,r#�_return_typer;r)r�r#r#r#r$rO*srOc@r&)
�CeilingFunctionzeThe `ceiling` function, which returns the nearest lower integer number
    for the given number.
    r�cCr7r8�r��rr�r#r#r$r;=r<zCeilingFunction.__init__cC�|�|||||�}tt|��Sr8)r�rr�rrVrWrArSrTr�r#r#r$r)?�zCeilingFunction.__call__cCr2)Nzceiling(%r)rVr�r#r#r$r�Br<zCeilingFunction.__repr__Nr+r#r#r#r$rU8�rUc@r&)
�ConcatFunctionzoThe `concat` function, which concatenates (joins) the variable number of
    strings it gets as arguments.
    �exprscGr7r8)r])rr]r#r#r$r;Jr<zConcatFunction.__init__cs>g}�����fdd�|jD�D]	}|�t|��qd�|�S)Ncsg|]
}|�������qSr#r#�r@r��rWrVrSrArTr#r$rCNs�z+ConcatFunction.__call__.<locals>.<listcomp>r�)r]rJr"r�)rrVrWrArSrT�strings�itemr#r_r$r)Ls
�
zConcatFunction.__call__cCsdd�dd�|jD��S)Nz
concat(%s)z, cS�g|]}t|��qSr#)�reprr^r#r#r$rCS�z+ConcatFunction.__repr__.<locals>.<listcomp>)r�r]r�r#r#r$r�RszConcatFunction.__repr__Nr+r#r#r#r$r\Esr\c@r-)�ContainsFunctionz\The `contains` function, which returns whether a string contains a given
    substring.
    �string1�string2cCr.r8�rfrg�rrfrgr#r#r$r;Zr/zContainsFunction.__init__cCs4|�|||||�}|�|||||�}t|�t|�vSr8)rfrgr"�rrVrWrArSrTrfrgr#r#r$r)]�zContainsFunction.__call__cCr;�Nzcontains(%r, %r)rhr�r#r#r$r�ar<zContainsFunction.__repr__Nr+r#r#r#r$reU�rec@sPeZdZdZddgZejejejej	d�Z
ddd�Zdd	�Zd
d�Z
dd
�ZdS)�MatchesFunctionz]The `matches` function, which returns whether a string matches a regular
    expression.
    rfrg)r��mrir]r�cCs||_||_|�|�|_dSr8)rfrg�
_map_flags�flags)rrfrgrqr#r#r$r;kszMatchesFunction.__init__cCs<t|�|||||��}t|�|||||��}t�|||j�Sr8)r"rfrgr��searchrqrjr#r#r$r)oszMatchesFunction.__call__csttj�fdd�|D�tj�S)Ncsg|]}�j|�qSr#)�flag_map)r@�flagr�r#r$rCur�z.MatchesFunction._map_flags.<locals>.<listcomp>)r�operator�or_r��U)rrqr#r�r$rpss�zMatchesFunction._map_flagscCr;rlrhr�r#r#r$r�vr<zMatchesFunction.__repr__N)r�)r&r'r(r)r,r��S�M�I�X�flag_mappingr;r)rpr�r#r#r#r$rnds
rnc@r>)�
FalseFunctionzEThe `false` function, which always returns the boolean `false` value.cCr2�NFr#r(r#r#r$r)|r*zFalseFunction.__call__cCr2)Nzfalse()r#r�r#r#r$r�~r*zFalseFunction.__repr__NrAr#r#r#r$r}yrBr}c@r&)
�
FloorFunctionzfThe `ceiling` function, which returns the nearest higher integer number
    for the given number.
    r�cCr7r8rVrWr#r#r$r;�r<zFloorFunction.__init__cCrXr8)r�rrrYr#r#r$r)�rZzFloorFunction.__call__cCr2)Nz	floor(%r)rVr�r#r#r$r��r<zFloorFunction.__repr__Nr+r#r#r#r$r�r[rc@r>)�LocalNameFunctionzXThe `local-name` function, which returns the local name of the current
    element.
    cC�|tur	|djSdSrG)rr�r(r#r#r$r)��
�zLocalNameFunction.__call__cCr2)Nzlocal-name()r#r�r#r#r$r��r*zLocalNameFunction.__repr__NrAr#r#r#r$r���
r�c@r>)�NameFunctionzVThe `name` function, which returns the qualified name of the current
    element.
    cCs|tur|dSdSrGrCr(r#r#r$r)�s�zNameFunction.__call__cCr2)Nzname()r#r�r#r#r$r��r*zNameFunction.__repr__NrAr#r#r#r$r��r�r�c@r>)�NamespaceUriFunctionz^The `namespace-uri` function, which returns the namespace URI of the
    current element.
    cCr�rG)rr1r(r#r#r$r)�r�zNamespaceUriFunction.__call__cCr2)Nznamespace-uri()r#r�r#r#r$r��r*zNamespaceUriFunction.__repr__NrAr#r#r#r$r��r�r�c@r&)
�NotFunctionzUThe `not` function, which returns the negated boolean value of its
    argument.
    r�cCr7r8rPr�r#r#r$r;�r<zNotFunction.__init__cCst|�|||||��Sr8)r$r�r(r#r#r$r)�szNotFunction.__call__cCr2)Nznot(%s)rPr�r#r#r$r��r<zNotFunction.__repr__Nr+r#r#r#r$r��sr�c@s:eZdZdZdgZe�d�jZdd�Z	dd�Z
dd	�Zd
S)�NormalizeSpaceFunctionz�The `normalize-space` function, which removes leading and trailing
    whitespace in the given string, and replaces multiple adjacent whitespace
    characters inside the string with a single space.
    r�z\s{2,}cCr7r8rPr�r#r#r$r;�r<zNormalizeSpaceFunction.__init__cCs&|�|||||�}|�dt|����S)N� )r��
_normalizer"�strip�rrVrWrArSrTr�r#r#r$r)�szNormalizeSpaceFunction.__call__cCsdt|j�S)Nznormalize-space(%s))rcr�r�r#r#r$r��szNormalizeSpaceFunction.__repr__N)r&r'r(r)r,r�r�subr�r;r)r�r#r#r#r$r��sr�c@r&)
�NumberFunctionz=The `number` function that converts its argument to a number.r�cCr7r8rPr�r#r#r$r;�r<zNumberFunction.__init__cCrQr8)r�rrRr#r#r$r)�rSzNumberFunction.__call__cCr2)Nz
number(%r)rPr�r#r#r$r��r<zNumberFunction.__repr__Nr+r#r#r#r$r��sr�c@r&)
�
RoundFunctionz]The `round` function, which returns the nearest integer number for the
    given number.
    r�cCr7r8rVrWr#r#r$r;�r<zRoundFunction.__init__cCrXr8)r��roundrrYr#r#r$r)�rZzRoundFunction.__call__cCr2)Nz	round(%r)rVr�r#r#r$r��r<zRoundFunction.__repr__Nr+r#r#r#r$r��r[r�c@r-)�StartsWithFunctionzbThe `starts-with` function that returns whether one string starts with
    a given substring.
    rfrgcCr.r8rhrir#r#r$r;�r/zStartsWithFunction.__init__cCs6|�|||||�}|�|||||�}t|��t|��Sr8)rfrgr"r�rjr#r#r$r)�szStartsWithFunction.__call__cCr;)Nzstarts-with(%r, %r)rhr�r#r#r$r��r<zStartsWithFunction.__repr__Nr+r#r#r#r$r��rmr�c@r&)
�StringLengthFunctionzRThe `string-length` function that returns the length of the given
    string.
    r�cCr7r8rPr�r#r#r$r;�r<zStringLengthFunction.__init__cCrXr8)r�rGr"r�r#r#r$r)�rZzStringLengthFunction.__call__cCr2)Nzstring-length(%r)rPr�r#r#r$r��r<zStringLengthFunction.__repr__Nr+r#r#r#r$r��r[r�c@s2eZdZdZgd�Zd
dd�Zdd�Zdd	�ZdS)�SubstringFunctionz�The `substring` function that returns the part of a string that starts
    at the given offset, and optionally limited to the given length.
    �r��start�lengthNcCr8r8r�)rr�r�r�r#r#r$r;r9zSubstringFunction.__init__c	Csd|�|||||�}|�|||||�}d}|jdur"|�|||||�}|t|�tt|��t|��SrG)r�r�r�rrGr")	rrVrWrArSrTr�r�r�r#r#r$r)s
 zSubstringFunction.__call__cCs.|jdurd|j|j|jfSd|j|jfS)Nzsubstring(%r, %r, %r)zsubstring(%r, %r))r�r�r�r�r#r#r$r�s


�zSubstringFunction.__repr__r8r+r#r#r#r$r��s
r�c@r-)�SubstringAfterFunctionzrThe `substring-after` function that returns the part of a string that
    is found after the given substring.
    rfrgcCr.r8rhrir#r#r$r;r/zSubstringAfterFunction.__init__c	CsVt|�|||||��}t|�|||||��}|�|�}|dkr)||t|�d�SdS�Nrr�)r"rfrg�findrG�	rrVrWrArSrTrfrg�indexr#r#r$r)s
zSubstringAfterFunction.__call__cCr;�Nzsubstring-after(%r, %r)rhr�r#r#r$r�$r<zSubstringAfterFunction.__repr__Nr+r#r#r#r$r��r�c@r-)�SubstringBeforeFunctionztThe `substring-before` function that returns the part of a string that
    is found before the given substring.
    rfrgcCr.r8rhrir#r#r$r;,r/z SubstringBeforeFunction.__init__c	CsNt|�|||||��}t|�|||||��}|�|�}|dkr%|d|�SdSr�)r"rfrgr�r�r#r#r$r)/s
z SubstringBeforeFunction.__call__cCr;r�rhr�r#r#r$r�6r<z SubstringBeforeFunction.__repr__Nr+r#r#r#r$r�'r�r�c@r6)
�TranslateFunctionznThe `translate` function that translates a set of characters in a
    string to target set of characters.
    �r��	fromchars�tocharscCr8r8r�)rr�r�r�r#r#r$r;>r9zTranslateFunction.__init__c
Csnt|�|||||��}t|�|||||��}t|�|||||��}ttdd�|D�dd�|D���}	|�|	�S)NcSrbr#��ord�r@�cr#r#r$rCFrdz.TranslateFunction.__call__.<locals>.<listcomp>cSrbr#r�r�r#r#r$rCGrd)r"r�r�r��dict�zip�	translate)
rrVrWrArSrTr�r�r��tabler#r#r$r)Bs�
zTranslateFunction.__call__cCsd|j|j|jfS)Nztranslate(%r, %r, %r)r�r�r#r#r$r�Is
�zTranslateFunction.__repr__Nr+r#r#r#r$r�9r=r�c@r>)�TrueFunctionzCThe `true` function, which always returns the boolean `true` value.cCr2r3r#r(r#r#r$r)Pr*zTrueFunction.__call__cCr2)Nztrue()r#r�r#r#r$r�Rr*zTrueFunction.__repr__NrAr#r#r#r$r�MrBr��boolean�ceiling�concat�contains�matches�falserz
local-namer"z
namespace-uriznormalize-space�notr�r�zstarts-withz
string-length�	substring)zsubstring-afterzsubstring-beforer��truec@rK)�Literalz&Abstract base class for literal nodes.NrMr#r#r#r$r�drNr�c@r&)
rzA string literal node.r�cCr7r8�r�)rr�r#r#r$r;jr<zStringLiteral.__init__cCr3r8r�r(r#r#r$r)lr5zStringLiteral.__call__cCr2)Nz"%s"r�r�r#r#r$r�nr<zStringLiteral.__repr__Nr+r#r#r#r$rg�rc@r&)
rzA number literal node.r�cCr7r8rVrWr#r#r$r;tr<zNumberLiteral.__init__cCr3r8rVr(r#r#r$r)vr5zNumberLiteral.__call__cC�
t|j�Sr8)�strr�r�r#r#r$r�xr<zNumberLiteral.__repr__Nr+r#r#r#r$rqr�rc@r&)
rzA variable reference node.r"cCr7r8r4)rr"r#r#r$r;~r<zVariableReference.__init__cCs|�|j�Sr8)r�r"r(r#r#r$r)�r%zVariableReference.__call__cCr�r8)r�r"r�r#r#r$r��r<zVariableReference.__repr__Nr+r#r#r#r$r{r�rc@r-)rzThe boolean operator `and`.�lval�rvalcCr.r8�r�r��rr�r�r#r#r$r;�r/zAndOperator.__init__cCs8t|�|||||��}|sdS|�|||||�}t|�Sr~�r$r�r��rrVrWrArSrTr�r�r#r#r$r)��
zAndOperator.__call__cCr;)Nz	%s and %sr�r�r#r#r$r��r<zAndOperator.__repr__Nr+r#r#r#r$r��rc@r-)�EqualsOperatorzThe equality operator `=`.r�r�cCr.r8r�r�r#r#r$r;�r/zEqualsOperator.__init__cCs4t|�|||||��}t|�|||||��}||kSr8�rr�r�r�r#r#r$r)��zEqualsOperator.__call__cCr;)Nz%s=%sr�r�r#r#r$r��r<zEqualsOperator.__repr__Nr+r#r#r#r$r���r�c@r-)�NotEqualsOperatorzThe equality operator `!=`.r�r�cCr.r8r�r�r#r#r$r;�r/zNotEqualsOperator.__init__cCs4t|�|||||��}t|�|||||��}||kSr8r�r�r#r#r$r)�r�zNotEqualsOperator.__call__cCr;)Nz%s!=%sr�r�r#r#r$r��r<zNotEqualsOperator.__repr__Nr+r#r#r#r$r��r�r�c@r-)rzThe boolean operator `or`.r�r�cCr.r8r�r�r#r#r$r;�r/zOrOperator.__init__cCs8t|�|||||��}|rdS|�|||||�}t|�Sr3r�r�r#r#r$r)�r�zOrOperator.__call__cCr;)Nz%s or %sr�r�r#r#r$r��r<zOrOperator.__repr__Nr+r#r#r#r$r�r�rc@r-)�GreaterThanOperatorz+The relational operator `>` (greater than).r�r�cCr.r8r�r�r#r#r$r;�r/zGreaterThanOperator.__init__cCs4|�|||||�}|�|||||�}t|�t|�kSr8�r�r�rr�r#r#r$r)�rkzGreaterThanOperator.__call__cCr;)Nz%s>%sr�r�r#r#r$r��r<zGreaterThanOperator.__repr__Nr+r#r#r#r$r��r�r�c@r-)�GreaterThanOrEqualOperatorz5The relational operator `>=` (greater than or equal).r�r�cCr.r8r�r�r#r#r$r;�r/z#GreaterThanOrEqualOperator.__init__cCs4|�|||||�}|�|||||�}t|�t|�kSr8r�r�r#r#r$r)�rkz#GreaterThanOrEqualOperator.__call__cCr;)Nz%s>=%sr�r�r#r#r$r��r<z#GreaterThanOrEqualOperator.__repr__Nr+r#r#r#r$r��r�r�c@r-)�LessThanOperatorz(The relational operator `<` (less than).r�r�cCr.r8r�r�r#r#r$r;�r/zLessThanOperator.__init__cCs4|�|||||�}|�|||||�}t|�t|�kSr8r�r�r#r#r$r)�rkzLessThanOperator.__call__cCr;)Nz%s<%sr�r�r#r#r$r��r<zLessThanOperator.__repr__Nr+r#r#r#r$r��r�r�c@r-)�LessThanOrEqualOperatorz2The relational operator `<=` (less than or equal).r�r�cCr.r8r�r�r#r#r$r;�r/z LessThanOrEqualOperator.__init__cCs4|�|||||�}|�|||||�}t|�t|�kSr8r�r�r#r#r$r)�rkz LessThanOrEqualOperator.__call__cCr;)Nz%s<=%sr�r�r#r#r$r��r<z LessThanOrEqualOperator.__repr__Nr+r#r#r#r$r��r�r�)r�r�r�r�r�r�r#)ar)�collectionsr�	functoolsr�mathrrrur��	itertoolsrr �
genshi.compatr�genshi.corerr	r
rrr
rrrrrrr�__all__�
__docformat__�objectrr*r+r,r-r.r1rxr�rr�rr�rrrr"r$r�r�ryr�rzr�rDr{r�rLrOrUr\rernr}rr�r�r�r�r�r�r�r�r�r�r�r�r�r�rr�rrrrr�r�rr�r�r�r�rrqrrr#r#r#r$�<module>s�
,PF		

�



���������������	�







�

https://t.me/RX1948 - 2025