
    tf$                     D   d Z ddlmZ  G d de          Z G d d          Z G d d          Z G d	 d
          Z G d d          Zd Z	 G d d          Z
 G d d          Z G d d          Z G d d          Z G d d          Zi Zd Zd Zd Zd Zd ZdS )z
XPath query support.

This module provides L{XPathQuery} to match
L{domish.Element<twisted.words.xish.domish.Element>} instances against
XPath-like expressions.
    )StringIOc                       e Zd Zd ZdS )LiteralValuec                     | S N selfelems     W/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/words/xish/xpath.pyvaluezLiteralValue.value   s        N)__name__
__module____qualname__r   r   r   r   r   r      s#            r   r   c                       e Zd Zd Zd ZdS )
IndexValuec                 4    t          |          dz
  | _        d S )N   )intindex)r
   r   s     r   __init__zIndexValue.__init__   s    ZZ!^


r   c                 &    |j         | j                 S r   )childrenr   r	   s     r   r   zIndexValue.value   s    }TZ((r   N)r   r   r   r   r   r   r   r   r   r      s2        $ $ $) ) ) ) )r   r   c                        e Zd Zd Zd Zd ZdS )AttribValuec                 F    || _         | j         dk    r| j        | _        d S d S )Nxmlns)
attribnamevalue_nsr   )r
   r   s     r   r   zAttribValue.__init__    s+    $?g%%DJJJ &%r   c                     |j         S r   )urir	   s     r   r    zAttribValue.value_ns%   s	    xr   c                 F    | j         |j        v r|j        | j                  S d S r   )r   
attributesr	   s     r   r   zAttribValue.value(   s%    ?do--?4?334r   N)r   r   r   r   r    r   r   r   r   r   r      sA        ' ' '
      r   r   c                        e Zd Zd Zd Zd ZdS )CompareValuec                 b    || _         || _        |dk    r| j        | _        d S | j        | _        d S )N=)lhsrhs_compareEqualr   _compareNotEqualr
   r)   opr*   s       r   r   zCompareValue.__init__0   s5    99+DJJJ.DJJJr   c                 n    | j                             |          | j                            |          k    S r   r)   r   r*   r	   s     r   r+   zCompareValue._compareEqual8   )    x~~d##tx~~d';';;;r   c                 n    | j                             |          | j                            |          k    S r   r0   r	   s     r   r,   zCompareValue._compareNotEqual;   r1   r   N)r   r   r   r   r+   r,   r   r   r   r&   r&   /   sA        / / /< < << < < < <r   r&   c                   $    e Zd ZdZd Zd Zd ZdS )BooleanValuea^  
    Provide boolean XPath expression operators.

    @ivar lhs: Left hand side expression of the operator.
    @ivar op: The operator. One of C{'and'}, C{'or'}.
    @ivar rhs: Right hand side expression of the operator.
    @ivar value: Reference to the method that will calculate the value of
                 this expression given an element.
    c                 b    || _         || _        |dk    r| j        | _        d S | j        | _        d S )Nand)r)   r*   _booleanAndr   
_booleanOrr-   s       r   r   zBooleanValue.__init__J   s4    ;;)DJJJDJJJr   c                 j    | j                             |          o| j                            |          S )z
        Calculate boolean and of the given expressions given an element.

        @param elem: The element to calculate the value of the expression from.
        r0   r	   s     r   r7   zBooleanValue._booleanAndR   s+     x~~d##<t(<(<<r   c                 j    | j                             |          p| j                            |          S )z
        Calculate boolean or of the given expressions given an element.

        @param elem: The element to calculate the value of the expression from.
        r0   r	   s     r   r8   zBooleanValue._booleanOrZ   s+     x~~d##;tx~~d';';;r   N)r   r   r   __doc__r   r7   r8   r   r   r   r4   r4   ?   sK         ) ) )= = =< < < < <r   r4   c                 H    d| z  } t                      |                     }|S )z;
    Internal method which selects the function object
    z_%s_Function)globals)fname	klassnamecs      r   FunctionrA   c   s)     &I		)AHr   c                        e Zd Zd Zd Zd ZdS )_not_Functionc                     d | _         d S r   	baseValuer
   s    r   r   z_not_Function.__init__m   s    r   c                     || _         d S r   rE   )r
   rF   s     r   	setParamsz_not_Function.setParamsp   s    "r   c                 8    | j                             |           S r   )rF   r   r	   s     r   r   z_not_Function.values   s    >''----r   N)r   r   r   r   rI   r   r   r   r   rC   rC   l   sA          # # #. . . . .r   rC   c                       e Zd Zd Zd ZdS )_text_Functionc                     d S r   r   rG   s    r   rI   z_text_Function.setParamsx   s    r   c                      t          |          S r   )strr	   s     r   r   z_text_Function.value{   s    4yyr   N)r   r   r   rI   r   r   r   r   rL   rL   w   s2              r   rL   c                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )	_Locationc                 0    g | _         d | _        d | _        d S r   
predicateselementNamechildLocationrG   s    r   r   z_Location.__init__       !r   c                     | j         d k    r| j         |j        k    rdS | j        D ]}|                    |          s dS dS Nr   r   )rU   namerT   r   r
   r   ps      r   matchesPredicatesz_Location.matchesPredicates   sZ    t##(8DI(E(E1 	 	A774== qq qr   c                     |                      |          sdS | j        d k    r5|                                D ]}| j                            |          r dS  ndS dS rY   )r]   rV   elementsmatchesr
   r   r@   s      r   r`   z_Location.matches   sx    %%d++ 	1%%]]__  %--a00 11 1qr   c                     |                      |          sd S | j        d k    r4|                                D ]}| j                            ||           d S |                    t          |                     d S r   )r]   rV   r_   queryForStringwriterO   )r
   r   	resultbufr@   s       r   rc   z_Location.queryForString   s    %%d++ 	F%%]]__ @ @"11!Y????@ @ OOCII&&&&&r   c                     |                      |          sd S | j        d k    r4|                                D ]}| j                            ||           d S |                    |           d S r   )r]   rV   r_   queryForNodesappendr
   r   
resultlistr@   s       r   rg   z_Location.queryForNodes   s    %%d++ 	F%%]]__ @ @"00J????@ @ d#####r   c                    |                      |          sd S | j        d k    r4|                                D ]}| j                            ||           d S |j        D ],}t          |t                    r|                    |           -d S r   )r]   rV   r_   queryForStringListr   
isinstancerO   rh   ri   s       r   rl   z_Location.queryForStringList   s    %%d++ 	F%%]]__ E E"55aDDDDE E ] ) )a%% )%%a((() )r   N)	r   r   r   r   r]   r`   rc   rg   rl   r   r   r   rQ   rQ      sn        " " "
    ' ' '$ $ $
) 
) 
) 
) 
)r   rQ   c                   D    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
S )_AnyLocationc                 0    g | _         d | _        d | _        d S r   rS   rG   s    r   r   z_AnyLocation.__init__   rW   r   c                 J    | j         D ]}|                    |          s dS dS rY   )rT   r   r[   s      r   r]   z_AnyLocation.matchesPredicates   s6     	 	A774== qqqr   c                     |j         d k    r|                     |j         |           |                    |j                   d S r   )parentlistParentsrh   rZ   )r
   r   
parentlists      r   rt   z_AnyLocation.listParents   sC    ;$T[*555$)$$$$$r   c                     | j         d k    s| j         |j        k    rW|                     |          rB| j        d k    r5|                                D ]}| j                            |          r dS  ndS dS NTFrU   rZ   r]   rV   r_   r`   ra   s      r   isRootMatchz_AnyLocation.isRootMatch   s    $$(8DI(E(E$$T** )F!T)) $ $A)11!44 $#tt$$ tur   c                 N   | j         d k    s| j         |j        k    rY|                     |          rD| j        d k    r7|                                D ] }| j                            |          r|c S !d S |S |                                D ]}|                     |          r|c S d S r   rx   ra   s      r   findFirstRootMatchz_AnyLocation.findFirstRootMatch   s    $$(8DI(E(E$$T** )F !T)) ! !A)11!44 ! !t 
 ]]__  <<?? HHH 4r   c                     |                      |          rdS |                                D ]}|                     |          r dS dS rw   )ry   r_   r`   ra   s      r   r`   z_AnyLocation.matches   s[    D!! 
	4
 ]]__    <<??  44  5r   c                      t          d          )Nz2queryForString is not implemented for any location)NotImplementedError)r
   r   re   s      r   rc   z_AnyLocation.queryForString  s    !"VWWWr   c                     |                      |          r|                    |           |                                D ]}|                     ||           d S r   )ry   rh   r_   rg   ri   s       r   rg   z_AnyLocation.queryForNodes  sh    D!! 	$d###  	. 	.Aq*----	. 	.r   c                     |                      |          r4|j        D ],}t          |t                    r|                    |           -|                                D ]}|                     ||           d S r   )ry   r   rm   rO   rh   r_   rl   ri   s       r   rl   z_AnyLocation.queryForStringList  s    D!! 	)] ) )a%% )%%a((( 	3 	3A##Az2222	3 	3r   N)r   r   r   r   r]   rt   ry   r{   r`   rc   rg   rl   r   r   r   ro   ro      s        " " "
  % % %

 
 
  4  X X X. . .3 3 3 3 3r   ro   c                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )
XPathQueryc                     || _         ddlm}m}  | ||                    } t	          |d                      | _        d S )Nr   )XPathParserXPathParserScannerXPATH)queryStrtwisted.words.xish.xpathparserr   r   getattrbaseLocation)r
   r   r   r   parsers        r   r   zXPathQuery.__init__  s\     RRRRRRRR//99::4GFG4466r   c                 4    | j                                         S r   )r   __hash__rG   s    r   r   zXPathQuery.__hash__  s    }%%'''r   c                 6    | j                             |          S r   )r   r`   r	   s     r   r`   zXPathQuery.matches"  s     ((...r   c                 |    t                      }| j                            ||           |                                S r   )r   r   rc   getvaluer
   r   results      r   rc   zXPathQuery.queryForString%  s4    ((v666   r   c                 j    g }| j                             ||           t          |          dk    rd S |S Nr   )r   rg   lenr   s      r   rg   zXPathQuery.queryForNodes*  s;    ''f555v;;!4Mr   c                 j    g }| j                             ||           t          |          dk    rd S |S r   )r   rl   r   r   s      r   rl   zXPathQuery.queryForStringList2  s;    ,,T6:::v;;!4Mr   N)	r   r   r   r   r   r`   rc   rg   rl   r   r   r   r   r     sn        7 7 7( ( (/ / /! ! !
      r   r   c                 \    | t           vrt          |           t           | <   t           |          S r   )__internedQueriesr   )queryStrings    r   internQueryr   >  s,    +++)3K)@)@+&[))r   c                 F    t          |                               |          S r   )r   r`   xpathstrr   s     r   r`   r`   D  s    x  ((...r   c                 F    t          |                               |          S r   )r   rl   r   s     r   rl   rl   H  s    x  33D999r   c                 F    t          |                               |          S r   )r   rc   r   s     r   rc   rc   L  s    x  //555r   c                 F    t          |                               |          S r   )r   rg   r   s     r   rg   rg   P  s    x  ..t444r   N)r;   ior   rO   r   r   r   r&   r4   rA   rC   rL   rQ   ro   r   r   r   r`   rl   rc   rg   r   r   r   <module>r      s-             3   
) ) ) ) ) ) ) )        < < < < < < < < !< !< !< !< !< !< !< !<H  . . . . . . . .       ;) ;) ;) ;) ;) ;) ;) ;)|V3 V3 V3 V3 V3 V3 V3 V3r" " " " " " " "J  * * */ / /: : :6 6 65 5 5 5 5r   