+
    Dfj,h                        R t ^ RIt^ RIt^ RIt^ RIHt ^ RIHt ^ RIH	t	 ^ RI
HtHtHtHtHtHtHt ^ RIHt ^ RIHt ^ RIHtHt ^ R	IHtHtHtHtHt ^ R
IH t  ^ RI!H"t" ^ RI#H$t$ ^ RI%H&t& ^ RI'H(t(H)t)H*t* ^ RI+H,t,H-t-H.t. ^ RI/H0t0H1t1H2t2H3t3H4t4H5t5H6t6H7t7H8t8H9t9H:t:H;t; ^ RI<H=t= ]P|                  R,          R8  t? ! R R]=]"4      t@ ! R R]$4      tAR P                  P                  tD ! R R]$4      tER# )zf
Tests for the flattening portion of L{twisted.web.template}, implemented in
L{twisted.web._flatten}.
N)OrderedDictdedent)FunctionType)CallableDictListNoReturnOptionalTuplecast)XML)implementer)assert_thatequal_to)CancelledErrorDeferredgatherResultspassthrusucceedFailure)XMLAssertionMixin)SynchronousTestCase)BUFFER_SIZE)FlattenerErrorUnfilledSlotUnsupportedType)IRenderableIRequestITemplateLoader)CDATACharRefCommentElementFlattenableTag	TagLoaderflattenflattenStringrendererslottags)FlattenTestCase:N   Nc                   @  a  ] tR t^6t o RtV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR	 ltV 3R
 lR lt	V 3R lR lt
V 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R  lR! ltV 3R" lR# ltV 3R$ lR% ltV 3R& lR' ltV 3R( lR) ltV 3R* lR+ ltV 3R, lR- ltV 3R. lR/ ltV 3R0 lR1 ltV 3R2 lR3 ltV 3R4 lR5 ltV 3R6 lR7 ltV 3R8 lR9 lt V 3R: lR; lt!V 3R< lR= lt"R>t#V t$R?# )@SerializationTestsz&
Tests for flattening various things.
c                   < V ^8  d   QhRR/# r.   returnN )format__classdict__s   "?/usr/lib/python3/dist-packages/twisted/web/test/test_flatten.py__annotate__SerializationTests.__annotate__;   s     
 
 
    c                ~    V P                  \        P                  ! \        P                  ! R4      RR7      R4       R# )z*
Test that nested tags flatten correctly.
42there)his'   <html hi="there"><body>42</body></html>N)assertFlattensImmediatelyr,   htmlbodyselfs   &r7   test_nestedTags"SerializationTests.test_nestedTags;   s+     	&&IIdiio'26	
r:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   r9   D   s     S Sd Sr:   c                R    V P                  RR4      3 V P                  RR4      3 R# )z<
Test that strings will be flattened and escaped correctly.
ones   onez
<abc&&>123s   &lt;abc&amp;&amp;&gt;123N)r?   rB   s   &r7   test_serializeString'SerializationTests.test_serializeStringD   s+     	&&uf56&&|5PQRr:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   r9   K   s     ? ?t ?r:   c                P    V P                  \        P                  ! 4       R4       R# )z@
The serialized form of a self-closing tag is C{'<tagName />'}.
s   <img />Nr?   r,   imgrB   s   &r7   test_serializeSelfClosingTags0SerializationTests.test_serializeSelfClosingTagsK   s     	&&txxz:>r:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   r9   Q   s     R R Rr:   c                T    V P                  \        P                  ! RR7      R4       R# )zF
The serialized form of attribute I{a} with value I{b} is C{'a="b"'}.
foosrcs   <img src="foo" />NrM   rB   s   &r7   test_serializeAttribute*SerializationTests.test_serializeAttributeQ   s     	&&txxE':<PQr:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   r9   W   s     M M4 Mr:   c                x    \         P                  ! 4       p\        RR.4      Vn        V P	                  VR4       R# )zO
Multiple attributes are separated by a single space in their serialized
form.
s   <img src="foo" name="bar" />N)rU   rS   )namebar)r,   rN   r   
attributesr?   rC   tags   & r7   !test_serializedMultipleAttributes4SerializationTests.test_serializedMultipleAttributesW   s1    
 hhj$no%FG&&s,KLr:   c                Z   < V ^8  d   QhRS[ S[.S[3,          RS[ S[.S[3,          RR/# )r.   wrapDatawrapTagr3   N)r   strr%   r&   )r5   r6   s   "r7   r8   r9   `   sA     
 
C5+-.
 3%,-
 
	
r:   c           	     l    V P                  V! \        P                  ! V! R4      R7      4      R4       R# )a  
Common implementation of L{test_serializedAttributeWithSanitization}
and L{test_serializedDeferredAttributeWithSanitization},
L{test_serializedAttributeWithTransparentTag}.

@param wrapData: A 1-argument callable that wraps around the
    attribute's value so other tests can customize it.

@param wrapTag: A 1-argument callable that wraps around the outer tag
    so other tests can customize it.
<>&"rT   s!   <img src="&lt;&gt;&amp;&quot;" />NrM   )rC   rb   rc   s   &&&r7   checkAttributeSanitization-SerializationTests.checkAttributeSanitization`   s+      	&&DHH&!1230	
r:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   r9   u   s     < <$ <r:   c                :    V P                  \        \        4       R# )z
Attribute values containing C{"<"}, C{">"}, C{"&"}, or C{'"'} have
C{"&lt;"}, C{"&gt;"}, C{"&amp;"}, or C{"&quot;"} substituted for those
bytes in the serialized output.
N)rg   r   rB   s   &r7   (test_serializedAttributeWithSanitization;SerializationTests.test_serializedAttributeWithSanitizationu   s     	''(;r:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   r9   }   s     ; ;$ ;r:   c                :    V P                  \        \        4       R# )z
Like L{test_serializedAttributeWithSanitization}, but when the contents
of the attribute are in a L{Deferred
<twisted.internet.defer.Deferred>}.
N)rg   r   r   rB   s   &r7   0test_serializedDeferredAttributeWithSanitizationCSerializationTests.test_serializedDeferredAttributeWithSanitization}   s     	'':r:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   r9      s     > >$ >r:   c                R   a . oR V3R llpR V3R llpV P                  W4       R# )zC
Like L{test_serializedAttributeWithSanitization} but with a slot.
c                0    V ^8  d   QhR\         R\        /# r.   valuer3   rd   r%   )r5   s   "r7   r8   YSerializationTests.test_serializedAttributeWithSlotWithSanitization.<locals>.__annotate__   s     	! 	!c 	!k 	!r:   c                 <   < SP                  V 4       \        R 4      # stuff)appendr+   ru   tosss   &r7   
insertSlotWSerializationTests.test_serializedAttributeWithSlotWithSanitization.<locals>.insertSlot   s    KK= r:   c                0    V ^8  d   QhR\         R\         /# r.   r^   r3   )r&   )r5   s   "r7   r8   rw      s     	3 	3# 	3# 	3r:   c                 D   < V P                  SP                  4       R 7      # )ry   )	fillSlotspop)r^   r}   s   &r7   fillSlotUSerializationTests.test_serializedAttributeWithSlotWithSanitization.<locals>.fillSlot   s    ==txxz=22r:   N)rg   )rC   r~   r   r}   s   &  @r7   0test_serializedAttributeWithSlotWithSanitizationCSerializationTests.test_serializedAttributeWithSlotWithSanitization   s.     	! 	!	3 	3 	''
=r:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   r9      s     D DD Dr:   c                N    V P                  \        P                  \        4       R# )z
Attribute values which are supplied via the value of a C{t:transparent}
tag have the same substitution rules to them as values supplied
directly.
N)rg   r,   transparentr   rB   s   &r7   *test_serializedAttributeWithTransparentTag=SerializationTests.test_serializedAttributeWithTransparentTag   s     	''(8(8(Cr:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   r9      s     @ @ @r:   c                t   aa  ! R R\         4      o. oR V3R llpR VV3R llpV P                  W4       R# )zu
Like L{test_serializedAttributeWithTransparentTag}, but when the
attribute is rendered by a renderer on an element.
c                   Z   a a ] tR t^t oV3R lV 3R llt]V3R lR l4       tRtVtV ;t	# )_SerializationTests.test_serializedAttributeWithTransparentTagWithRenderer.<locals>.WithRendererc                :   < V ^8  d   QhRS[ RS[S[,          RR/# )r.   ru   loaderr3   N)rd   r
   r    )r5   r6   s   "r7   r8   lSerializationTests.test_serializedAttributeWithTransparentTagWithRenderer.<locals>.WithRenderer.__annotate__   s(     ) )c )8O3L )QU )r:   c                2   < Wn         \        SV `	  V4       R # N)ru   super__init__)rC   ru   r   	__class__s   &&&r7   r   hSerializationTests.test_serializedAttributeWithTransparentTagWithRenderer.<locals>.WithRenderer.__init__   s    "
 (r:   c                <   < V ^8  d   QhRS[ S[,          RS[RS[/# )r.   requestr^   r3   )r
   r   r&   r%   )r5   r6   s   "r7   r8   r      s'     " "Xh%7 "c "k "r:   c                    V P                   # r   ru   )rC   r   r^   s   &&&r7   rz   eSerializationTests.test_serializedAttributeWithTransparentTagWithRenderer.<locals>.WithRenderer.stuff   s    zz!r:   r   )
__name__
__module____qualname____firstlineno__r   r*   rz   __static_attributes____classdictcell____classcell__)r   r6   s   @@r7   WithRendererr      s(     ) ) " " "r:   r   c                0    V ^8  d   QhR\         R\        /# rt   rv   )r5   s   "r7   r8   _SerializationTests.test_serializedAttributeWithTransparentTagWithRenderer.<locals>.__annotate__   s     	4 	4# 	4+ 	4r:   c                 T   < SP                  V 4       \        P                  ! R R7      # )rz   render)r{   r,   r   r|   s   &r7   insertRendereraSerializationTests.test_serializedAttributeWithTransparentTagWithRenderer.<locals>.insertRenderer   s     KK##733r:   c                0    V ^8  d   QhR\         R\        /# r   )r&   r%   )r5   s   "r7   r8   r      s     	< 	< 	< 	<r:   c                 D   < S! SP                  4       \        V 4      4      # r   )r   r'   )r^   r   r}   s   &r7   r   YSerializationTests.test_serializedAttributeWithTransparentTagWithRenderer.<locals>.render   s    
IcN;;r:   N)r$   rg   )rC   r   r   r   r}   s   &  @@r7   6test_serializedAttributeWithTransparentTagWithRendererISerializationTests.test_serializedAttributeWithTransparentTagWithRenderer   s:    	"7 	" 	4 	4	< 	< 	''?r:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   r9      s     = = =r:   c                j    \        \        4       ! R R4      4       pV P                  V\        4       R# )z
Like L{test_serializedAttributeWithTransparentTag}, but when the
attribute is a provider of L{IRenderable} rather than a transparent
tag.
c                   V   a  ] tR t^t o V 3R lR ltV 3R lR ltV 3R lR ltRtV tR# )	LSerializationTests.test_serializedAttributeWithRenderable.<locals>.Arbitraryc                $   < V ^8  d   QhRS[ RR/# )r.   ru   r3   N)r%   )r5   r6   s   "r7   r8   YSerializationTests.test_serializedAttributeWithRenderable.<locals>.Arbitrary.__annotate__   s     # #k #d #r:   c                    Wn         R # r   r   )rC   ru   s   &&r7   r   USerializationTests.test_serializedAttributeWithRenderable.<locals>.Arbitrary.__init__   s    "
r:   c                6   < V ^8  d   QhRS[ S[,          RS[/# r.   r   r3   r
   r   r%   )r5   r6   s   "r7   r8   r      s      " "hx&8 "[ "r:   c                    V P                   # r   r   )rC   r   s   &&r7   r   SSerializationTests.test_serializedAttributeWithRenderable.<locals>.Arbitrary.render   s    zz!r:   c                R   < V ^8  d   QhRS[ RS[S[S[,          S[.S[3,          /# r.   rZ   r3   rd   r   r
   r   r&   r%   )r5   r6   s   "r7   r8   r      s1     = ==8H-s3[@A=r:   c                    \        R 4      h)zUnexpected call)NotImplementedErrorrC   rZ   s   &&r7   lookupRenderMethod_SerializationTests.test_serializedAttributeWithRenderable.<locals>.Arbitrary.lookupRenderMethod   s     **;<<r:   r   N)	r   r   r   r   r   r   r   r   r   r6   s   @r7   	Arbitraryr      s#     # #" "= =r:   r   N)r   r   rg   r   )rC   r   s   & r7   &test_serializedAttributeWithRenderable9SerializationTests.test_serializedAttributeWithRenderable   s2     
[	!
	= 
	= 
"
	= 	''	8<r:   c                <   < V ^8  d   QhRS[ S[.S[3,          RR/# )r.   rc   r3   N)r   r&   r%   )r5   r6   s   "r7   r8   r9      s)     = ={ 23=	=r:   c                   \         P                  ! R4      p\         P                  ! V! V4      R7      pV P                  VR4      pV P                  VR4      pV P	                  \        V4      P                  R,          V4       R# )a/  
Common implementation of L{test_serializedAttributeWithTag} and
L{test_serializedAttributeWithDeferredTag}.

@param wrapTag: A 1-argument callable that wraps around the attribute's
    value so other tests can customize it.
@type wrapTag: callable taking L{Tag} and returning something
    flattenable
rf   rT   s@   <img src="&lt;a&gt;&amp;lt;&amp;gt;&amp;amp;&quot;&lt;/a&gt;" />s   <a>&lt;&gt;&amp;"</a>rU   N)r,   arN   r?   assertXMLEqualr   attrib)rC   rc   innerTagouterTagouterinners   &&    r7   checkTagAttributeSerialization1SerializationTests.checkTagAttributeSerialization   sp     66&>88 12..O
 ..x9QR 	CJ--e4e<r:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   r9      s     6 6 6r:   c                0    V P                  \        4       R# )z
L{Tag} objects which are serialized within the context of an attribute
are serialized such that the text content of the attribute may be
parsed to retrieve the tag.
N)r   r   rB   s   &r7   test_serializedAttributeWithTag2SerializationTests.test_serializedAttributeWithTag   s     	++H5r:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   r9      s     5 5 5r:   c                0    V P                  \        4       R# )zu
Like L{test_serializedAttributeWithTag}, but when the L{Tag} is in a
L{Deferred <twisted.internet.defer.Deferred>}.
N)r   r   rB   s   &r7   'test_serializedAttributeWithDeferredTag:SerializationTests.test_serializedAttributeWithDeferredTag   s    
 	++G4r:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   r9      s     
 
d 
r:   c                    V P                  \        P                  ! \        P                  ! RR7      R7      R4      pV P	                  \        V4      P                  R,          R4       R# )z
Similar to L{test_serializedAttributeWithTag}, but for the additional
complexity where the tag which is the attribute value itself has an
attribute value which contains bytes which require substitution.
rf   )hrefrT   sV   <img src="&lt;a href=&quot;&amp;lt;&amp;gt;&amp;amp;&amp;quot;&quot;&gt;&lt;/a&gt;" />rU   s"   <a href="&lt;&gt;&amp;&quot;"></a>N)r?   r,   rN   r   r   r   r   )rC   	flatteneds   & r7   ,test_serializedAttributeWithTagWithAttribute?SerializationTests.test_serializedAttributeWithTagWithAttribute   sS     22HHV,-
	 		N!!%(*O	
r:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   r9     s     N Nt Nr:   c                <    V P                  \        R4      R4       R# )z9
Test that comments are correctly flattened and escaped.
foo bars   <!--foo bar-->N)r?   r#   rB   s   &r7   test_serializeComment(SerializationTests.test_serializeComment  s     	&&wy'9;LMr:   c                @   < V ^8  d   QhRS[ S[S[,          ,          /# r.   r3   )r   r   bytes)r5   r6   s   "r7   r8   r9     s     '& '&htE{&; '&r:   c                   a  R V 3R llp. pR F:  p\        R\        V4      4      pVP                  V4       VP                  V4       K<  	  \	        V4      # )a  
The data in a L{Comment} is escaped and mangled in the flattened output
so that the result can be safely included in an HTML document.

Test that C{>} is escaped when the sequence C{-->} is encountered
within a comment, and that comments do not end with C{-}.
c                (    V ^8  d   QhR\         RR/# )r.   cr3   N)r   )r5   s   "r7   r8   =SerializationTests.test_commentEscaping.<locals>.__annotate__  s     	7 	7U 	7t 	7r:   c                   < SP                  V P                  R 4      V : R24       SP                  V P                  R4      V : R24       SP                  \        V 4      ^8  V : R24       V ^R	 pRV9   d   SP	                  RV4       MSP                  RV4       V'       d   SP                  VR
,          R4       R# R# )s   <!--z' does not start with the comment prefixs   -->z% does not end with the comment suffixz# is too short to be a legal comments   foo   >   -N)
assertTrue
startswithendswithlenassertInassertNotInassertNotEqual)r   contentrC   s   & r7   verifyComment>SerializationTests.test_commentEscaping.<locals>.verifyComment  s    OOW%%>? OO

6"%<= OOCFaKA50S)TU"gG dG,  w/##GBK6 r:   N) z	foo > barzabracadabra-znot-->magic)r)   r#   addCallbackr{   r   )rC   r   resultsr   ds   f    r7   test_commentEscaping'SerializationTests.test_commentEscaping  sW    	7 	7( 
A dGAJ/AMM-(NN1
 W%%r:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   r9   6  s     
 
T 
r:   c                t    V P                  \        R4      R4      3 V P                  \        R4      R4       R# )z5
Test that CDATA is correctly flattened and escaped.
r   s   <![CDATA[foo bar]]>zfoo ]]> bars#   <![CDATA[foo ]]]]><![CDATA[> bar]]>N)r?   r!   rB   s   &r7   test_serializeCDATA&SerializationTests.test_serializeCDATA6  s6     	&&uY'79OPQ&&- "H	
r:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   r9   ?  s     
 
t 
r:   c                j   RpV P                  VR4       V P                  \        P                  ! V4      R4       V P                  \        V4      R4       V P                  \	        V4      R4       V P                  \        V4      \        4       V P                  \        RVR/R7      \        4       R	# )
z~
Test that unicode is encoded correctly in the appropriate places, and
raises an error when it occurs in inappropriate place.
   ☃s   ☃s
   <p>☃</p>s
   <!--☃-->s   <![CDATA[☃]]>pr  )r\   N)r?   r,   r  r#   r!   assertFlatteningRaisesr&   UnicodeEncodeError)rC   snowmans   & r7   test_serializeUnicode(SerializationTests.test_serializeUnicode?  s    
  &&w@&&tvvg8NO&&ww'79OP&&uW~7RS##CL2DE##".0B	
r:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   r9   N  s     8 8t 8r:   c                R    \        \        R4      4      pV P                  VR4       R# )zM
A character reference is flattened to a string using the I{&#NNNN;}
syntax.
r  s   &#9731;N)r"   ordr?   )rC   refs   & r7   test_serializeCharRef(SerializationTests.test_serializeCharRefN  s#    
 c-()&&sJ7r:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   r9   V  s     ? ? ?r:   c                <    V P                  \        R4      R4       R# )zb
Test that a deferred is substituted with the current value in the
callback chain when flattened.
twos   twoN)r?   r   rB   s   &r7   test_serializeDeferred)SerializationTests.test_serializeDeferredV  s    
 	&&wu~v>r:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   r9   ]  s     4 4 4r:   c                d    \        R4      pV P                  VR4       V P                  VR4       R# )z5
Test that the same deferred can be flattened twice.
threes   threeN)r   r?   )rC   r  s   & r7   test_serializeSameDeferredTwice2SerializationTests.test_serializeSameDeferredTwice]  s.     G&&q(3&&q(3r:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   r9   e  s     > > >r:   c                |    ^ RI Hp / p\        V! R4      V4       VR,          pV P                  V! R4      R4       R# )z\
Test that a coroutine returning a value is substituted with the that
value when flattened.
r   zE
            async def coro(x):
                return x
            corofour   fourN)textwrapr   execr?   rC   r   	namespacer&  s   &   r7   test_serializeCoroutine*SerializationTests.test_serializeCoroutinee  sF    
 	$-/	 	
  &&tF|W=r:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   r9   z  s     > >$ >r:   c                    ^ RI Hp \        \        R7      p\	        V! R4      V4       VR,          pV P                  V! R4      R4       R# )zj
Test that a coroutine returning an awaited deferred value is
substituted with that value when flattened.
r   r   zT
            async def coro(x):
                return await succeed(x)
            r&  r'  r(  N)r)  r   dictr   r*  r?   r+  s   &   r7    test_serializeCoroutineWithAwait3SerializationTests.test_serializeCoroutineWithAwaitz  sK    
 	$)	 	
  &&tF|W=r:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   r9     s     V V4 Vr:   c                t   a  \        \        4       ! V 3R lR4      4       pS P                  V! 4       R4       R# )zA
Test that flattening respects all of the IRenderable interface.
c                   L   <a  ] tR tRt o V 3R lR ltV 3R lV3R lltRtV tR# )ASerializationTests.test_serializeIRenderable.<locals>.FakeElementi  c                &   < V ^8  d   QhRS[ RS[/# )r.   oredr3   )objectr&   )r5   r6   s   "r7   r8   NSerializationTests.test_serializeIRenderable.<locals>.FakeElement.__annotate__  s      & S r:   c           	         \         P                  ! R \         P                  ! RR7      R\         P                  ! RR7      4      # )zhello, testr   z - )r,   r  r   )ignr:  s   &&r7   r   HSerializationTests.test_serializeIRenderable.<locals>.FakeElement.render  s5    vv$$F3$$F3	 r:   c                R   < V ^8  d   QhRS[ RS[S[S[,          S[.S[3,          /# r   r   )r5   r6   s   "r7   r8   r<    s1     7 778H-s3[@A7r:   c                .   < SP                  VR 4       R # )r>  c                     V! R 4      # )worldr4   )r?  nodes   &&r7   <lambda>fSerializationTests.test_serializeIRenderable.<locals>.FakeElement.lookupRenderMethod.<locals>.<lambda>  s    gr:   )assertEqual)r?  rZ   rC   s   &&r7   r   TSerializationTests.test_serializeIRenderable.<locals>.FakeElement.lookupRenderMethod  s       v.66r:   r4   N)r   r   r   r   r   r   r   r   )r6   rC   s   @r7   FakeElementr8    s      7 7 7r:   rJ  s   <p>hello, world - world</p>N)r   r   r?   )rC   rJ  s   f r7   test_serializeIRenderable,SerializationTests.test_serializeIRenderable  s6    
 
[	!	7 	7 
"	7 	&&{}6TUr:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   r9     s     Q QD Qr:   c                \    V P                  \        P                  ! RR7      \        4       R# )z
Test that flattening a tag with a C{render} attribute when no render
factory is available in the context raises an exception.
r>  r   N)r  r,   r   
ValueErrorrB   s   &r7   "test_serializeMissingRenderFactory5SerializationTests.test_serializeMissingRenderFactory  s     	##D$4$4F$CZPr:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   r9     s     C CT Cr:   c                    \         P                  ! \        R4      4      pVP                  4       pVP	                  RR7       V P                  V\        4       V P                  VR4       R# )zC
Test that flattening a slot will use the slot value from the tag.
r>  zhello, worldr>  s   <p>hello, world</p>N)r,   r  r+   cloner   r  r   r?   )rC   t1t2s   &  r7   test_serializeSlots&SerializationTests.test_serializeSlots  sP     VVDL!XXZ
.)##B5&&r+ABr:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   r9     s     G GT Gr:   c                    \         P                  ! \        R4      4      pVP                  \	        \         P
                  ! R4      4      R7       V P                  VR4       R# )zd
Test that a slot with a deferred as its value will be flattened using
the value from the deferred.
r>  zfour>rT  s   <p><em>four&gt;</em></p>N)r,   r  r+   r   r   emr?   )rC   ts   & r7   test_serializeDeferredSlots.SerializationTests.test_serializeDeferredSlots  sC    
 FF4< 	!123&&q*EFr:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   r9     s     ; ; ;r:   c                2    V P                  R\        4       R# )zD
Test that flattening an unknown type of thing raises an exception.
N)r  r   rB   s   &r7   test_unknownTypeRaises)SerializationTests.test_unknownTypeRaises  s     	##D/:r:   r4   N)%r   r   r   r   __doc__rD   rI   rO   rV   r_   rg   rk   ro   r   r   r   r   r   r   r   r   r   r  r	  r  r  r  r"  r-  r3  rK  rP  rX  r^  rb  r   r   r   s   @r7   r0   r0   6   sK    
 
S S? ?R RM M
 
*< <; ;> >D D@ @4= =,= =46 65 5
 
$N N'& '&R
 

 
8 8? ?4 4> >*> >*V V.Q QC CG G; ;r:   r0   c                   ~   a  ] tR tRt o RtV 3R lR ltV 3R lR ltV 3R lR ltV 3R	 lR
 ltV 3R lR lt	Rt
V tR# )FlattenChunkingTestsi  z]
Tests for the way pieces of the result are chunked together in calls to
the write function.
c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   !FlattenChunkingTests.__annotate__  s     0 0D 0r:   c                    . pV P                  \        R. ROVP                  4      4       \        V\	        R.4      4       R# )z
If the entire value to be flattened is available synchronously and fits
into the buffer it is all passed to a single call to the write
function.
Ns   123)123)successResultOfr(   r{   r   r   )rC   outputs   & r7   test_oneSmallChunk'FlattenChunkingTests.test_oneSmallChunk  s5     !WT?FMMJKFHfX./r:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   rh    s     
 
d 
r:   c           	         R.\         ,          pR.\         ,          pR.\         ,          p. pV P                  \        RWV.VP                  4      4       \	        V\        R\         ,          R\         ,          R\         ,          .4      4       R# )z
If the entire value to be flattened is available synchronously but does
not fit into the buffer then it is chunked into buffer-sized pieces
and these are passed to the write function.
xyzN   x   y   z)r   rm  r(   r{   r   r   )rC   somesomeMoreevenMorern  s   &    r7   test_someLargeChunks)FlattenChunkingTests.test_someLargeChunks  sv     u{"5;&5;& WTDH+Ev}}UVd[($*<d[>PQR	
r:   c                v   < V ^8  d   QhRS[ S[.S[S[S[,          S[ . S[3,          3,          3,          RR/# )r.   startr3   N)r   r%   r   r   r;  )r5   r6   s   "r7   r8   rh    sF     -
 -
M5+!6V8L!LMM
-

 
-
r:   c                    V! R4      w  r#V! R4      w  rERRVRRVRR.p. p\        RWgP                  4      pV! 4        V! 4        V P                  V4       \        V\	        . R	O4      4       R# )
a  
Assert that flattening with a L{Deferred} returned by C{start} results
in the expected buffering behavior.

The L{Deferred} need not have a result by it is returned by C{start}
but must have a result after the callable returned along with it is
called.

The expected buffering behavior is that flattened values up to the
L{Deferred} are written together and then the result of the
L{Deferred} is written together with values following it up to the
next L{Deferred}.
zfirst-zsecond-zalready-availablez-chunkszchunks-already-computedzmore-chunks-N)s   already-available-chunkss   first-chunks-already-computeds$   second-more-chunks-already-available)r(   r{   rm  r   r   )	rC   r  
first_waitfirst_finishsecond_waitsecond_finishru   rn  r  s	   &&       r7   _chunksSeparatedByAsyncTest0FlattenChunkingTests._chunksSeparatedByAsyncTest  s    & $)? 
%*9%5"	
 !D%/Q		
r:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   rh    s     5 5T 5r:   c                4    R R lpV P                  V4       R# )a^  
When a fired L{Deferred} is encountered any buffered data is
passed to the write function.  Then the L{Deferred}'s result is passed
to another write along with following synchronous values.

This exact buffering behavior should be considered an implementation
detail and can be replaced by some other better behavior in the future
if someone wants.
c                z    V ^8  d   QhR\         R\        \        \         ,          \        . R3,          3,          /# r.   vr3   Nr%   r   r   r   )r5   s   "r7   r8   NFlattenChunkingTests.test_chunksSeparatedByFiredDeferred.<locals>.__annotate__#  s4     	. 	.	.8K((2t8*<<=	.r:   c                     \        V 4      R  3# )c                      R # r   r4   r4   r:   r7   rF  ^FlattenChunkingTests.test_chunksSeparatedByFiredDeferred.<locals>.sync_start.<locals>.<lambda>&  s    r:   r1  )r  s   &r7   
sync_startLFlattenChunkingTests.test_chunksSeparatedByFiredDeferred.<locals>.sync_start#  s     AJ--r:   Nr  )rC   r  s   & r7   #test_chunksSeparatedByFiredDeferred8FlattenChunkingTests.test_chunksSeparatedByFiredDeferred  s    	.
 	((4r:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   rh  *  s     6 6t 6r:   c                4    R R lpV P                  V4       R# )z
When an unfired L{Deferred} is encountered any buffered data is
passed to the write function.  After the result of the L{Deferred} is
available it is passed to another write along with following
synchronous values.
c                z    V ^8  d   QhR\         R\        \        \         ,          \        . R3,          3,          /# r  r  )r5   s   "r7   r8   PFlattenChunkingTests.test_chunksSeparatedByUnfiredDeferred.<locals>.__annotate__2  s4     	. 	.	.8K((2t8*<<=	.r:   c                 ,   a a \        4       oSVV 3R  l3# )c                  &   < S P                  S4      # r   )callback)r  r  s   r7   rF  aFlattenChunkingTests.test_chunksSeparatedByUnfiredDeferred.<locals>.async_start.<locals>.<lambda>6  s    qzz!}r:   )r   )r  r  s   f@r7   async_startOFlattenChunkingTests.test_chunksSeparatedByUnfiredDeferred.<locals>.async_start2  s     (0zA,--r:   Nr  )rC   r  s   & r7   %test_chunksSeparatedByUnfiredDeferred:FlattenChunkingTests.test_chunksSeparatedByUnfiredDeferred*  s    	. 	((5r:   r4   N)r   r   r   r   rd  ro  r|  r  r  r  r   r   r   s   @r7   rf  rf    s=     
0 0
 
"-
 -
^5 5$6 6r:   rf  c                      R # r   r4   r4   r:   r7   rF  rF  C  s    r:   c                      a  ] tR tRt o RtV 3R lR ltV 3R lR ltV 3R lR ltV 3R	 lR
 ltV 3R lR lt	V 3R lR lt
RtV tR# )FlattenerErrorTestsiF  z
Tests for L{FlattenerError}.
c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8    FlattenerErrorTests.__annotate__K  s     
 
 
r:   c           	         \        \        4       ! R R4      4       pV P                  \        \	        \        R4      V! 4       .. 4      4      R4       R# )z
If a L{FlattenerError} is created with an L{IRenderable} provider root,
the repr of that object is included in the string representation of the
exception.
c                   2   a  ] tR tRt o V 3R lR ltRtV tR# )7FlattenerErrorTests.test_renderable.<locals>.RenderableiR  c                    < V ^8  d   QhRS[ /# r   rd   )r5   r6   s   "r7   r8   DFlattenerErrorTests.test_renderable.<locals>.Renderable.__annotate__T  s     ) )# )r:   c                    R # )zrenderable reprr4   rB   s   &r7   __repr__@FlattenerErrorTests.test_renderable.<locals>.Renderable.__repr__T  s    (r:   r4   N)r   r   r   r   r  r   r   r   s   @r7   
Renderabler  R  s     ) )r:   r  reasonzCException while flattening:
  renderable repr
RuntimeError: reason
N)r   r   rH  rd   r   RuntimeError)rC   r  s   & r7   test_renderable#FlattenerErrorTests.test_renderableK  sO     
[	!	) 	) 
"	) 	|H5
~rJK%	
r:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   r  ^  s     
 
$ 
r:   c           	         \        RR^^R7      pV P                  \        \        \	        R4      V.. 4      4      R4       R# )z
If a L{FlattenerError} is created with a L{Tag} instance with source
location information, the source location is included in the string
representation of the exception.
divz/foo/filename.xhtml)filename
lineNumbercolumnNumberr  zlException while flattening:
  File "/foo/filename.xhtml", line 17, column 12, in "div"
RuntimeError: reason
N)r&   rH  rd   r   r  r]   s   & r7   test_tagFlattenerErrorTests.test_tag^  sA     %"7BUWX|H5ubAB%	
r:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   r  m  s     	
 	
 	
r:   c           
     x    V P                  \        \        \        R4      \	        R4      .. 4      4      R4       R# )z
If a L{FlattenerError} is created with a L{Tag} instance without source
location information, only the tagName is included in the string
representation of the exception.
r  spanz>Exception while flattening:
  Tag <span>
RuntimeError: reason
N)rH  rd   r   r  r&   rB   s   &r7   test_tagWithoutLocation+FlattenerErrorTests.test_tagWithoutLocationm  s1     	|H5F}bIJU	
r:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   r  x  s     ,
 ,
 ,
r:   c           
       a R V3R llpR R lo V! 4        V P                  R4       \        '       d   RpMR	pV P                  \        \        X. X4      4      R
\        VP                  P                  ^,           V\        SP                  P                  ^,           3,          4       R#   \         dD   p\        P                  ! \        P
                  ! 4       ^,          4      R,          pTp Rp?LRp?ii ; i)z{
If a L{FlattenerError} is created with traceback frames, they are
included in the string representation of the exception.
c                    V ^8  d   QhRR/# r2   r4   )r5   s   "r7   r8   8FlattenerErrorTests.test_traceback.<locals>.__annotate__  s     	 	4 	r:   c                     < S ! 4        R # r   r4   )gs   r7   f-FlattenerErrorTests.test_traceback.<locals>.f  s    Cr:   c                $    V ^8  d   QhR\         /# r   )r	   )r5   s   "r7   r8   r    s     	) 	)8 	)r:   c                      \        R 4      h)r  )r  r4   r:   r7   r  -FlattenerErrorTests.test_traceback.<locals>.g  s    x((r:   zf() must raise RuntimeError:   NNNz    ~^^
r  zException while flattening:
  File "%s", line %d, in f
    g()
%s  File "%s", line %d, in g
    raise RuntimeError("reason")
RuntimeError: reason
)failr  	traceback
extract_tbsysexc_infoIS_PYTHON_313rH  rd   r   HERE__code__co_firstlineno)rC   r  etbinfoexccolumn_markerr  s   &     @r7   test_traceback"FlattenerErrorTests.test_tracebackx  s    	 		)	5C II34='MMsB/0% 

))A-

))A-	
  	))#,,.*;<R@FC	s   B- -C;89C66C;c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   r    s     34 34t 34r:   c                N  a \        4       o\        \        4       ! V3R lR4      4       p\        RV! 4       .4      pV P	                  V4       \        R4      pSP                  V4       V P                  V\        4      p\        '       d   RpMRpV P                  \        VP                  4      \        P                  ! \        R4      V,           \        P                   R7      4       V P#                  R	\        VP                  4      4       V P                  S\
        4       R# )
zl
When flattening a renderer which raises an exception asynchronously,
the error is reported when it occurs.
c                   b   <a  ] tR tRt o RtV 3R lR ltV 3R lR ltV 3R lV3R lltR	tV t	R
# )PFlattenerErrorTests.test_asynchronousFlattenError.<locals>.NotActuallyRenderablei  z#No methods provided; this will failc                    < V ^8  d   QhRS[ /# r   r  )r5   r6   s   "r7   r8   ]FlattenerErrorTests.test_asynchronousFlattenError.<locals>.NotActuallyRenderable.__annotate__  s     ( (# (r:   c                    R # )z<unrenderable>r4   rB   s   &r7   r  YFlattenerErrorTests.test_asynchronousFlattenError.<locals>.NotActuallyRenderable.__repr__  s    'r:   c                R   < V ^8  d   QhRS[ RS[S[S[,          S[.S[3,          /# r   r   )r5   r6   s   "r7   r8   r    s1      8H-s3[@Ar:   c                    R # r   r4   r   s   &&r7   r   cFlattenerErrorTests.test_asynchronousFlattenError.<locals>.NotActuallyRenderable.lookupRenderMethod  s     r:   c                6   < V ^8  d   QhRS[ S[,          RS[/# r   r   )r5   r6   s   "r7   r8   r    s       hx&8 [ r:   c                   < S# r   r4   )rC   r   failings   &&r7   r   WFlattenerErrorTests.test_asynchronousFlattenError.<locals>.NotActuallyRenderable.render  s    r:   r4   N)
r   r   r   r   rd  r  r   r   r   r   )r6   r  s   @r7   NotActuallyRenderabler    s+     1( ( 
  r:   r  Nexamplez.*
.*
.*
RuntimeError: example
r  av                      Exception while flattening:
                      \[<unrenderable>\]
                      <unrenderable>
                      <Deferred at .* current result: <twisted.python.failure.Failure builtins.RuntimeError: example>>
                      File ".*", line \d*, in _flattenTree
                        element = await element.*
                    )flagszRuntimeError: example)r   r   r   r)   assertNoResultr  errbackfailureResultOfr   r  assertRegexrd   ru   recompiler   	MULTILINEr   )rC   r  
flatteningr  failurer  r  s   &     @r7   test_asynchronousFlattenError1FlattenerErrorTests.test_asynchronousFlattenError  s    
 %-J	[	!	 	 
"	 #4*?*A)BC
J'9%&&z>B=AMMJJ	  
  ll	
" 	-s7==/AB 	Wl3r:   c                   < V ^8  d   QhRR/# r2   r4   )r5   r6   s   "r7   r8   r    s     $3 $3T $3r:   c                2  aaa	 ^ oRoR VV3R llpRo	R V	3R llp\        V4      p\        RV4      pV P                  V4       VP                  V4       VP	                  4        V P                  V\        4      pV P                  S^4       V P                  SV4       V P                  S	\        4       V P                  \        \        S	4      P                  \        4       VP                  P                  ^ ,          pV P                  V\        4       R# )z0
The flattening of a Deferred can be cancelled.
Nc                >    V ^8  d   QhR\         \        ,          RR/# )r.   	cancelledr3   N)r   r;  )r5   s   "r7   r8   5FlattenerErrorTests.test_cancel.<locals>.__annotate__  s     	 	8F#3 	 	r:   c                    < V oS^,          oR# )r  Nr4   )r  	cancelArgcancelCounts   &r7   checkCancel4FlattenerErrorTests.test_cancel.<locals>.checkCancel  s    !I1Kr:   c                (    V ^8  d   QhR\         RR/# )r.   r  r3   Nr   )r5   s   "r7   r8   r    s     	 	W 	 	r:   c                    < V oR # r   r4   )r  errs   &r7   saveErr0FlattenerErrorTests.test_cancel.<locals>.saveErr  s    Cr:   )r   r)   r  
addErrbackcancelr  r   rH  assertIsassertIsInstancer   r   ru   r   args)
rC   r  r  r  r  r  r  r  r  r  s
   &      @@@r7   test_cancelFlattenerErrorTests.test_cancel  s     		 	
 	 	 '{3"4+
J'	W &&z>Ba(i#c7+d7C066Gmm  #c>2r:   r4   N)r   r   r   r   rd  r  r  r  r  r  r  r   r   r   s   @r7   r  r  F  sH     
 
&
 
	
 	
,
 ,
\34 34j$3 $3r:   r  )      )Frd  r  r  r  collectionsr   r)  r   typesr   typingr   r   r   r	   r
   r   r   xml.etree.ElementTreer   zope.interfacer   hamcrestr   r   twisted.internet.deferr   r   r   r   r   twisted.python.failurer   twisted.test.testutilsr   twisted.trial.unittestr   twisted.web._flattenr   twisted.web.errorr   r   r   twisted.web.iwebr   r   r    twisted.web.templater!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   twisted.web.test._utilr-   version_infor  r0   rf  r  co_filenamer  r  r4   r:   r7   <module>r$     s   
 
 
  #   H H H % & *  + 4 6 , K K C C    3  $/O;*; O;dp6. p6v 	**y3- y3r:   