
    w:i4                     >   d Z ddlmZ ddlmZ ddlmZmZ ddlZddl	Z	ddl
mZ ddlmZmZ ddlmZmZmZmZ dd	lmZmZmZmZmZmZmZmZmZ d
dgZdZ G d de          Z e j!        Z!e j"        Z"e j#        Z#e j$        Z$e j%        Z% G d de          Z& G d de          Z' G d de          Z( G d d
e          Z) G d de*          Z+ G d de          Z,d Z-d Z.d Z/d Z0d Z1 G d de          Z2 G d  d!e          Z3 G d" d#e          Z4 G d$ d%e          Z5 G d& d'e          Z6 G d( d)e          Z7 G d* d+e          Z8 G d, d-e          Z9e6e7e8e9d.Z: G d/ d0e          Z; G d1 d2e;          Z< G d3 d4e;          Z= G d5 d6e;          Z> G d7 d8e;          Z? G d9 d:e;          Z@ G d; d<e;          ZA G d= d>e;          ZB G d? d@e;          ZC G dA dBe;          ZD G dC dDe;          ZE G dE dFe;          ZF G dG dHe;          ZG G dI dJe;          ZH G dK dLe;          ZI G dM dNe;          ZJ G dO dPe;          ZK G dQ dRe;          ZL G dS dTe;          ZM G dU dVe;          ZN G dW dXe;          ZO G dY dZe;          ZPi d[e<d\e=d]e>d^e?d_e@d`eAdaeBdbeCdceDddeEdeeGdfeFdgeHdheIdieJdjeKdkeLeMeNeOePdlZQ G dm dne          ZR G do dpeR          ZS G dq dreR          ZT G ds dteR          ZU G du dve          ZV G dw dxe          ZW G dy dze          ZX G d{ d|e          ZY G d} d~e          ZZ G d de          Z[ G d de          Z\ G d de          Z]eWeXeZe[e\e]dZ^e$ e2d          dfZ_e% e2d          dfZ`dS )aD  Basic 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)	text_type
IS_PYTHON2)StreamAttrs	NamespaceQName)	STARTENDTEXTSTART_NSEND_NSCOMMENTPISTART_CDATA	END_CDATAPathPathSyntaxErrorzrestructuredtext enc                   <    e Zd ZdZdZdZdZdZdZe	d             Z
dS )	Axisz7Defines constants for the various supported XPath axes.	attributechild
descendantzdescendant-or-selfselfc                 p    t          | |                                                    dd          d          S )zdReturn the axis constant for the given name, or `None` if no such
        axis was defined.
        -_N)getattrupperreplace)clsnames     C/var/www/html/trac/venv/lib/python3.11/site-packages/genshi/path.pyfornamezAxis.fornameB   s.    
 sDJJLL00c::DAAA    N)__name__
__module____qualname____doc__	ATTRIBUTECHILD
DESCENDANTDESCENDANT_OR_SELFSELFclassmethodr(    r)   r'   r   r   9   sR        AAIEJ-DB B [B B Br)   r   c                   0    e Zd Zed             Zd Zd ZdS )GenericStrategyc                     dS NTr4   r%   paths     r'   supportszGenericStrategy.supportsS   s    tr)   c                     || _         d S Nr:   r   r:   s     r'   __init__zGenericStrategy.__init__W       			r)   c                 r   | j         }|rP|d         d         t          u rt          g|z   n|t          |d         d         |d         d         fg|dd          z   nM|d         d         t          u s*|d         d         t          u s|d         d         t
          u rt          g|z   n|dg gfggdfd	}|S )Nr         Fc                    | d d         \  }}}d }|t           u rr                                 d S |t          u s|t          u s|t          u s	|t
          u rd S t          d d         D                       }g }	t                    d         d         t          k    pdz
  }
d}|r||	                                \  }}}|         \  }}}|t          u s	|t          u rO|rM|	r4|	d         d         |k    r"|	d         d                             |           n|	                    ||f            ||||||          st                      }t          |          t          |          z   }d}d}|r|D ]} ||||||          }t          |          t           u rt#          t%          ||                    D ]s\  }}||v r
t          |          |dz   k     r|                    d           ||xx         dz  cc<   ||         t'          |          k    r|                    |           tt          |          |k    rd}|dz  }|sd} n|sg }|dz   |
k    r+d}d         \  }}}|t          u r ||||||          }|r|}n|dz            d         }|t          u s	|t*          u rU|r|d         d         |dz   k    r|                    |dz   g |gf           n!|d         d                             |           |t*          ur|	                    |dz   |gf           |||t.          u r                    |	           |S )	N   c                     g | ]
\  }}||g fS r4   r4   ).0poscous      r'   
<listcomp>z7GenericStrategy.test.<locals>._test.<locals>.<listcomp>   s"    HHH(#sS"~HHHr)   r   rC   TFrD   )r   popr   r   r   r   r   lenr.   popleftr0   r1   extendappendsettypefloat	enumerater   intaddr2   
appendleftr   )event
namespaces	variables
updateonlykinddatarI   retval	pos_queuenext_posreal_lenlast_checkedxpcoumcouaxisnodetest
predicatesmissedcounters_lencnummatched	predicatepretvalirJ   child_counter	next_axisstackstepss                               r'   _testz#GenericStrategy.test.<locals>._testq   s   #BQBiOD$F s{{  IIKKKtx46>>{**di.?.?tHHeBiHHHIIIH 5zzeBili&?%K!LHL  XB ) 1 1 3 34-21X*h
 J&&$2D*D*D$*D 3HRLOq$8$8 Q..t4444 D	222  xdCYGG  "4yy3t994   #%/ # #	"+)D$,6,5#7 #7  ==E11
 +4E$4E4E*F*F 2 23#$;;$,#&s88dQh#6#6$'JJqMMM #D			Q			 $'t9G#<#<$*JJqMMM  #6{{l::*/ AID& #',W"U#   !#q5H$$ #G16r.D(Jy(("*(4sJ+4#6 #6 )!( %a!eQI !$666)t:K:K( BIaLOa!e,C,C%00!a%m_1MNNNN%aLO22=AAA !,, Q(@AAAq  XBt u}}X&&&Mr)   F)r:   r.   _DOTSLASHSLASHr1   r/   r0   	_DOTSLASH)r   ignore_contextpru   rs   rt   s       @@r'   testzGenericStrategy.testZ   s    I 		tAw)##'(1,,ad1gqtAw?@1QRR5HqT!W1aI!5!5Q47j((K!OEEE rd)t	 t	 t	 t	 t	 t	 t	l r)   Nr*   r+   r,   r3   r;   r@   r{   r4   r)   r'   r6   r6   Q   sP          [  M M M M Mr)   r6   c                   4    e Zd ZdZed             Zd Zd ZdS )SimplePathStrategyzCStrategy for path with only local names, attributes and text nodes.c                     |d         d         t           u rdS t          t          t          f}|D ]\  }}}|r dS t	          ||          s dS dS )Nr   FT)r.   LocalNameTestCommentNodeTestTextNodeTest
isinstance)r%   r:   allowed_testsr!   rh   ri   s         r'   r;   zSimplePathStrategy.supports   sn    71:""5&F'+ 	 	#Ax uuh66 uutr)   c                    g | _         d}g }d fd}|D ]}|d         t          u rTt          |          dk    r#|d         |d         d         k    r
d | _          d S Hd}|                    |d                    f|d         t          u r|                    |d                    |d         t
          u r2 ||          }| j                             |||d         |f            d S  ||          }| j                             ||d |f           |d         g}|d         t          u rd}d} ||          }| j                             ||d |f           d S )NFc                     t          |           t          |          urdS t          |           t          k    r| j        |j        k    S dS )z!Tests if two node tests are equalFT)rS   r   r&   )node1node2s     r'   nodes_equalz0SimplePathStrategy.__init__.<locals>.nodes_equal  sC    E{{$u++--uE{{m++zUZ//4r)   c                 n   t          |           dk    rg S dg}d}t          dt          |                     D ]{}|dk    rA | |         | |                   s)||dz
           }|dk    r | |         | |                   ) | |         | |                   r|dz  }|                    |           ||S )z KMP prefix calculation for tabler   rC   )rN   rangerQ   )fpisrp   r   s       r'   calculate_piz1SimplePathStrategy.__init__.<locals>.calculate_pi  s    
 1vv{{	BA1c!ff%%  !eeKK!ad$;$;e1Q3A !eeKK!ad$;$;e;qtQqT** FA		!Ir)   r   rC   rL   T)	fragmentsr2   rN   rQ   r/   r.   r0   )r   r:   self_beginningfragmentr   rg   r   r   s          @r'   r@   zSimplePathStrategy.__init__   s    	 	 		 	 	 	 	"  	* 	*DAw$x==A%% Aw(2,q/11)- 2 &*NOODG,,,,aE!!Q((((aI%%!\(++%%xT!Wn&MNNN!\(++%%xT>&JKKK G97j((%*NN%)NN\(##xT>BCCCCCr)   c                 t    g j         j        | j        t                    dfd	}|S )NFc                 r   d S | d d         \  }}}|t           u rr
              d S |t          u s|t          u s|t          u s	|t          u rd S sTd}|         d         s|dz  }|         d         d}p|dk    }	|         d         sr|dk    r |||	f           d S nd         \  }}}	|]|	s[|         \  }
}}}t          |
          }||k    rn  |
|         |||||          r|dz  }nd\  }}||k    r|dz   k    r	|dz  }d}d}	||t          u r |||	f           d S |	r	 |         \  }
}}}t          |
          }|dk    rG||k    s |
|         |||||          s,||dz
           }|dk    r||k     |
|         |||||          , |
|         |||||          r|dz  }||k    r#|dz   k    rn|dz  }d}d}	|         d         snnn|t          u r.|	s|dz   k    r||k    r d d |	f           n |||	f           |dz   k    r||k    r|r ||||||          S dS d S )NrF   r   rC   rL   NNT)r   r   r   r   r   rN   r   )rY   rZ   r[   r\   r]   r^   rI   fidrz   icfragr   attribr!   frag_lenfrags	frags_lenry   rs   	stack_pop
stack_pushs                  r'   ru   z&SimplePathStrategy.test.<locals>._testH  su   }t#BQBiOD$ s{{  IKKKtx46>>{**di.?.?t '*Q- 1HC  *Q- #0a
 Sz!}  n  aJQ|,,,4 #2Y
Qr&+Cj#b&!t99==T!WT4j)DD (FAA (FC==S1W	%9%91HCAB{5==JQ|,,,t */*'D"fa"4yyH a%%Q(]]#DGD$ZKK &3qsG a%%Q(]]#DGD$ZKK &3 tAwtT3
IFF QH}}7i//!1HC !A!%B#(:a= & %& 14 u}}  -cAg22qH}} JdB/0000JQ|,,, Qw)##X J!6$c:yIIIt4r)   rv   )rQ   rM   r   rN   )r   ry   ru   r   r   rs   r   r   s    ` @@@@@r'   r{   zSimplePathStrategy.test=  sy    
 \
I	JJ	l	 l	 l	 l	 l	 l	 l	 l	 l	 l	 l	\ r)   N)r*   r+   r,   r-   r3   r;   r@   r{   r4   r)   r'   r~   r~      s]        MM	 	 [	BD BD BDHy y y y yr)   r~   c                   0    e Zd Zed             Zd Zd ZdS )SingleStepStrategyc                 (    t          |          dk    S NrC   )rN   r9   s     r'   r;   zSingleStepStrategy.supports  s    4yyA~r)   c                     || _         d S r=   r>   r?   s     r'   r@   zSingleStepStrategy.__init__  rA   r)   c                     | j         d         d         t          u rt          gz   d         d         t          u rd         d         pd g dgdfd	}|S )Nr   rL   rC   Fc                 &   | d d         \  }}}|t           u rsdxx         dz  cc<   d S |t          u s|t          u s|t          u s	|t          u rd S sd         d         t
          u rd         dk    pAd         d         t          u od         dk    p d         d         t          u od         dk     }|t          u rdxx         dz  cc<   |rd S d         \  }}	}
 |	|||||          sd S |
rd}|
D ]} ||||||          }t          |          t          u r[t                    |dz   k     r                    d           |xx         dz  cc<   |         t          |          k    rd}|dz  }|s d S r |||||          S dS )NrF   r   rC   FT)r   r   r   r   r   r2   r/   r0   r   rS   rT   rN   rQ   rV   )rY   rZ   r[   r\   r]   r^   rI   outsiderg   rh   ri   rl   rn   ro   countersdepthry   select_attrrt   s                 r'   ru   z&SingleStepStrategy.test.<locals>._test  s   #BQBiOD$ s{{% "!HHHMHHHt!!TV^^{**di.?.?t!   8A;$.@58q= G 8A;%/AE!HMG 8A;*4EqA  5==!HHHMHHH  4).q&D(J8D$ZCC t %!+ % %I'idCYOOGG}}-- x==4!833$OOA... !+#D>S\\99&+G	" % $%  K"{4sJ	JJJ4r)   rv   )r:   r.   rx   )r   ry   ru   r   r   r   rt   s    ` @@@@r'   r{   zSingleStepStrategy.test  s    	8A;)##K%'EBili/@E"IaLHD -	 -	 -	 -	 -	 -	 -	 -	 -	 -	^ r)   Nr|   r4   r)   r'   r   r     sK          [  : : : : :r)   r   c                   :    e Zd ZdZeeefZd	dZd Z	d
dZ
ddZdS )r   zImplements 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.
    NrL   c                 ,   || _         t          |||                                          | _        g | _        | j        D ]U}| j        D ]<}|                    |          r%| j                             ||                      n=t          d          VdS )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
        zNo strategy found for pathN)	source
PathParserparsepaths
strategies
STRATEGIESr;   rQ   NotImplementedError)r   textfilenamelinenor:   strategy_classs         r'   r@   zPath.__init__	  s     h77==??
J 	H 	HD"&/ H H!**400 O**>>$+?+?@@@E **FGGG 		H 	Hr)   c                 @   g }| j         D ]g}g }|D ]8\  }}}|                    |d|           |D ]}|dxx         d|z  z  cc<   9|                    d                    |                     hdt          |           j        dd                    |          dS )	N::rL   z[%s]/<z "|z">)r   rQ   joinrS   r*   )r   r   r:   rt   rg   rh   ri   rn   s           r'   __repr__zPath.__repr__  s    J 	* 	*DE.2 4 4*h
xx8999!+ 4 4I"III)!33IIII4LL%))))	* #4jj111388E????CCr)   c                      |i }|i }t          |          }|||f fd	}t           |            t          |d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              3   H   K    fd}	                                 } D ]} ||||          }|du rh|V  |d         t          u rTd}|dk    rL |            }|d         t          u r|dz  }n|d         t          u r|dz  }|V   ||||d           |dk    L{|r|V  d S )Nc                  "    t                     S r=   )next)streams   r'   <lambda>z0Path.select.<locals>._generate.<locals>.<lambda>A  s    DLL r)   Tr   rC   r\   )r{   r   r   )
r   nsvs_nextr{   rY   resultr   subeventr   s
   `        r'   	_generatezPath.select.<locals>._generate@  s      ((((E99;;D ! !eR,,T>>KKKQx5(( !#aii',uwwH'{e33 %
!)!!3!3 %
"*NNN D2rdCCCC $aii  ! LLL! !r)   
serializer)r   )iterr
   r"   )r   r   rZ   r[   r   s   `    r'   selectzPath.select'  s    ( JIf#
y 	! 	! 	! 	! 	! 	!& iikk!(t!D!DF F F 	Fr)   Fc                 r    fd| j         D             t                    dk    rd         S dfd	}|S )a1  Returns 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``
        c                 :    g | ]}|                               S r4   )r{   )rH   r   ry   s     r'   rK   zPath.test.<locals>.<listcomp>u  s%    AAAA''AAAr)   rC   r   Fc                 <    d }D ]} || |||          }||}|S )Nr   r4   )rY   rZ   r[   r\   r_   r{   valtestss          r'   _multizPath.test.<locals>._multiy  s?    F ! !d5*iJOOO> FMr)   rv   )r   rN   )r   ry   r   r   s    ` @r'   r{   z	Path.testV  s_    > BAAAAAAu::??8O	 	 	 	 	 	 r)   NrL   r   rv   )r*   r+   r,   r-   r   r~   r6   r   r@   r   r   r{   r4   r)   r'   r   r     s          %&8/JJH H H H&	D 	D 	D-F -F -F -F^* * * * * *r)   c                       e Zd ZdZddZdS )r   zEException raised when an XPath expression is syntactically incorrect.NrL   c                 z    |rd|||fz  }t                               | |           || _        || _        || _        d S )Nz%s (%s, line %d))	Exceptionr@   r   r   offset)r   messager   r   r   s        r'   r@   zPathSyntaxError.__init__  sK     	G(GXv+FFG4))) r)   )NrL   rL   )r*   r+   r,   r-   r@   r4   r)   r'   r   r     s.        OO     r)   c            	       V   e Zd ZdZdZdZ ej        dd                    d eD                       dd                    d	 eD                       d
          j	        Z
ddZed             Zed             Zd Zd Zd Zd Zd Zd dZd Zd Zd Zd Zd Zd Zd Zd Zd ZdS )!r   z)Tokenizes and parses an XPath expression.))'r   )"r   )r   :...//r   []()()@=!=!r   ,>=><=r   $z(("[^"]*")|(\'[^\']*\')|((?:\d+)?\.\d+)|(r   c                 6    g | ]}t          j        |          S r4   reescaperH   ts     r'   rK   zPathParser.<listcomp>  s     $C$C$CaRYq\\$C$C$Cr)   z)|([^ c                 B    g | ]}t          j        |d                    S )r   r   r   s     r'   rK   zPathParser.<listcomp>  s$    #E#E#EBIadOO#E#E#Er)   z	\s]+)|\s+NrL   c                     || _         || _        d d |                     |          D             D             | _        d| _        d S )Nc                     g | ]}||S r4   r4   r   s     r'   rK   z'PathParser.__init__.<locals>.<listcomp>  s,     ? ? ?Q<=?q ? ? ?r)   c                 .    g | ]\  }}}}}|p|p|p|p|S r4   r4   )rH   dqstrsqstrnumbertokenr&   s         r'   rK   z'PathParser.__init__.<locals>.<listcomp>  sF     #9 #9 #9'HueVUD $)#LE#LV#Lu#L #9 #9 #9r)   r   )r   r   	_tokenizetokensrI   )r   r   r   r   s       r'   r@   zPathParser.__init__  sb     ? ? #9 #9#'>>$#7#7#9 #9 #9 ? ? ? r)   c                 B    | j         t          | j                  dz
  k    S r   )rI   rN   r   r   s    r'   at_endzPathParser.at_end  s    x3t{++a///r)   c                 &    | j         | j                 S r=   )r   rI   r  s    r'   	cur_tokenzPathParser.cur_token  s    {48$$r)   c                 F    | xj         dz  c_         | j        | j                  S r   )rI   r   r  s    r'   
next_tokenzPathParser.next_token  s     A{48$$r)   c                 >    | j         s| j        | j        dz            S d S r   )r  r   rI   r  s    r'   
peek_tokenzPathParser.peek_token  s$    { 	-;tx!|,,tr)   c                 &   |                                  g}| j        dk    rF|                                  |                    |                                             | j        dk    F| j        s#t          d| j        z  | 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  rQ   r  r   r   r   )r   r   s     r'   r   zPathParser.parse  s     $$&&'n##OOLL,,../// n## { 	P!"O$(N#348M4;P P Pr)   c                    g }	 | j                             d          r|s| j         dk    rl|                                  |                                 \  }}}|                    t
          ||f           | j        s| j                             d          snt          d| j        | j	                  | j         dk    r)|                    t
          t                      g f           |                                  |                                 \  }}}|st          }|                    |||f           | j        s| j                             d          snS|S )NTr   r   z%Absolute location paths not supported)r  
startswithr  _location_steprQ   r1   r  r   r   r   NodeTestr/   )r   rt   rg   rh   ri   s        r'   r
  zPathParser._location_path  sx   	~((-- " G~--)))595H5H5J5J2h
&8(&0&2 3 3 3; "dn.G.G.L.L "! - /:;?=.2k; ; ; ^t++LL"4hjj"!EFFF!!!)-)<)<)>)>&D(J LL$*5666{ $.";";C"@"@ 3	6 r)   c                    | j         dk    rt          }|                                  n| j         dk    rt          }n| j         dk    rt	          d| j        | j                  |                                 dk    rht          	                    | j                   }|t	          d|z  | j        | j                  |                                  |                                  nd }| 
                    |pt                    }g }| j         dk    r2|                    |                                            | j         dk    2|||fS )Nr   r   r   zUnsupported axis "parent"r   zUnsupport axis "%s"r   )r  r.   r  r2   r   r   r   r  r   r(   
_node_testr/   rQ   
_predicate)r   rg   rh   ri   s       r'   r  zPathParser._location_step  sB   >S  DOO^s""DD^t##!"=t}"&+/ / /__$&&<<//D|%&;d&B&*mT[B B BOOOOD??4=511
n##doo//000 n##Xz))r)   c                    d x}}|                                  }|dv r|                                 }n|dk    rX| j        }|                                  |                                 }|dk    rt	          ||          }n\t          |||          }nJ| j        dk    rt          |          }n/| j        dk    rt                      }nt          || j                  }| j	        s|                                  |S )N)r   r   r   *r   )
r  
_node_typer  r  QualifiedPrincipalTypeTestQualifiedNameTestPrincipalTypeTestr  r   r  )r   rg   r{   prefixr  	localnames         r'   r  zPathParser._node_test  s    v__&&
$$??$$DD3^FOO))IC1$??(vyAA ~$$(..3&&zz$T4>::{ 	OOr)   c                    | j         }|                                  g }| j         dk    r\|                                  | j         dk    r=| j         }|d         |d         f| j        v r
|dd         }|                    |           t                              |          }|st          d|z  | j        | j                   || S )Nr   r   r   rL   rC   z%s() not allowed here)	r  r  _QUOTESrQ   _nodetest_mapgetr   r   r   )r   r&   argsstringr%   s        r'   r  zPathParser._node_type  s    ~>T!! OO~$$1Ivbz*dl::#AbD\FF###%% 	/!"9D"@$-"&+/ / /sDzr)   c                    | j         dk    sJ |                                  |                                 }| j         dk    r#t          d| j         z  | j        | j                  | j        s|                                  |S )Nr   r   z/Expected "]" to close predicate, but found "%s")r  r  _or_exprr   r   r   r  r   exprs     r'   r  zPathParser._predicate1  s    ~$$$$}}>S  ! #359^#D"&-> > > { 	OOr)   c                     |                                  }| j        dk    rA|                                  t          ||                                            }| j        dk    A|S )Nor)	_and_exprr  r  
OrOperatorr"  s     r'   r!  zPathParser._or_expr=  s]    ~~n$$OOdDNN$4$455D n$$ r)   c                     |                                  }| j        dk    rA|                                  t          ||                                            }| j        dk    A|S )Nand)_equality_exprr  r  AndOperatorr"  s     r'   r&  zPathParser._and_exprD  sa    ""$$n%%OOtT%8%8%:%:;;D n%% r)   c                     |                                  }| j        dv rMt          | j                 }|                                   |||                                            }| j        dv M|S )N)r   r   )_relational_exprr  _operator_mapr  r   r#  ops      r'   r*  zPathParser._equality_exprK  so    $$&&n++t~.BOO2dD113344D n++ r)   c                     |                                  }| j        dv rMt          | j                 }|                                   |||                                            }| j        dv M|S )N)r   r   r   r   )	_sub_exprr  r.  r  r/  s      r'   r-  zPathParser._relational_exprS  sm    ~~n 666t~.BOO2dDNN,,--D n 666 r)   c                    | j         }|dk    r|                                 S |                                  |                                 }| j         dk    r#t	          d| j         z  | j        | j                  |                                  |S )Nr   r   z4Expected ")" to close sub-expression, but found "%s")r  _primary_exprr  r!  r   r   r   )r   r   r#  s      r'   r2  zPathParser._sub_expr[  s    C<<%%'''}}>S  ! #359^#D"&-> > > 	r)   c                    | j         }t          |          dk    rB|d         |d         f| j        v r+|                                  t	          |dd                   S |d                                         s|d         dk    r0|                                  t          t          |                    S |dk    r7|                                 }|                                  t          |          S | j	        s;| 
                                                    d          r|                                 S d }|dk    rt          }|                                  |                     |          S )NrC   r   rL   r   r   r   r   )r  rN   r  r  StringLiteralisdigitNumberLiteralas_floatVariableReferencer  r  r  _function_callr.   r  )r   r   rg   s      r'   r4  zPathParser._primary_exprh  sE   u::>>uQxr3t|CCOO qt---1X 	)58s??OO %111c\\OO%%EOO$U+++ 	)!2!2!=!=c!B!B 	)&&(((D|| !!!??4(((r)   c                 V   | j         }|                                 dk    rg }n| j         dk    sJ |                                  |                                 g}| j         dk    rF|                                  |                    |                                            | j         dk    F| j         dk    s#t	          d| j         z  | j        | j                  |                                  t                              |          }|st	          d|z  | j        | j                   || S )Nr   r   r   r   z<Expected ")" to close function argument list, but found "%s"zUnsupported function "%s")	r  r  r!  rQ   r   r   r   _function_mapr  )r   r&   r  r%   s       r'   r;  zPathParser._function_call}  s7   ~??$$DD>S((((OOMMOO$D.C''!!!DMMOO,,, .C'' >S((% '=?C~'N&*mT[B B B 	%% 	>!"="D"&-> > >sDzr)   r   r=   )r*   r+   r,   r-   r  _TOKENSr   compiler   findallr   r@   propertyr  r  r  r  r   r
  r  r  r  r  r!  r&  r*  r-  r2  r4  r;  r4   r)   r'   r   r     s       33&GDG

88$C$C7$C$C$CDDDD77#E#EW#E#E#EFFFFH I IIP     0 0 X0 % % X%% % %    (  >* * *0   6  *
 
 
          ) ) )*    r)   r   c                 v    t          | t                    r#t          |           dk    sJ | d         d         S | S )zConvert value to a scalar. If a single element Attrs() object is passed
    the value of the single attribute will be returned.rC   r   )r   r   rN   values    r'   	as_scalarrE    s<     % 5zzQQx{r)   c                 :    t          t          |                     S r=   )rT   rE  rC  s    r'   r9  r9    s     5!!"""r)   c                 \    t           rt          nt          } |t          |                     S r=   )r	   longrV   rE  )rD  long_clss     r'   as_longrJ    s(    !*ttsH8Ie$$%%%r)   c                 J    t          |           } | du rdS t          |           S )NFr   )rE  r   rC  s    r'   	as_stringrL    s+    eE~~rUr)   c                 :    t          t          |                     S r=   )boolrE  rC  s    r'   as_boolrO    s    	%  !!!r)   c                   *    e Zd ZdZdgZd Zd Zd ZdS )r  z?Node test that matches any event with the given principal type.principal_typec                     || _         d S r=   )rQ  )r   rQ  s     r'   r@   zPrincipalTypeTest.__init__  s    ,r)   c                 L    |t           u r| j        t          u r
|d         pd S dS d S )NrC   T)r   rQ  r.   r   r]   r^   rI   rZ   r[   s         r'   __call__zPrincipalTypeTest.__call__  s3    5=="i//Aw$&t	 =r)   c                     dS )Nr  r4   r  s    r'   r   zPrincipalTypeTest.__repr__  s    sr)   Nr*   r+   r,   r-   	__slots__r@   rU  r   r4   r)   r'   r  r    sO        II!"I- - -      r)   r  c                   ,    e Zd ZdZddgZd Zd Zd ZdS )r  z[Node test that matches any event with the given principal type in a
    specific namespace.rQ  r  c                 "    || _         || _        d S r=   )rQ  r  )r   rQ  r  s      r'   r@   z#QualifiedPrincipalTypeTest.__init__  s    ,r)   c                     t          |                    | j                            |t          u rC| j        t
          u r+|d         r#t          fd|d         D                       pd S |d         v S d S )NrC   c                 &    g | ]\  }}|v 	||fS r4   r4   )rH   r&   rD  	namespaces      r'   rK   z7QualifiedPrincipalTypeTest.__call__.<locals>.<listcomp>  s5     4 4 4e!%!2!2  $Um!2!2!2r)   r   )r   r  r  r   rQ  r.   r   )r   r]   r^   rI   rZ   r[   r]  s         @r'   rU  z#QualifiedPrincipalTypeTest.__call__  s    jnnT[99::	5=="i//DG/ 4 4 4 4tAw 4 4 4 5 5 =8<= Aw)++ =r)   c                     d| j         z  S )Nz%s:*)r  r  s    r'   r   z#QualifiedPrincipalTypeTest.__repr__  s    ##r)   NrW  r4   r)   r'   r  r    sU         !8,I  , , ,$ $ $ $ $r)   r  c                   ,    e Zd ZdZddgZd Zd Zd ZdS )r   zWNode test that matches any event with the given principal type and
    local name.
    rQ  r&   c                 "    || _         || _        d S r=   )rQ  r&   )r   rQ  r&   s      r'   r@   zLocalNameTest.__init__  s    ,			r)   c                     |t           u rh| j        t          u rD| j        |d         v r5t	          | j        |d                             | j                  fg          S |d         j        | j        k    S d S )NrC   r   )r   rQ  r.   r&   r   r  r  rT  s         r'   rU  zLocalNameTest.__call__  sn    5=="i//DIa4H4Hty$q'++di*@*@ABCCCAw(DI55	 =r)   c                     | j         S r=   r&   r  s    r'   r   zLocalNameTest.__repr__  
    yr)   NrW  r4   r)   r'   r   r     sW          "6*I  6 6 6    r)   r   c                   ,    e Zd ZdZg dZd Zd Zd ZdS )r  z[Node test that matches any event with the given principal type and
    qualified name.
    rQ  r  r&   c                 0    || _         || _        || _        d S r=   rf  )r   rQ  r  r&   s       r'   r@   zQualifiedNameTest.__init__  s    ,			r)   c                    t          |                    | j                  d| j                  }|t          u rO| j        t          u r5||d         v r+t          ||d                             |          fg          S |d         |k    S d S )N}rC   r   )r   r  r  r&   r   rQ  r.   r   )r   r]   r^   rI   rZ   r[   qnames          r'   rU  zQualifiedNameTest.__call__  s    !<!<!<!<diiHII5=="i//ET!W4D4Dud1gkk%&8&89:;;;Aw%''	 =r)   c                 $    | j         d| j        S )Nr   )r  r&   r  s    r'   r   zQualifiedNameTest.__repr__  s    +++tyy11r)   NrW  r4   r)   r'   r  r    sX          544I  ( ( (2 2 2 2 2r)   r  c                   "    e Zd ZdZg Zd Zd ZdS )r   z*Node test that matches any comment events.c                     |t           u S r=   )r   rT  s         r'   rU  zCommentNodeTest.__call__  s    wr)   c                     dS )Nz	comment()r4   r  s    r'   r   zCommentNodeTest.__repr__  s    {r)   Nr*   r+   r,   r-   rX  rU  r   r4   r)   r'   r   r     s=        44I      r)   r   c                   "    e Zd ZdZg Zd Zd ZdS )r  z Node test that matches any node.c                 "    |t           u rdS |||fS r8   r   rT  s         r'   rU  zNodeTest.__call__  s    5==4T3r)   c                     dS )Nznode()r4   r  s    r'   r   zNodeTest.__repr__      xr)   Nro  r4   r)   r'   r  r     s=        **I      r)   r  c                   ,    e Zd ZdZdgZddZd Zd ZdS )ProcessingInstructionNodeTestz8Node test that matches any processing instruction event.targetNc                     || _         d S r=   rw  )r   rw  s     r'   r@   z&ProcessingInstructionNodeTest.__init__      r)   c                 F    |t           u o| j         p|d         | j        k    S Nr   )r   rw  rT  s         r'   rU  z&ProcessingInstructionNodeTest.__call__  s%    rzI4;H$q'T[2HIr)   c                 8    d}| j         rd| j         z   dz   }d|z  S )Nr   r   zprocessing-instruction(%s)ry  )r   args     r'   r   z&ProcessingInstructionNodeTest.__repr__  s-    ; 	*#c)C+c11r)   r=   rW  r4   r)   r'   rv  rv  
  sV        BB
I   J J J2 2 2 2 2r)   rv  c                   "    e Zd ZdZg Zd Zd ZdS )r   z&Node test that matches any text event.c                     |t           u S r=   )r   rT  s         r'   rU  zTextNodeTest.__call__  s    t|r)   c                     dS )Nztext()r4   r  s    r'   r   zTextNodeTest.__repr__  rt  r)   Nro  r4   r)   r'   r   r     s=        00I      r)   r   )commentnodezprocessing-instructionr   c                       e Zd ZdZdS )Functionz3Base class for function nodes in XPath expressions.Nr*   r+   r,   r-   r4   r)   r'   r  r  %  s        ====r)   r  c                   .    e Zd ZdZdgZeZd Zd Zd Z	dS )BooleanFunctionzPThe `boolean` function, which converts its argument to a boolean
    value.
    r#  c                     || _         d S r=   r#  r"  s     r'   r@   zBooleanFunction.__init__.  rA   r)   c                 R    |                      |||||          }t          |          S r=   )r#  rO  r   r]   r^   rI   rZ   r[   r   s          r'   rU  zBooleanFunction.__call__0  s'    iidCY??s||r)   c                     d| j         z  S )Nzboolean(%r)r  r  s    r'   r   zBooleanFunction.__repr__3  s    ty((r)   N)
r*   r+   r,   r-   rX  rN  _return_typer@   rU  r   r4   r)   r'   r  r  (  sY          IL    ) ) ) ) )r)   r  c                   *    e Zd ZdZdgZd Zd Zd ZdS )CeilingFunctionzeThe `ceiling` function, which returns the nearest lower integer number
    for the given number.
    r   c                     || _         d S r=   r   r   r   s     r'   r@   zCeilingFunction.__init__;  rz  r)   c                 l    |                      |||||          }t          t          |                    S r=   )r   r   r9  r   r]   r^   rI   rZ   r[   r   s          r'   rU  zCeilingFunction.__call__=  s1    T4j)DDHV$$%%%r)   c                     d| j         z  S )Nzceiling(%r)r  r  s    r'   r   zCeilingFunction.__repr__@  s    t{**r)   NrW  r4   r)   r'   r  r  6  sT          
I  & & &+ + + + +r)   r  c                   *    e Zd ZdZdgZd Zd Zd ZdS )ConcatFunctionzoThe `concat` function, which concatenates (joins) the variable number of
    strings it gets as arguments.
    exprsc                     || _         d S r=   )r  )r   r  s     r'   r@   zConcatFunction.__init__H  s    


r)   c                     g }fd| j         D             D ]$}|                    t          |                     %d                    |          S )Nc           	      .    g | ]} |          S r4   r4   )rH   r#  r^   r]   rZ   rI   r[   s     r'   rK   z+ConcatFunction.__call__.<locals>.<listcomp>L  s;     - - - T$c:yAA - - -r)   r   )r  rQ   rL  r   )r   r]   r^   rI   rZ   r[   stringsitems    `````  r'   rU  zConcatFunction.__call__J  s    - - - - - - - -!%- - - 	, 	,DNN9T??++++wwwr)   c                 P    dd                     d | j        D                       z  S )Nz
concat(%s), c                 ,    g | ]}t          |          S r4   )repr)rH   r#  s     r'   rK   z+ConcatFunction.__repr__.<locals>.<listcomp>Q  s    (K(K(Kd(K(K(Kr)   )r   r  r  s    r'   r   zConcatFunction.__repr__P  s*    dii(K(K
(K(K(KLLLLr)   NrW  r4   r)   r'   r  r  C  sY          	I       M M M M Mr)   r  c                   ,    e Zd ZdZddgZd Zd Zd ZdS )ContainsFunctionz\The `contains` function, which returns whether a string contains a given
    substring.
    string1string2c                 "    || _         || _        d S r=   r  r  r   r  r  s      r'   r@   zContainsFunction.__init__X      r)   c                     |                      |||||          }|                     |||||          }t          |          t          |          v S r=   )r  r  rL  r   r]   r^   rI   rZ   r[   r  r  s           r'   rU  zContainsFunction.__call__[  sO    ,,tT3
IFF,,tT3
IFF!!Yw%7%777r)   c                 (    d| j         d| j        dS Nz	contains(r  r   r  r  s    r'   r   zContainsFunction.__repr___       %)\\\4<<<@@r)   NrW  r4   r)   r'   r  r  S  s\          I&I  8 8 8A A A A Ar)   r  c                   j    e Zd ZdZddgZej        ej        ej        ej	        dZ
ddZd Zd Zd	 Zd
S )MatchesFunctionz]The `matches` function, which returns whether a string matches a regular
    expression.
    r  r  )r   mrp   rd   r   c                 V    || _         || _        |                     |          | _        d S r=   )r  r  
_map_flagsflags)r   r  r  r  s       r'   r@   zMatchesFunction.__init__i  s'    __U++


r)   c           	          t          |                     |||||                    }t          |                     |||||                    }t          j        ||| j                  S r=   )rL  r  r  r   searchr  r  s           r'   rU  zMatchesFunction.__call__m  sZ    DLLtS*iPPQQDLLtS*iPPQQy'4:666r)   c                 f     t          t          j         fd|D             t          j                  S )Nc                 *    g | ]}j         |         S r4   )flag_map)rH   flagr   s     r'   rK   z.MatchesFunction._map_flags.<locals>.<listcomp>s  s     ===tt}T*===r)   )r   operatoror_r   U)r   r  s   ` r'   r  zMatchesFunction._map_flagsq  s7    hl====u===rtE E 	Er)   c                 (    d| j         d| j        dS r  r  r  s    r'   r   zMatchesFunction.__repr__t  r  r)   N)r   )r*   r+   r,   r-   rX  r   SMIXflag_mappingr@   rU  r  r   r4   r)   r'   r  r  b  s          I&IBDrt"$??L, , , ,7 7 7E E EA A A A Ar)   r  c                   "    e Zd ZdZg Zd Zd ZdS )FalseFunctionzEThe `false` function, which always returns the boolean `false` value.c                     dS NFr4   rT  s         r'   rU  zFalseFunction.__call__z  s    ur)   c                     dS )Nzfalse()r4   r  s    r'   r   zFalseFunction.__repr__|  s    yr)   Nro  r4   r)   r'   r  r  w  s=        OOI      r)   r  c                   *    e Zd ZdZdgZd Zd Zd ZdS )FloorFunctionzfThe `ceiling` function, which returns the nearest higher integer number
    for the given number.
    r   c                     || _         d S r=   r  r  s     r'   r@   zFloorFunction.__init__  rz  r)   c                 l    |                      |||||          }t          t          |                    S r=   )r   r   r9  r  s          r'   rU  zFloorFunction.__call__  1    T4j)DDXf%%&&&r)   c                     d| j         z  S )Nz	floor(%r)r  r  s    r'   r   zFloorFunction.__repr__      T[((r)   NrW  r4   r)   r'   r  r    T          
I  ' ' ') ) ) ) )r)   r  c                   "    e Zd ZdZg Zd Zd ZdS )LocalNameFunctionzXThe `local-name` function, which returns the local name of the current
    element.
    c                 2    |t           u r|d         j        S d S r|  )r   r  rT  s         r'   rU  zLocalNameFunction.__call__      5==7$$ =r)   c                     dS )Nzlocal-name()r4   r  s    r'   r   zLocalNameFunction.__repr__  s    ~r)   Nro  r4   r)   r'   r  r    sC          I% % %    r)   r  c                   "    e Zd ZdZg Zd Zd ZdS )NameFunctionzVThe `name` function, which returns the qualified name of the current
    element.
    c                 (    |t           u r|d         S d S r|  rr  rT  s         r'   rU  zNameFunction.__call__  s    5==7N =r)   c                     dS )Nzname()r4   r  s    r'   r   zNameFunction.__repr__  rt  r)   Nro  r4   r)   r'   r  r    sC          I      r)   r  c                   "    e Zd ZdZg Zd Zd ZdS )NamespaceUriFunctionz^The `namespace-uri` function, which returns the namespace URI of the
    current element.
    c                 2    |t           u r|d         j        S d S r|  )r   r]  rT  s         r'   rU  zNamespaceUriFunction.__call__  r  r)   c                     dS )Nznamespace-uri()r4   r  s    r'   r   zNamespaceUriFunction.__repr__  s      r)   Nro  r4   r)   r'   r  r    sC          I% % %! ! ! ! !r)   r  c                   *    e Zd ZdZdgZd Zd Zd ZdS )NotFunctionzUThe `not` function, which returns the negated boolean value of its
    argument.
    r#  c                     || _         d S r=   r  r"  s     r'   r@   zNotFunction.__init__  rA   r)   c           	      P    t          |                     |||||                     S r=   )rO  r#  rT  s         r'   rU  zNotFunction.__call__  s'    499T4j)LLMMMMr)   c                     d| j         z  S )Nznot(%s)r  r  s    r'   r   zNotFunction.__repr__  s    49$$r)   NrW  r4   r)   r'   r  r    sW          I  N N N% % % % %r)   r  c                   T    e Zd ZdZdgZ ej        d          j        Zd Z	d Z
d ZdS )NormalizeSpaceFunctionzThe `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,}c                     || _         d S r=   r  r"  s     r'   r@   zNormalizeSpaceFunction.__init__  rA   r)   c                     |                      |||||          }|                     dt          |                                                    S )N )r#  
_normalizerL  stripr   r]   r^   rI   rZ   r[   r  s          r'   rU  zNormalizeSpaceFunction.__call__  sC    4sJ	BBsIf$5$5$;$;$=$=>>>r)   c                 0    dt          | j                  z  S )Nznormalize-space(%s))r  r#  r  s    r'   r   zNormalizeSpaceFunction.__repr__  s    $tDI66r)   N)r*   r+   r,   r-   rX  r   r?  subr  r@   rU  r   r4   r)   r'   r  r    sh          II&&*J  ? ? ?7 7 7 7 7r)   r  c                   *    e Zd ZdZdgZd Zd Zd ZdS )NumberFunctionz=The `number` function that converts its argument to a number.r#  c                     || _         d S r=   r  r"  s     r'   r@   zNumberFunction.__init__  rA   r)   c                 R    |                      |||||          }t          |          S r=   )r#  r9  r  s          r'   rU  zNumberFunction.__call__  s'    iidCY??}}r)   c                     d| j         z  S )Nz
number(%r)r  r  s    r'   r   zNumberFunction.__repr__  s    di''r)   NrW  r4   r)   r'   r  r    sN        GGI    ( ( ( ( (r)   r  c                   *    e Zd ZdZdgZd Zd Zd ZdS )RoundFunctionz]The `round` function, which returns the nearest integer number for the
    given number.
    r   c                     || _         d S r=   r  r  s     r'   r@   zRoundFunction.__init__  rz  r)   c                 l    |                      |||||          }t          t          |                    S r=   )r   roundr9  r  s          r'   rU  zRoundFunction.__call__  r  r)   c                     d| j         z  S )Nz	round(%r)r  r  s    r'   r   zRoundFunction.__repr__  r  r)   NrW  r4   r)   r'   r  r    r  r)   r  c                   ,    e Zd ZdZddgZd Zd Zd ZdS )StartsWithFunctionzbThe `starts-with` function that returns whether one string starts with
    a given substring.
    r  r  c                 "    || _         || _        d S r=   r  r  s      r'   r@   zStartsWithFunction.__init__  r  r)   c                     |                      |||||          }|                     |||||          }t          |                              t          |                    S r=   )r  r  rL  r  r  s           r'   rU  zStartsWithFunction.__call__  sX    ,,tT3
IFF,,tT3
IFF!!,,Yw-?-?@@@r)   c                 (    d| j         d| j        dS )Nzstarts-with(r  r   r  r  s    r'   r   zStartsWithFunction.__repr__  s     (,dlllCCr)   NrW  r4   r)   r'   r  r    s_          I&I  A A AD D D D Dr)   r  c                   *    e Zd ZdZdgZd Zd Zd ZdS )StringLengthFunctionzRThe `string-length` function that returns the length of the given
    string.
    r#  c                     || _         d S r=   r  r"  s     r'   r@   zStringLengthFunction.__init__  rA   r)   c                 l    |                      |||||          }t          t          |                    S r=   )r#  rN   rL  r  s          r'   rU  zStringLengthFunction.__call__  s1    4sJ	BB9V$$%%%r)   c                     d| j         z  S )Nzstring-length(%r)r  r  s    r'   r   zStringLengthFunction.__repr__  s    "TY..r)   NrW  r4   r)   r'   r  r    sT          I  & & &/ / / / /r)   r  c                   .    e Zd ZdZg dZddZd Zd ZdS )SubstringFunctionzThe `substring` function that returns the part of a string that starts
    at the given offset, and optionally limited to the given length.
    r  startlengthNc                 0    || _         || _        || _        d S r=   r  )r   r  r  r  s       r'   r@   zSubstringFunction.__init__  s    
r)   c                 ,   |                      |||||          }|                     |||||          }d}| j        |                     |||||          }|t          |          t	          t          |                    t          |          z
           S r|  )r  r  r  rJ  rN   rL  )	r   r]   r^   rI   rZ   r[   r  r  r  s	            r'   rU  zSubstringFunction.__call__  s    T4j)DD

4sJ	BB;"[[tS*iHHFgennS6):):%;%;gfoo%MMNNr)   c                 l    | j         d| j        d| j        d| j         dS d| j        d| j        dS )Nz
substring(r  r   )r  r  r  r  s    r'   r   zSubstringFunction.__repr__  sO    ;"".2kkk4:::.2kkk; ; # +/+++tzzzBBr)   r=   rW  r4   r)   r'   r  r    se          .--I   O O OC C C C Cr)   r  c                   ,    e Zd ZdZddgZd Zd Zd ZdS )SubstringAfterFunctionzrThe `substring-after` function that returns the part of a string that
    is found after the given substring.
    r  r  c                 "    || _         || _        d S r=   r  r  s      r'   r@   zSubstringAfterFunction.__init__  r  r)   c           	         t          |                     |||||                    }t          |                     |||||                    }|                    |          }|dk    r||t	          |          z   d          S dS Nr   r   )rL  r  r  findrN   	r   r]   r^   rI   rZ   r[   r  r  indexs	            r'   rU  zSubstringAfterFunction.__call__  s    DLLtS*iPPQQDLLtS*iPPQQW%%A::53w<</0011rr)   c                 (    d| j         d| j        dS Nzsubstring-after(r  r   r  r  s    r'   r   zSubstringAfterFunction.__repr__"       ,0LLL$,,,GGr)   NrW  r4   r)   r'   r  r    \          I&I    H H H H Hr)   r  c                   ,    e Zd ZdZddgZd Zd Zd ZdS )SubstringBeforeFunctionztThe `substring-before` function that returns the part of a string that
    is found before the given substring.
    r  r  c                 "    || _         || _        d S r=   r  r  s      r'   r@   z SubstringBeforeFunction.__init__*  r  r)   c           	          t          |                     |||||                    }t          |                     |||||                    }|                    |          }|dk    r
|d |         S dS r  )rL  r  r  r  r  s	            r'   rU  z SubstringBeforeFunction.__call__-  sq    DLLtS*iPPQQDLLtS*iPPQQW%%A::6E6?"rr)   c                 (    d| j         d| j        dS r  r  r  s    r'   r   z SubstringBeforeFunction.__repr__4  r  r)   NrW  r4   r)   r'   r  r  %  r  r)   r  c                   ,    e Zd ZdZg dZd Zd Zd ZdS )TranslateFunctionznThe `translate` function that translates a set of characters in a
    string to target set of characters.
    r  	fromcharstocharsc                 0    || _         || _        || _        d S r=   r  )r   r  r  r   s       r'   r@   zTranslateFunction.__init__<  s    "r)   c           	      r   t          |                     |||||                    }t          |                     |||||                    }t          |                     |||||                    }t	          t          d |D             d |D                                 }	|                    |	          S )Nc                 ,    g | ]}t          |          S r4   ordrH   cs     r'   rK   z.TranslateFunction.__call__.<locals>.<listcomp>D  s    444Q#a&&444r)   c                 ,    g | ]}t          |          S r4   r$  r&  s     r'   rK   z.TranslateFunction.__call__.<locals>.<listcomp>E  s    222Q#a&&222r)   )rL  r  r  r   dictzip	translate)
r   r]   r^   rI   rZ   r[   r  r  r   tables
             r'   rU  zTranslateFunction.__call__@  s    4;;tT3
INNOOdnnT4j)TTUU	DLLtS*iPPQQS44)44422'2224 4 5 5&&&r)   c                 8    d| j         d| j        d| j        dS )Nz
translate(r  r   r  r  s    r'   r   zTranslateFunction.__repr__G  s(     *.+++t~~~*.,,,8 	8r)   NrW  r4   r)   r'   r  r  7  sX          322I  ' ' '8 8 8 8 8r)   r  c                   "    e Zd ZdZg Zd Zd ZdS )TrueFunctionzCThe `true` function, which always returns the boolean `true` value.c                     dS r8   r4   rT  s         r'   rU  zTrueFunction.__call__N  s    tr)   c                     dS )Nztrue()r4   r  s    r'   r   zTrueFunction.__repr__P  rt  r)   Nro  r4   r)   r'   r/  r/  K  s=        MMI      r)   r/  booleanceilingconcatcontainsmatchesfalser   z
local-namer&   znamespace-uriznormalize-spacenotr   r  zstarts-withzstring-length	substring)zsubstring-afterzsubstring-beforer+  truec                       e Zd ZdZdS )Literalz&Abstract base class for literal nodes.Nr  r4   r)   r'   r<  r<  b  s        0000r)   r<  c                   *    e Zd ZdZdgZd Zd Zd ZdS )r6  zA string literal node.r   c                     || _         d S r=   r   )r   r   s     r'   r@   zStringLiteral.__init__h  rA   r)   c                     | j         S r=   r?  rT  s         r'   rU  zStringLiteral.__call__j  rd  r)   c                     d| j         z  S )Nz"%s"r?  r  s    r'   r   zStringLiteral.__repr__l  s    	!!r)   NrW  r4   r)   r'   r6  r6  e  sN          I    " " " " "r)   r6  c                   *    e Zd ZdZdgZd Zd Zd ZdS )r8  zA number literal node.r   c                     || _         d S r=   r  r  s     r'   r@   zNumberLiteral.__init__r  rz  r)   c                     | j         S r=   r  rT  s         r'   rU  zNumberLiteral.__call__t  s
    {r)   c                 *    t          | j                  S r=   )strr   r  s    r'   r   zNumberLiteral.__repr__v  s    4;r)   NrW  r4   r)   r'   r8  r8  o  sN          
I             r)   r8  c                   *    e Zd ZdZdgZd Zd Zd ZdS )r:  zA variable reference node.r&   c                     || _         d S r=   rc  )r   r&   s     r'   r@   zVariableReference.__init__|  rA   r)   c                 6    |                     | j                  S r=   )r  r&   rT  s         r'   rU  zVariableReference.__call__~  s    }}TY'''r)   c                 *    t          | j                  S r=   )rF  r&   r  s    r'   r   zVariableReference.__repr__  s    49~~r)   NrW  r4   r)   r'   r:  r:  y  sN        $$I  ( ( (    r)   r:  c                   ,    e Zd ZdZddgZd Zd Zd ZdS )r+  zThe boolean operator `and`.lvalrvalc                 "    || _         || _        d S r=   rL  rM  r   rL  rM  s      r'   r@   zAndOperator.__init__      				r)   c           	          t          |                     |||||                    }|sdS |                     |||||          }t          |          S r  rO  rL  rM  r   r]   r^   rI   rZ   r[   rL  rM  s           r'   rU  zAndOperator.__call__  sU    tyytS*iHHII 	5yytS*i@@t}}r)   c                 $    | j         d| j        S )Nz and rO  r  s    r'   r   zAndOperator.__repr__  s    "iii33r)   NrW  r4   r)   r'   r+  r+    sQ        %% I    4 4 4 4 4r)   r+  c                   ,    e Zd ZdZddgZd Zd Zd ZdS )EqualsOperatorzThe equality operator `=`.rL  rM  c                 "    || _         || _        d S r=   rO  rP  s      r'   r@   zEqualsOperator.__init__  rQ  r)   c           	          t          |                     |||||                    }t          |                     |||||                    }||k    S r=   rE  rL  rM  rT  s           r'   rU  zEqualsOperator.__call__  N    4sJ	JJKK4sJ	JJKKt|r)   c                 $    | j         d| j        S )Nr   rO  r  s    r'   r   zEqualsOperator.__repr__      )))TYY//r)   NrW  r4   r)   r'   rW  rW    sQ        $$ I    0 0 0 0 0r)   rW  c                   ,    e Zd ZdZddgZd Zd Zd ZdS )NotEqualsOperatorzThe equality operator `!=`.rL  rM  c                 "    || _         || _        d S r=   rO  rP  s      r'   r@   zNotEqualsOperator.__init__  rQ  r)   c           	          t          |                     |||||                    }t          |                     |||||                    }||k    S r=   rZ  rT  s           r'   rU  zNotEqualsOperator.__call__  r[  r)   c                 $    | j         d| j        S )Nr   rO  r  s    r'   r   zNotEqualsOperator.__repr__      999dii00r)   NrW  r4   r)   r'   r_  r_    sQ        %% I    1 1 1 1 1r)   r_  c                   ,    e Zd ZdZddgZd Zd Zd ZdS )r'  zThe boolean operator `or`.rL  rM  c                 "    || _         || _        d S r=   rO  rP  s      r'   r@   zOrOperator.__init__  rQ  r)   c           	          t          |                     |||||                    }|rdS |                     |||||          }t          |          S r8   rS  rT  s           r'   rU  zOrOperator.__call__  sU    tyytS*iHHII 	4yytS*i@@t}}r)   c                 $    | j         d| j        S )Nz or rO  r  s    r'   r   zOrOperator.__repr__  s    !YYY		22r)   NrW  r4   r)   r'   r'  r'    sQ        $$ I    3 3 3 3 3r)   r'  c                   ,    e Zd ZdZddgZd Zd Zd ZdS )GreaterThanOperatorz+The relational operator `>` (greater than).rL  rM  c                 "    || _         || _        d S r=   rO  rP  s      r'   r@   zGreaterThanOperator.__init__  rQ  r)   c                     |                      |||||          }|                     |||||          }t          |          t          |          k    S r=   rL  rM  r9  rT  s           r'   rU  zGreaterThanOperator.__call__  K    yytS*i@@yytS*i@@~~..r)   c                 $    | j         d| j        S )Nr   rO  r  s    r'   r   zGreaterThanOperator.__repr__  r]  r)   NrW  r4   r)   r'   ri  ri    sQ        55 I  / / /0 0 0 0 0r)   ri  c                   ,    e Zd ZdZddgZd Zd Zd ZdS )GreaterThanOrEqualOperatorz5The relational operator `>=` (greater than or equal).rL  rM  c                 "    || _         || _        d S r=   rO  rP  s      r'   r@   z#GreaterThanOrEqualOperator.__init__  rQ  r)   c                     |                      |||||          }|                     |||||          }t          |          t          |          k    S r=   rl  rT  s           r'   rU  z#GreaterThanOrEqualOperator.__call__  K    yytS*i@@yytS*i@@~~$//r)   c                 $    | j         d| j        S )Nr   rO  r  s    r'   r   z#GreaterThanOrEqualOperator.__repr__  rc  r)   NrW  r4   r)   r'   rp  rp    sQ        ?? I  0 0 01 1 1 1 1r)   rp  c                   ,    e Zd ZdZddgZd Zd Zd ZdS )LessThanOperatorz(The relational operator `<` (less than).rL  rM  c                 "    || _         || _        d S r=   rO  rP  s      r'   r@   zLessThanOperator.__init__  rQ  r)   c                     |                      |||||          }|                     |||||          }t          |          t          |          k     S r=   rl  rT  s           r'   rU  zLessThanOperator.__call__  rm  r)   c                 $    | j         d| j        S )Nr   rO  r  s    r'   r   zLessThanOperator.__repr__  r]  r)   NrW  r4   r)   r'   rv  rv    sQ        22 I  / / /0 0 0 0 0r)   rv  c                   ,    e Zd ZdZddgZd Zd Zd ZdS )LessThanOrEqualOperatorz2The relational operator `<=` (less than or equal).rL  rM  c                 "    || _         || _        d S r=   rO  rP  s      r'   r@   z LessThanOrEqualOperator.__init__  rQ  r)   c                     |                      |||||          }|                     |||||          }t          |          t          |          k    S r=   rl  rT  s           r'   rU  z LessThanOrEqualOperator.__call__  rs  r)   c                 $    | j         d| j        S )Nr   rO  r  s    r'   r   z LessThanOrEqualOperator.__repr__  rc  r)   NrW  r4   r)   r'   r{  r{    sQ        << I  0 0 01 1 1 1 1r)   r{  )r   r   r   r   r   r   r4   )ar-   collectionsr   	functoolsr   mathr   r   r  r   	itertoolsr   genshi.compatr   r	   genshi.corer
   r   r   r   r   r   r   r   r   r   r   r   r   __all____docformat__objectr   r.   r/   r0   r1   r2   r6   r~   r   r   r   r   r   rE  r9  rJ  rL  rO  r  r  r   r  r   r  rv  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r/  r=  r<  r6  r8  r:  r+  rW  r_  r'  ri  rp  rv  r{  r.  rw   rx   r4   r)   r'   <module>r     st   6                      				       / / / / / / / / 7 7 7 7 7 7 7 7 7 7 7 7/ / / / / / / / / / / / / / / / / / / / / / $
%%B B B B B6 B B B" N	
_
, yV V V V Vf V V VrL L L L L L L L^C C C C C C C CLA A A A A6 A A AH	 	 	 	 	i 	 	 	B B B B B B B BN  # # #
& & &  " " "       $ $ $ $ $ $ $ $$    F   "2 2 2 2 2 2 2 2&    f       v   2 2 2 2 2F 2 2 2    6    ,X+H%' '> > > > >v > > >) ) ) ) )h ) ) )+ + + + +h + + +M M M M MX M M M A A A A Ax A A AA A A A Ah A A A*    H   ) ) ) ) )H ) ) )	 	 	 	 	 	 	 		 	 	 	 	8 	 	 		! 	! 	! 	! 	!8 	! 	! 	!
% 
% 
% 
% 
%( 
% 
% 
%7 7 7 7 7X 7 7 7	( 	( 	( 	( 	(X 	( 	( 	() ) ) ) )H ) ) )D D D D D D D D/ / / / /8 / / /C C C C C C C C.H H H H HX H H H$H H H H Hh H H H$8 8 8 8 8 8 8 8(    8   'O 'Y '>'+57G'O'-4m'EL' !-.?' BH	'  /0D	'
 #$:'
 =B;' >' ,3M'  2' 5D%' (34E' %;(7H%' ' '1 1 1 1 1f 1 1 1" " " " "G " " "         G             4 4 4 4 4& 4 4 40 0 0 0 0V 0 0 01 1 1 1 1 1 1 13 3 3 3 3 3 3 30 0 0 0 0& 0 0 01 1 1 1 1 1 1 10 0 0 0 0v 0 0 01 1 1 1 1f 1 1 1 %,=)1K&.EG G
 %&7&7&=&=rB$$T**B/			r)   