
    Yf=*                     h    d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	  G d dej
                  ZdS )	    )unittest)xpath)Element)
XPathQuery)SyntaxErrorc                       e Zd ZddZddZddZddZddZddZdd	Z	dd
Z
ddZddZddZddZddZddZddZddZddZddZddZddZddZddZddZddZddZddZddZdS )
XPathTestsreturnNc                 B   t          d          | _        d| j        d<   d| j        d<   | j                            d           | j                            d          | _        | j                            d          | _        | j                            d	          | _        | j                            d
           | j                            d           | j                            d          | _        d| j        d<   | j                            d          | _        | j                            d          | _	        | j                            d	          | _
        | j
                            d           | j                            d          | _        | j                            d          | _        d| j        d<   d| j        d<   | j                            d          | _        | j                            d	          | _        | j                            d           | j                            d          | _        d| j        d<   d| j        d<   | j                            d          | _        | j                            d	          | _        | j                            d           | j                            d          | _        d| j        d<   d| j        d<   d| j        d<   | j                            d          | _        | j                            d           d S )N)testnsfoovalue1attrib1zuser@host/resourceattrib3somecontentbarr   garDEFsomemorecontentvalue2attrib2ABCvalue4attrib4value5attrib5JKLMNOvalue6   áattrib6quuxu   ☃)r   e
addContent
addElementbar1subfoogar1bar2bar3subfoo2gar2bar4bar5subfoo3gar3bar6subfoo4gar4bar7r"   selfs    O/var/www/html/env/lib/python3.11/site-packages/twisted/words/test/test_xpath.pysetUpzXPathTests.setUp   s   8 *++$y0y-(((F%%e,,	i**511K**511		U###+,,,F%%e,,	'	)I((//	y++E22I((//		U###F%%e,,	F%%e,,	'	)'	)y++E22I((//		U###F%%e,,	'	)'	)y++E22I((//		U###F%%e,,	'	)'	)#	)I((00		]+++++    c           	         |                      t          j        d| j                  d           |                      t          j        d| j                  | j        | j        | j        | j        | j	        | j
        g           |                      t          j        d| j                  d           |                      t          j        d| j                  ddg           dS )z=
        Test basic operation of the static methods.
        /foo/barT/foor   r   N)assertEqualr   matchesr#   queryForNodesr&   r)   r-   r.   r1   r4   queryForStringqueryForStringListr5   s    r7   test_staticMethodszXPathTests.test_staticMethodsL   s     	z46::DAAA
DF33Y	49diDIN	
 	
 	
 	-fdf==}MMM$VTV44}FW6X	
 	
 	
 	
 	
r9   c                     t          d          }|                     |                    | j                  d           dS )z3
        Test matching foo with child bar.
        r;      Nr   r=   r>   r#   r6   xps     r7   test_locationFooBarzXPathTests.test_locationFooBarZ   s;     
##DF++Q/////r9   c                     t          d          }|                     |                    | j                  d           |                     |                    | j                  | j        | j        | j        g           dS )z8
        Test finding foos at the second level.
        z/foo/bar/foorD   N)r   r=   r>   r#   r?   r'   r/   r2   rF   s     r7   test_locationFooBarFooz!XPathTests.test_locationFooBarFooa   sy     ''DF++Q///TV$$t{DL$,&O	
 	
 	
 	
 	
r9   c                     t          d          }|                     |                    | j                  d           dS )z(
        Test not finding bar3.
        z	/foo/bar3r   NrE   rF   s     r7   test_locationNoBar3zXPathTests.test_locationNoBar3k   s;     $$DF++Q/////r9   c           	      $   t          d          }|                     |                    | j                  d           |                     |                    | j                  | j        | j        | j        | j        | j	        | j
        g           dS )z-
        Test finding childs of foo.
        z/foo/*TN)r   r=   r>   r#   r?   r&   r)   r-   r.   r1   r4   rF   s     r7   test_locationAllChildsz!XPathTests.test_locationAllChildsr   s     !!DF++T222TV$$Y	49diDIN	
 	
 	
 	
 	
r9   c                     t          d          }|                     |                    | j                  d           dS )z3
        Test matching foo with attribute.
        z/foo[@attrib1]TNrE   rF   s     r7   test_attributezXPathTests.test_attribute}   s<     ())DF++T22222r9   c                     t          d          }|                     |                    | j                  d           |                     |                    | j                  | j        g           dS )z>
        Test find nodes with attribute having value.
        z/foo/*[@attrib2='value2']TN)r   r=   r>   r#   r?   r)   rF   s     r7   test_attributeWithValueAnyz%XPathTests.test_attributeWithValueAny   f     344DF++T222))$&11DI;?????r9   c                     t          d          }|                     |                    | j                  d           |                     |                    | j                  | j        g           dS )zI
        Nodes' attributes can be matched with non-ASCII values.
        u   /foo/*[@attrib6='á']TN)r   r=   r>   r#   r?   r4   rF   s     r7   test_locationWithValueUnicodez(XPathTests.test_locationWithValueUnicode   sf     /00DF++T222))$&11DI;?????r9   c                     t          d          }|                     |                    | j                  d           dS )z4
        Test matching node with namespace.
        z/foo[@xmlns='testns']/barrD   NrE   rF   s     r7   test_namespaceFoundzXPathTests.test_namespaceFound   <     344DF++Q/////r9   c                     t          d          }|                     |                    | j                  d           dS )z>
        Test not matching node with wrong namespace.
        z/foo[@xmlns='badns']/bar2r   NrE   rF   s     r7   test_namespaceNotFoundz!XPathTests.test_namespaceNotFound   rX   r9   c                     t          d          }|                     |                    | j                  d           dS )zA
        Test matching node with attribute having value.
        z/foo[@attrib1='value1']rD   NrE   rF   s     r7   test_attributeWithValuez"XPathTests.test_attributeWithValue   s<     122DF++Q/////r9   c                     t          d          }|                     |                    | j                  d           dS )zM
        queryforString on absolute paths returns their first CDATA.
        r<   r   N)r   r=   r@   r#   rF   s     r7   test_queryForStringzXPathTests.test_queryForString   s=     **4622MBBBBBr9   c                     t          d          }|                     |                    | j                  ddg           dS )zO
        queryforStringList on absolute paths returns all their CDATA.
        r<   r   r   Nr   r=   rA   r#   rF   s     r7   test_queryForStringListz"XPathTests.test_queryForStringList   sN     !!$&))M;L+M	
 	
 	
 	
 	
r9   c                     t          d          }|                     |                    | j                  ddg           dS )zO
        queryforStringList on relative paths returns all their CDATA.
        z//foor   r   Nr`   rF   s     r7   "test_queryForStringListAnyLocationz-XPathTests.test_queryForStringListAnyLocation   sN       !!$&))M;L+M	
 	
 	
 	
 	
r9   c           	          t          d          }|                     |                    | j                  | j        | j        | j        | j        | j        | j	        g           dS )z%
        Test finding nodes.
        r;   N)
r   r=   r?   r#   r&   r)   r-   r.   r1   r4   rF   s     r7   test_queryForNodeszXPathTests.test_queryForNodes   sb     
##TV$$Y	49diDIN	
 	
 	
 	
 	
r9   c                     t          d          }|                     |                    | j                  d           dS )z7
        Test matching a node with given text.
        z/foo[text() = 'somecontent']TNrE   rF   s     r7   test_textConditionzXPathTests.test_textCondition   s<     677DF++T22222r9   c                     t          d          }|                     |                    | j                  d           |                     |                    | j                  | j        g           dS )zK
        A node can be matched by text with non-ascii code points.
        u   //*[text()='☃']TN)r   r=   r>   r#   r?   r"   rF   s     r7   test_textConditionUnicodez$XPathTests.test_textConditionUnicode   rS   r9   c                     t          d          }|                     |                    | j                  d           dS )z(
        Test for not operator.
        z/foo[not(@nosuchattrib)]TNrE   rF   s     r7   test_textNotOperatorzXPathTests.test_textNotOperator   s<     233DF++T22222r9   c                 l   t          d          }|                     |                    | j                  d           |                     |                    | j                  | j        | j        | j        | j        g           |                     |	                    | j                  g d           dS )zS
        Test finding any nodes named gar and getting their text contents.
        z//garT)r   r   r   r   N)
r   r=   r>   r#   r?   r(   r,   r0   r3   rA   rF   s     r7   test_anyLocationAndTextz"XPathTests.test_anyLocationAndText   s       DF++T222TV$$ty$)TY	&R	
 	
 	
 	..tv668T8T8TUUUUUr9   c           
      0   t          d          }|                     |                    | j                  d           |                     |                    | j                  | j        | j        | j        | j        | j	        | j
        | j        g           dS )z3
        Test finding any nodes named bar.
        //barTN)r   r=   r>   r#   r?   r&   r)   r*   r-   r.   r1   r4   rF   s     r7   test_anyLocationzXPathTests.test_anyLocation   s       DF++T222TV$$								
 	
 	
 	
 	
r9   c                 f    t          d          }|                     t          |j        d           dS )zn
        L{XPathQuery.queryForString} should raise a L{NotImplementedError}
        for any location.
        ro   N)r   assertRaisesNotImplementedErrorr@   rF   s     r7   test_anyLocationQueryForStringz)XPathTests.test_anyLocationQueryForString   s3    
   -r/@$GGGGGr9   c                     t          d          }|                     |                    | j                  d           |                     |                    | j                  | j        g           dS )z9
        Test boolean and operator in condition.
        z.//bar[@attrib4='value4' and @attrib5='value5']TN)r   r=   r>   r#   r?   r.   rF   s     r7   test_andOperatorzXPathTests.test_andOperator  sf     HIIDF++T222))$&11DI;?????r9   c                     t          d          }|                     |                    | j                  d           |                     |                    | j                  | j        | j        g           dS )z8
        Test boolean or operator in condition.
        z-//bar[@attrib5='value4' or @attrib5='value5']TN)r   r=   r>   r#   r?   r.   r1   rF   s     r7   test_orOperatorzXPathTests.test_orOperator  sk     GHHDF++T222))$&11DIty3IJJJJJr9   c                     t          d          }|                     |                    | j                  d           |                     |                    | j                  | j        | j        g           dS )zK
        Test multiple boolean operators in condition with parens.
        zf//bar[@attrib4='value4' and
                                 (@attrib5='value4' or @attrib5='value6')]TN)r   r=   r>   r#   r?   r1   r4   rF   s     r7   test_booleanOperatorsParensz&XPathTests.test_booleanOperatorsParens  st     N
 
 	DF++T222))$&11DIty3IJJJJJr9   c                     t          d          }|                     |                    | j                  d           |                     |                    | j                  | j        | j        | j        g           dS )zN
        Test multiple boolean operators in condition without parens.
        z//bar[@attrib5='value4' or
                                 @attrib5='value5' or
                                 @attrib5='value6']TN)r   r=   r>   r#   r?   r.   r1   r4   rF   s     r7   test_booleanOperatorsNoParensz(XPathTests.test_booleanOperatorsNoParens#  sw     7
 

 	DF++T222))$&11DIty$)3TUUUUUr9   c                     |                      t          t          d          }|                     |j                            d          d|j        z             dS )z}
        A missing closing bracket raises a SyntaxError.

        This test excercises the most common failure mode.
        z//bar[@attrib1zTrying to find one ofzCSyntaxError message '%s' doesn't start with 'Trying to find one of'N)rr   r   r   
assertTruemsg
startswith)r6   excs     r7   test_badXPathNoClosingBracketz(XPathTests.test_badXPathNoClosingBracket/  s]     Z9MNNG677Ug	
 	
 	
 	
 	
r9   )r
   N)__name__
__module____qualname__r8   rB   rH   rJ   rL   rN   rP   rR   rU   rW   rZ   r\   r^   ra   rc   re   rg   ri   rk   rm   rp   rt   rv   rx   rz   r|   r    r9   r7   r	   r	      sY       =, =, =, =,~
 
 
 
0 0 0 0
 
 
 
0 0 0 0	
 	
 	
 	
3 3 3 3@ @ @ @@ @ @ @0 0 0 00 0 0 00 0 0 0C C C C
 
 
 

 
 
 

 
 
 
3 3 3 3@ @ @ @3 3 3 3	V 	V 	V 	V
 
 
 
&H H H H@ @ @ @K K K K	K 	K 	K 	K
V 
V 
V 
V
 
 
 
 
 
r9   r	   N)twisted.trialr   twisted.words.xishr   twisted.words.xish.domishr   twisted.words.xish.xpathr   twisted.words.xish.xpathparserr   TestCaser	   r   r9   r7   <module>r      s   
 # " " " " " $ $ $ $ $ $ - - - - - - / / / / / / 6 6 6 6 6 6n
 n
 n
 n
 n
" n
 n
 n
 n
 n
r9   