+
    Dfj,                         R t ^ RIHt ^ RIHtHt ^ RIHt ^ RIH	t	 ^ RI
HtHt  ! R R4      t ! R R	]]	4      t ! R
 R]]	4      tR# )zH
Specific tests for (some of) the methods in L{twisted.web.domhelpers}.
)reload)AnyOptional)minidom)TestCase)
domhelpersmicrodomc                      a  ] tR t^t o RtRtR tR tR tR t	R t
R tR	 tR
 tR tR tR tR tR tV 3R ltRtV tR# )DOMHelpersTestsMixinz
A mixin for L{TestCase} subclasses which defines test methods for
domhelpers functionality based on a DOM creation function provided by a
subclass.
Nc                   V P                   P                  R 4      p\        P                  ! VR4      ^ ,          P                  pRpV P                  W#4       VP                  p\        P                  ! VR4      ^ ,          P                  pV P                  W#4       RpV P                   P                  V4      p\        P                  ! VR4      pRP                  V Uu. uF  qP                  R4      NK  	  up4      pRpV P                  W#4       VP                  p	\        P                  ! V	R4      pRP                  V Uu. uF  qP                  R4      NK  	  up4      pV P                  W#4       Rp
V P                   P                  V
4      p\        P                  ! VR4      pRP                  V Uu. uF  qP                  R4      NK  	  up4      pRpV P                  W#4       VP                  p\        P                  ! VR4      pRP                  V Uu. uF  qP                  R4      NK  	  up4      pV P                  W#4       RpV P                   P                  V4      p\        P                  ! VR4      pVP                  pWP                  R
,          P                  ^ ,          .pV P                  W#4       \        P                  ! VR4      pV P                  W#4       R	# u upi u upi u upi u upi )z<foo/>fooz<a><foo in="a"/><b><foo in="b"/></b><c><foo in="c"/></c><foo in="d"/><foo in="ef"/><g><foo in="g"/><h><foo in="h"/></h></g></a> inabcdefghaH  
<a><foo in="a"/>
    <b><foo in="b"/>
        <d><foo in="d"/>
            <g><foo in="g"/></g>
            <h><foo in="h"/></h>
        </d>
        <e><foo in="e"/>
            <i><foo in="i"/></i>
        </e>
    </b>
    <c><foo in="c"/>
        <f><foo in="f"/>
            <j><foo in="j"/></j>
        </f>
    </c>
</a>
abdgheicfjz'<foo><bar></bar><baz><foo/></baz></foo>N)
domparseStringr   getElementsByTagNamenodeNameassertEqualdocumentElementjoingetAttribute
childNodes)selfdoc1actualexpectedel1doc2_xmldoc2tag_listnodeel2doc3_xmldoc3el3doc4_xmldoc4roots   &               B/usr/lib/python3/dist-packages/twisted/web/test/test_domhelpers.pytest_getElementsByTagName.DOMHelpersTestsMixin.test_getElementsByTagName   s   xx##H-00u=a@II*""00e<Q?HH* Uxx##H-224?hGhd++D1hGH*""223>hGhd++D1hGH*" xx##H-224?hGhd++D1hGH*""223>hGhd++D1hGH*<xx##H-00u=##//"-88;<*00u=*U H
 H, H
 Hs   K.K38K8K=c                   V P                   P                  R 4      p\        P                  ! V4      pRpV P	                  W#4       \        P                  ! VP
                  4      pV P	                  W#4       RpV P                   P                  V4      p\        P                  ! V4      pRpV P	                  W#4       \        P                  ! VP
                  4      pV P	                  W#4       RpV P                   P                  V4      p\        P                  ! V4      pRpV P	                  W#4       \        P                  ! VP
                  4      pV P	                  W#4       R# )z
<a>foo</a>r   z+<a>a<b>b</b><c>c</c>def<g>g<h>h</h></g></a>r   r   NzP<a>a<b>b<d>d<g>g</g><h>h</h></d><e>e<i>i</i></e></b><c>c<f>f<j>j</j></f></c></a>r   r   r   gatherTextNodesr   r   )r   r   r   r   r    r!   r%   r&   s   &       r+   test_gatherTextNodes)DOMHelpersTestsMixin.test_gatherTextNodesQ   s$   xx##L1++D1*++D,@,@A*@xx##H-++D1*++D,@,@A*- 	 xx##H-++D1*++D,@,@A*    c                j   V P                   P                  R 4      pVP                  p\        P                  ! V4       V P                  VP                  4       VP                  R4      P                  4       4       V P                   P                  R 4      pVP                  P                  ^ ,          p\        P                  ! V4       VP                  P                  4       pVP                  R4      pVP                  VP                  R4      4       V P                  WVP                  4       4       R# )z<a><b><c><d/></c></b></a>abN)
r   r   r   r   	clearNoder   toxmlcreateElementr   appendChild)r   r   a_noder!   b_noder   r   s   &      r+   test_clearNode#DOMHelpersTestsMixin.test_clearNodel   s    xx##$?@%%V$););C)@)F)F)HIxx##$?@%%003V$%%++-%%c*T//45!12r3   c                t   V P                   P                  R 4      pV P                   P                  4       p\        P                  ! VR4      pVP                  4       pVP                  R4      pVP                  RR4       V P                  WEP                  4       4       \        P                  ! VR4      pVP                  4       pVP                  R4      pVP                  RR4       V P                  WEP                  4       4       V P                  \        P                  \        P                  VR4       R# )	$<a><b id="bar"/><c class="foo"/></a>r   cclassbarr6   idpzorkN)r   r   Documentr   getr8   r9   setAttributer   assertRaisesNodeLookupErrorr   r   docr#   r   r   s   &     r+   test_getDOMHelpersTestsMixin.test_getz   s    xx##$JKhh!~~dE*$$S)gu-!12~~dE*$$S)dE*!12*44jnndGTr3   c                   V P                   P                  R 4      pV P                   P                  4       p\        P                  ! VR4      pVP                  4       pVP                  R4      pVP                  RR4       V P                  WEP                  4       4       \        P                  ! VR4      pV P                  VR4       R# )r@   r   rA   rB   rE   N)
r   r   rF   r   getIfExistsr8   r9   rH   r   assertIdenticalrK   s   &     r+   test_getIfExists%DOMHelpersTestsMixin.test_getIfExists   s    xx##$JKhh!%%dE2$$S)gu-!12%%dG4T4(r3   c                B   V P                   P                  R 4      pV P                   P                  4       p\        P                  ! VR4      pVP                  4       pVP                  R4      pVP                  RR4       V P                  WEP                  4       4       R# )z<a><b id="foo"><c></c></b></a>r   r6   rD   N)	r   r   rF   r   getAndClearr8   r9   rH   r   rK   s   &     r+   test_getAndClear%DOMHelpersTestsMixin.test_getAndClear   s{    xx##$DEhh!%%dE2$$S)dE*!12r3   c                    V P                   P                  R 4      pV P                   P                  4       p\        P                  ! VP
                  RR^R7      pRP                  V Uu. uF  qDP                  4       NK  	  up4      pVP                  R4      pVP                  RR4       VP                  R4      pVP                  RR4       VP                  V4       V P                  WVP                  4       4       \        P                  ! VP
                  RR^ R7      pRP                  V Uu. uF  qDP                  4       NK  	  up4      pV P                  WVP                  4       VP                  4       ,           4       R# u upi u upi )z:<a><b foo="olive"><c foo="olive"/></b><d foo="poopy"/></a>r   olive)	noNestingr   r6   rA   N)r   r   rF   r   locateNodesr   r   r8   r9   rH   r:   r   )r   r   rL   	node_listr#   r   r   rA   s   &       r+   test_locateNodes%DOMHelpersTestsMixin.test_locateNodes   s0   xx##H
 hh!**4??E7VWX	9=94**,9=>$$S)eW-c"	ug&Q!12**4??E7VWX	9=94**,9=>!1AGGI!=> > >s   )F1Fc           	     z   V P                   P                  R 4      p\        P                  ! VP                  ^ ,          P                  ^ ,          P                  ^ ,          4      pRP                  V Uu. uF#  p\        VR4      '       g   K  VP                  NK%  	  up4      pV P                  VR4       R# u upi )z!<a><b><c><d/></c><e/></b><f/></a>r   tagNamecbaN)	r   r   r   
getParentsr   r   hasattrr`   r   r   r   r\   r#   r   s   &    r+   test_getParents$DOMHelpersTestsMixin.test_getParents   s    xx##$GH))OOA))!,77:
	 &/Lid743K\T\\iL
 	' Ms   4B8B8c                   V P                   P                  R 4      p\        P                  ! VR4      pRP	                  V Uu. uF  q3P
                  NK  	  up4      pV P                  VR4       \        P                  ! VRR4      pRP	                  V Uu. uF  q3P
                  NK  	  up4      pV P                  VR4       R# u upi u upi )z+<a foo="1"><b foo="2"/><c foo="1"/><d/></a>r   r   abc1acN)r   r   r   findElementsWithAttributer   r`   r   rd   s   &    r+   test_findElementsWithAttribute3DOMHelpersTestsMixin.test_findElementsWithAttribute   s    xx##$QR88uE	9=94,,9=>'88ucJ	9=94,,9=>& > >s   CC
c                    V P                   P                  R 4      p\        P                  ! VR4      p\	        V4      pV P                  V^4       R# )z#<doc><foo/><bar/><foo>a</foo></doc>r   N)r   r   r   findNodesNamedlenr   )r   r   r\   r   s   &   r+   test_findNodesNamed(DOMHelpersTestsMixin.test_findNodesNamed   sB    xx##$IJ--dE:	Y#r3   c                Z    R pRpV P                  \        P                  ! V4      V4       R# )z9this string " contains many & characters> xml< won't likezHthis string &quot; contains many &amp; characters&gt; xml&lt; won't likeN)r   r   escaper   jr   s   &  r+   test_escape DOMHelpersTestsMixin.test_escape   s,    HV 	 	**1-x8r3   c                Z    R pRpV P                  \        P                  ! V4      V4       R# )zTthis string &quot; has &&amp; entities &gt; &lt; and some characters xml won't like<zEthis string " has && entities > < and some characters xml won't like<N)r   r   unescaperu   s   &  r+   test_unescape"DOMHelpersTestsMixin.test_unescape   s,    bT 	 	,,Q/:r3   c                    V P                   P                  R4      pV P                  \        P                  ! V4      R4       R# )zd
L{getNodeText} returns the concatenation of all the text data at or
beneath the node passed to it.
z(<foo><bar>baz</bar><bar>quux</bar></foo>bazquuxN)r   r   r   r   getNodeText)r   r#   s   & r+   test_getNodeText%DOMHelpersTestsMixin.test_getNodeText   s4    
 xx##$NO//5yAr3   c                6   < V ^8  d   Qh/ S[ S[,          ;R&   # )   r   )r   r   )format__classdict__s   "r+   __annotate__!DOMHelpersTestsMixin.__annotate__   s      
# r3    )__name__
__module____qualname____firstlineno____doc__r   r,   r1   r=   rM   rR   rV   r]   re   rl   rq   rw   r{   r   __annotate_func____static_attributes____classdictcell__r   s   @r+   r
   r
      s]      C6+p+63U"
)3?&('$9;BW  r3   r
   c                   6   a  ] tR t^t o ]tR tR tR tRt	V t
R# )MicroDOMHelpersTestsc                    RpV P                   P                  V4      p\        P                  ! V4      pRpV P	                  W44       \        P                  ! VP
                  4      pV P	                  W44       R# )z
Microdom discards whitespace-only text nodes, so L{gatherTextNodes}
returns only the text from nodes which had non-whitespace characters.
z?<html>
  <head>
  </head>
  <body>
    stuff
  </body>
</html>
z
    stuff
  Nr/   )r   r(   r)   r   r   s   &    r+   #test_gatherTextNodesDropsWhitespace8MicroDOMHelpersTests.test_gatherTextNodesDropsWhitespace   sf    
 xx##H-++D1$*++D,@,@A*r3   c                    RpV P                   P                  V4      p\        P                  ! V4      pRpV P	                  W44       \        P                  ! VP
                  4      pV P	                  W44       R# )z2
Microdom does not decode entities in text nodes.
<x>Souffl&amp;</x>zSouffl&amp;Nr/   r   doc5_xmldoc5r   r   s   &    r+   test_textEntitiesNotDecoded0MicroDOMHelpersTests.test_textEntitiesNotDecoded   sd     (xx##H-++D1 *++D,@,@A*r3   c                    \        \        4       V P                  V P                  .4      pV P	                  ^\        V4      4       V P	                  RV^ ,          R,          4       R# )z/
An import will raise the deprecation warning.
z8twisted.web.domhelpers was deprecated at Twisted 23.10.0messageN)r   r   flushWarningstest_deprecationr   rp   )r   warningss   & r+   r   %MicroDOMHelpersTests.test_deprecation  sV     	z%%t'<'<&=>CM*FQK	"	
r3   r   N)r   r   r   r   r   r   r   r   r   r   r   r   s   @r+   r   r      s     
C+(
+

 

r3   r   c                   0   a  ] tR tRt o ]tR tR tRtV t	R# )MiniDOMHelpersTestsi  c                    RpV P                   P                  V4      p\        P                  ! V4      pRpV P	                  W44       \        P                  ! VP
                  4      pV P	                  W44       R# )z-
Minidom does decode entities in text nodes.
r   zSouffl&Nr/   r   s   &    r+   test_textEntitiesDecoded,MiniDOMHelpersTests.test_textEntitiesDecoded  sd     (xx##H-++D1*++D,@,@A*r3   c                   V P                   P                  R4      p\        P                  ! V4      pV P	                  VR4       V P                  V\        4       V P                   P                  RP                  4       4      p\        P                  ! V4      pV P	                  VR4       V P                  V\        4       R# )z
L{domhelpers.getNodeText} returns a C{unicode} string when text
nodes are represented in the DOM with unicode, whether or not there
are non-ASCII characters present.
z<foo>bar</foo>rC   u   <foo>☃</foo>u   ☃N)r   r   r   r   r   assertIsInstancestrencode)r   r#   texts   &  r+   test_getNodeUnicodeText+MiniDOMHelpersTests.test_getNodeUnicodeText#  s     xx##$45%%d+u%dC(xx##$<$C$C$EF%%d+}-dC(r3   r   N)
r   r   r   r   r   r   r   r   r   r   r   s   @r+   r   r     s     
C
+) )r3   r   N)r   	importlibr   typingr   r   xml.domr   twisted.trial.unittestr   twisted.webr   r   r
   r   r   r   r3   r+   <module>r      sI   
     + ,QB QBh-
/ -
`). )r3   