
    Vhq                        d Z ddlZddlmZ ddlmZmZ ddlmZ ddl	m
Z
 ddlmZmZ 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 ddlmZ ddlmZ ddlmZmZm Z  ddl!m"Z"m#Z# ddl$m%Z% ddl&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/ ddl0m1Z1 ddl2m3Z3  ee4d      Z5 G d de      Z6 G d de      Z7 G d de      Z8 G d d      Z9 G d d ee9      Z: G d! d"ee9      Z; G d# d$ee9      Z< G d% d&ee9      Z= G d' d(e1      Z> G d) d*e1      Z? G d+ d,e'      Z@ G d- d.e'      ZA G d/ d0e'      ZB G d1 d2      ZC ee"       G d3 d4e3             ZD G d5 d6e      ZEy)7z#
Tests for L{twisted.web.template}
    N)StringIO)ListOptional)implementer)verifyObject)Deferredsucceed)EventLoggingObserver)globalLogPublisher)Failure)FilePath)TestCase)suppress)UnexposedMethodError)FlattenerErrorMissingRenderMethodMissingTemplateLoader)IRequestITemplateLoader)NOT_DONE_YET)	ElementFlattenableTag	TagLoaderXMLFile	XMLStringrenderElementrenderertags)FlattenTestCase)DummyRequesthPassing filenames or file objects to XMLFile is deprecated since Twisted 12.1.  Pass a FilePath instead.)categorymessagec                   8    e Zd ZdZddZddZddZddZddZy)	TagFactoryTestszO
    Tests for L{_TagFactory} through the publicly-exposed L{tags} object.
    Nc                 \    t         j                  }| j                  |j                  d       y)z=
        HTML tags can be retrieved through C{tags}.
        aN)r   r(   assertEqualtagNameselftags     N/home/dcms/DCMS/lib/python3.12/site-packages/twisted/web/test/test_template.pytest_lookupTagzTagFactoryTests.test_lookupTag4   s!     ffc*    c                 \    t         j                  }| j                  |j                  d       y)zj
        Twisted supports the latest and greatest HTML tags from the HTML5
        specification.
        videoN)r   r2   r)   r*   r+   s     r.   test_lookupHTML5Tagz#TagFactoryTests.test_lookupHTML5Tag;   s!    
 jjg.r0   c                 \    t         j                  }| j                  |j                  d       y)z
        To support transparent inclusion in templates, there is a special tag,
        the transparent tag, which has no name of its own but is accessed
        through the "transparent" attribute.
         N)r   transparentr)   r*   r+   s     r.   test_lookupTransparentTagz)TagFactoryTests.test_lookupTransparentTagC   s#     b)r0   c                 D    | j                  t        t        t        d       y)zv
        Invalid tags which are not part of HTML cause AttributeErrors when
        accessed through C{tags}.
        invalidNassertRaisesAttributeErrorgetattrr   r,   s    r.   test_lookupInvalidTagz%TagFactoryTests.test_lookupInvalidTagL   s    
 	.'4Cr0   c                 D    | j                  t        t        t        d       y)z
        As a special case, the <xmp> tag is simply not available through
        C{tags} or any other part of the templating machinery.
        xmpNr:   r>   s    r.   test_lookupXMPzTagFactoryTests.test_lookupXMPS   s    
 	.'4?r0   returnN)	__name__
__module____qualname____doc__r/   r3   r7   r?   rB    r0   r.   r&   r&   /   s"    +/*D@r0   r&   c                   P    e Zd 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y)ElementTestsz5
    Tests for the awesome new L{Element} class.
    Nc                     t               }| j                  t        |j                  d      }| j	                  |j
                  |       y)zr
        L{Element.render} raises L{MissingTemplateLoader} if the C{loader}
        attribute is L{None}.
        N)r   r;   r   renderassertIdenticalelementr,   rO   errs      r.   test_missingTemplateLoaderz'ElementTests.test_missingTemplateLoader`   s8    
 ) 5w~~tLS[['2r0   c           	      t     G d dt               }| j                  dt        t         |                          y)zT
        A L{MissingTemplateLoader} instance can be repr()'d without error.
        c                       e Zd ZdefdZy)FElementTests.test_missingTemplateLoaderRepr.<locals>.PrettyReprElementrD   c                      yNPretty Repr ElementrI   r>   s    r.   __repr__zOElementTests.test_missingTemplateLoaderRepr.<locals>.PrettyReprElement.__repr__o       ,r0   NrE   rF   rG   strrY   rI   r0   r.   PrettyReprElementrU   n       -# -r0   r]   rX   N)r   assertInreprr   )r,   r]   s     r.   test_missingTemplateLoaderReprz+ElementTests.test_missingTemplateLoaderRepri   s0    
	- 	- 	!4(=>O>Q(R#S	
r0   c                     t               }| j                  t        |j                  d      }| j	                  |j
                  |       | j                  |j                  d       y)z
        When called with the name which is not associated with a render method,
        L{Element.lookupRenderMethod} raises L{MissingRenderMethod}.
        fooN)r   r;   r   lookupRenderMethodrN   rO   r)   
renderNamerP   s      r.   test_missingRendererMethodz'ElementTests.test_missingRendererMethodv   sO    
 ) 3W5O5OQVWS[['2/r0   c                      G d dt               }t        t         |       d            }| j                  d|       | j                  d|       y)zR
        A L{MissingRenderMethod} instance can be repr()'d without error.
        c                       e Zd ZdefdZy)DElementTests.test_missingRenderMethodRepr.<locals>.PrettyReprElementrD   c                      yrW   rI   r>   s    r.   rY   zMElementTests.test_missingRenderMethodRepr.<locals>.PrettyReprElement.__repr__   rZ   r0   Nr[   rI   r0   r.   r]   ri      r^   r0   r]   expectedMethodrX   N)r   r`   r   r_   )r,   r]   ss      r.   test_missingRenderMethodReprz)ElementTests.test_missingRenderMethodRepr   sE    
	- 	- $%6%8:JKL+Q/&*r0   c                      G d dt               } |       j                  d      }| j                   |dt        j                        d       y)z
        When called with the name of a defined render method,
        L{Element.lookupRenderMethod} returns that render method.
        c                   0    e Zd Zedee   dedefd       Zy)BElementTests.test_definedRenderer.<locals>.ElementWithRenderMethodrequestr-   rD   c                      y)NbarrI   r,   rq   r-   s      r.   rc   zFElementTests.test_definedRenderer.<locals>.ElementWithRenderMethod.foo   s    r0   N)	rE   rF   rG   r   r   r   r   r   rc   rI   r0   r.   ElementWithRenderMethodrp      s.    8H#5 C K  r0   ru   rc   Nrs   )r   rd   r)   r   br)r,   ru   rc   s      r.   test_definedRendererz!ElementTests.test_definedRenderer   s>    	g 	
 &'::5AT477+U3r0   c                     t        t               G d d              G fddt              } |       }| j                  |j	                  d      dg       y)zi
        L{Element.render} loads a document from the C{loader} attribute and
        returns it.
        c                       e Zd Zdee   fdZy)0ElementTests.test_render.<locals>.TemplateLoaderrD   c                     dgS )NresultrI   r>   s    r.   loadz5ElementTests.test_render.<locals>.TemplateLoader.load   s
     z!r0   N)rE   rF   rG   r   r   r}   rI   r0   r.   TemplateLoaderrz      s    "d;/ "r0   r~   c                       e Zd Z W         Zy)-ElementTests.test_render.<locals>.StubElementN)rE   rF   rG   loader)r~   s   r.   StubElementr      s    #%Fr0   r   Nr|   )r   r   r   r)   rM   )r,   r   rO   r~   s      @r.   test_renderzElementTests.test_render   sQ     
_	%	" 	" 
&	"	&' 	& --z:r0   c                     | j                  t        t              }t        j                  dk\  r| j                  t        |      d       y| j                  t        |      d       y)z
        If the L{renderer} decorator  is called without any arguments, it will
        raise a comprehensible exception.
        )   
   z=Expose.__call__() missing 1 required positional argument: 'f'z6__call__() missing 1 required positional argument: 'f'N)r;   	TypeErrorr   sysversion_infor)   r\   )r,   tes     r.   test_misuseRendererz ElementTests.test_misuseRenderer   sV    
 y(3w&BX BQr0   c                 P    | j                  t        t        j                  dd       y)z
        Called directly, without a default, L{renderer.get} raises
        L{UnexposedMethodError} when it cannot find a renderer.
        NnotARenderer)r;   r   r   getr>   s    r.   test_renderGetDirectlyErrorz(ElementTests.test_renderGetDirectlyError   s    
 	.dNSr0   rC   )rE   rF   rG   rH   rR   ra   rf   rm   rw   r   r   r   rI   r0   r.   rK   rK   [   s0    3
0+4;"Tr0   rK   c                   H    e Zd ZdZddZddZege_        ddZege_        y)XMLFileReprTestszB
    Tests for L{twisted.web.template.XMLFile}'s C{__repr__}.
    Nc                 j    t        d      }| j                  d|dt        t        |                   y)zK
        An L{XMLFile} with a L{FilePath} returns a useful repr().
        /tmp/fake.xml<XMLFile of >N)r   r)   r`   r   )r,   paths     r.   test_filePathzXMLFileReprTests.test_filePath   s0     (<xq143FGr0   c                 X    d}| j                  d|dt        t        |                   y)zH
        An L{XMLFile} with a filename returns a useful repr().
        r   r   r   N)r)   r`   r   )r,   fnames     r.   test_filenamezXMLFileReprTests.test_filename   s+      <y2D4HIr0   c                 j    t        d      }| j                  d|dt        t        |                   y)zK
        An L{XMLFile} with a file object returns a useful repr().
        znot xmlr   r   N)r   r)   r`   r   )r,   fobjs     r.   	test_filezXMLFileReprTests.test_file   s0     	"<xq143FGr0   rC   )	rE   rF   rG   rH   r   r   _xmlFileSuppressr   r   rI   r0   r.   r   r      s3    HJ //MH ++Ir0   r   c                   L    e Zd ZU eed<   	 dZ	 defdZddZddZ	e
ge	_        y)	XMLLoaderTestsMixindeprecatedUse<p>Hello, world.</p>rD   c                     t         N)NotImplementedErrorr>   s    r.   loaderFactoryz!XMLLoaderTestsMixin.loaderFactory   s    !!r0   Nc                 *   t        | t              sJ | j                         }|j                         \  }t        |t              sJ | j                  | j                  g      }| j                  rP| j                  t        |      d       | j                  |d   d   t               | j                  |d   d   d       n| j                  t        |      d       | j                  |j                  d       | j                  |j                  dg       y	)
zQ
        Verify that the loader returns a tag with the correct children.
        )offendingFunctions   r   r#   r$   r"   pHello, world.N)
isinstancer   r   r}   r   flushWarningsr   r)   lenDeprecationWarningr*   children)r,   r   r-   warningss       r.   	test_loadzXMLLoaderTestsMixin.test_load   s     $)))##%#s###%%$:L:L9M%NS]A.Xa[46HII&K S]A.c*'89r0   c                     t        | t              sJ | j                         }|j                         }|j                         }| j	                  ||       y)zd
        If {load()} can be called on a loader twice the result should be the
        same.
        N)r   r   r   r}   r)   )r,   r   tags1tags2s       r.   test_loadTwicez"XMLLoaderTestsMixin.test_loadTwice	  sH    
 $)))##%&r0   rC   )rE   rF   rG   bool__annotations__templateStringr   r   r   r   r   r   rI   r0   r.   r   r      s<    
 ,N" ":0	'  00Nr0   r   c                        e Zd ZdZdZdefdZy)XMLStringLoaderTestsz5
    Tests for L{twisted.web.template.XMLString}
    FrD   c                 ,    t        | j                        S )zS
        @return: an L{XMLString} constructed with C{self.templateString}.
        )r   r   r>   s    r.   r   z"XMLStringLoaderTests.loaderFactory  s     ,,--r0   NrE   rF   rG   rH   r   r   r   rI   r0   r.   r   r     s     M. .r0   r   c                        e Zd ZdZdZdefdZy)XMLFileWithFilePathTestszJ
    Tests for L{twisted.web.template.XMLFile}'s L{FilePath} support.
    FrD   c                     t        | j                               }|j                  | j                  j	                  d             t        |      S )z
        @return: an L{XMLString} constructed with a L{FilePath} pointing to a
            file that contains C{self.templateString}.
        utf8)r   mktemp
setContentr   encoder   r,   fps     r.   r   z&XMLFileWithFilePathTests.loaderFactory,  s;    
 dkkm$
d))0089r{r0   Nr   rI   r0   r.   r   r   %  s     M r0   r   c                        e Zd ZdZdZdefdZy)XMLFileWithFileTestszU
    Tests for L{twisted.web.template.XMLFile}'s deprecated file object support.
    TrD   c                 >    t        t        | j                              S )z{
        @return: an L{XMLString} constructed with a file object that contains
            C{self.templateString}.
        )r   r   r   r>   s    r.   r   z"XMLFileWithFileTests.loaderFactory=  s    
 x 3 3455r0   Nr   rI   r0   r.   r   r   6  s     M6 6r0   r   c                        e Zd ZdZdZdefdZy)XMLFileWithFilenameTestszR
    Tests for L{twisted.web.template.XMLFile}'s deprecated filename support.
    TrD   c                     t        | j                               }|j                  | j                  j	                  d             t        |j                        S )z
        @return: an L{XMLString} constructed with a filename that points to a
            file containing C{self.templateString}.
        r   )r   r   r   r   r   r   r   r   s     r.   r   z&XMLFileWithFilenameTests.loaderFactoryL  s@    
 dkkm$
d))0089rwwr0   Nr   rI   r0   r.   r   r   E  s     M   r0   r   c                       e Zd 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y)FlattenIntegrationTestsz[
    Tests for integration between L{Element} and
    L{twisted.web._flatten.flatten}.
    Nc                 d    g d}|D ]'  }| j                  t        t        |            |       ) y)z
        Given a series of parsable XML strings, verify that
        L{twisted.web._flatten.flatten} will flatten the L{Element} back to the
        input when sent on a round trip.
        )   <p>Hello, world.</p>s   <p><!-- hello, world --></p>s    <p><![CDATA[Hello, world.]]></p>sB   <test1 xmlns:test2="urn:test2"><test2:test3></test2:test3></test1>s0   <test1 xmlns="urn:test2"><test3></test3></test1>
   <p>☃</p>r   N)assertFlattensImmediatelyr   r   )r,   	fragmentsxmls      r.   test_roundTripz&FlattenIntegrationTests.test_roundTrip\  s5    
	  	PC**7)C.+I3O	Pr0   c                 R    t        t        d            }| j                  |d       y)zx
        When flattening an HTML entity, it should flatten out to the utf-8
        representation if possible.
        z<p>&#9731;</p>r   r   Nr   r   r   r,   rO   s     r.   test_entityConversionz-FlattenIntegrationTests.test_entityConversionm  s%    
 +;!<=&&w0FGr0   c                 @    | j                  t               t               y)zk
        Rendering an Element without a loader attribute raises the appropriate
        exception.
        N)assertFlatteningRaisesr   r   r>   s    r.   rR   z2FlattenIntegrationTests.test_missingTemplateLoaderu  s    
 	##GI/DEr0   c                 Z    t        t        d            }| j                  |t               y)z
        Flattening an L{Element} with a C{loader} which has a tag with a render
        directive fails with L{FlattenerError} if there is no available render
        method to satisfy that directive.
        zy
        <p xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1"
          t:render="unknownMethod" />
        r   N)r   r   r   r   r   s     r.   test_missingRenderMethodz0FlattenIntegrationTests.test_missingRenderMethod|  s.     
 	##G-@Ar0   c                 R    t        t        d            }| j                  |d       y)zw
        A C{transparent} element should be eliminated from the DOM and rendered as
        only its children.
        zk<t:transparent xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1">Hello, world.</t:transparent>r      Hello, world.Nr   r   s     r.   test_transparentRenderingz1FlattenIntegrationTests.test_transparentRendering  s.    
 #
 	&&w0@Ar0   c                 R    t        t        d            }| j                  |d       y)z~
        An Element with an attr tag renders the vaule of its attr tag as an
        attribute of its containing tag.
        z<a xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1"><t:attr name="href">http://example.com</t:attr>Hello, world.</a>r   s.   <a href="http://example.com">Hello, world.</a>Nr   r   s     r.   test_attrRenderingz*FlattenIntegrationTests.test_attrRendering  s1    
 
 	&&F	
r0   c                 r    | j                  t        d      D cg c]  }t        d       c}d       yc c}w )z
        When rendering a large number of already-fired Deferreds we should not
        encounter any recursion errors or stack-depth issues.
           xs   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxN)r   ranger	   )r,   is     r.   !test_synchronousDeferredRecursionz9FlattenIntegrationTests.test_synchronousDeferredRecursion  s*    
 	&&eCj'I'I:V'Is   4c                 :    | j                  t        t        d       y)z{
        A template with a toplevel C{attr} tag will not load; it will raise
        L{AssertionError} if you try.
        z<t:attr
            xmlns:t='http://twistedmatrix.com/ns/twisted.web.template/0.1'
            name='something'
            >hello</t:attr>
            Nr;   AssertionErrorr   r>   s    r.   test_errorToplevelAttrz.FlattenIntegrationTests.test_errorToplevelAttr  s    
 		
r0   c                 :    | j                  t        t        d       y)z
        A template with an C{attr} tag with no C{name} attribute will not load;
        it will raise L{AssertionError} if you try.
        z{<html><t:attr
            xmlns:t='http://twistedmatrix.com/ns/twisted.web.template/0.1'
            >hello</t:attr></html>Nr   r>   s    r.   test_errorUnnamedAttrz-FlattenIntegrationTests.test_errorUnnamedAttr  s    
 	&	
r0   c                 t    d}t        t        |            }| j                  ||j                  d             y)z
        If the parser sees a prefix it doesn't recognize on an attribute, it
        will pass it on through to serialization.
        z}<hello:world hello:sample="testing" xmlns:hello="http://made-up.example.com/ns/not-real">This is a made-up tag.</hello:world>r   r   N)r   r   assertFlattensTor   )r,   theInputrO   s      r.   test_lenientPrefixBehaviorz2FlattenIntegrationTests.test_lenientPrefixBehavior  s6    3 	
 8!45gxv'>?r0   c                 j     G d dt               } |t        d            }| j                  |d       y)zi
        An Element with a render method which returns a Deferred will render
        correctly.
        c                   0    e Zd Zedee   dedefd       Zy)HFlattenIntegrationTests.test_deferredRendering.<locals>.RenderfulElementrq   r-   rD   c                     t        d      S Nr   )r	   rt   s      r.   renderMethodzUFlattenIntegrationTests.test_deferredRendering.<locals>.RenderfulElement.renderMethod  s     //r0   N	rE   rF   rG   r   r   r   r   r   r   rI   r0   r.   RenderfulElementr     s1    0'108;00 0r0   r   
        <p xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1"
          t:render="renderMethod">
            Goodbye, world.
        </p>
        r   r   Nr   r,   r   rO   s      r.   test_deferredRenderingz.FlattenIntegrationTests.test_deferredRendering  s:    	0w 	0 #	
 	&&w0@Ar0   c                 P     G d dt               }| j                   |       d       y)z
        If there is a non-None loader attribute on the class of an Element
        instance but none on the instance itself, the class attribute is used.
        c                       e Zd Z ed      Zy)EFlattenIntegrationTests.test_loaderClassAttribute.<locals>.SubElementr   N)rE   rF   rG   r   r   rI   r0   r.   
SubElementr    s    56Fr0   r  r   N)r   r   )r,   r  s     r.   test_loaderClassAttributez1FlattenIntegrationTests.test_loaderClassAttribute  s#    	7 	7 	&&z|5LMr0   c                 t    g  G fddt               } |t        d            }| j                  |d       y)z
        An Element with a valid render directive has that directive invoked and
        the result added to the output.
        c                   6    e Zd Zedee   dedef fd       Zy)IFlattenIntegrationTests.test_directiveRendering.<locals>.RenderfulElementrq   r-   rD   c                 :    j                  | |f        |d      S r   )append)r,   rq   r-   renderss      r.   r   zVFlattenIntegrationTests.test_directiveRendering.<locals>.RenderfulElement.renderMethod  s      g/?++r0   Nr   )r	  s   r.   r   r    s2    ,'1,8;,, ,r0   r   x
        <p xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1"
          t:render="renderMethod" />
        r   r   Nr   )r,   r   rO   r	  s      @r.   test_directiveRenderingz/FlattenIntegrationTests.test_directiveRendering   sB    
 	,w 	, #
 	&&w0GHr0   c                 j     G d dt               } |t        d            }| j                  |d       y)z
        An Element with a render method which omits the containing tag
        successfully removes that tag from the output.
        c                   0    e Zd Zedee   dedefd       Zy)TFlattenIntegrationTests.test_directiveRenderingOmittingTag.<locals>.RenderfulElementrq   r-   rD   c                      yr   rI   rt   s      r.   r   zaFlattenIntegrationTests.test_directiveRenderingOmittingTag.<locals>.RenderfulElement.renderMethod   s     'r0   Nr   rI   r0   r.   r   r    s1    ''1'8;'' 'r0   r   r   r   r   Nr   r   s      r.   "test_directiveRenderingOmittingTagz:FlattenIntegrationTests.test_directiveRenderingOmittingTag  s:    	'w 	' #	
 	&&w0@Ar0   c                 j     G d dt               } |t        d            }| j                  |d       y)t
        An Element which is returned by the render method of another Element is
        rendered properly.
        c                   0    e Zd Zedee   dedefd       Zy)UFlattenIntegrationTests.test_elementContainingStaticElement.<locals>.RenderfulElementrq   r-   rD   c                 8     |t        t        d                  S )Nz<em>Hello, world.</em>r   )r   r   rt   s      r.   r   zbFlattenIntegrationTests.test_elementContainingStaticElement.<locals>.RenderfulElement.renderMethod9  s     7)4L*MNOOr0   Nr   rI   r0   r.   r   r  8  s6    P'1P8;PP Pr0   r   r
  r   s   <p><em>Hello, world.</em></p>Nr   r   s      r.   #test_elementContainingStaticElementz;FlattenIntegrationTests.test_elementContainingStaticElement2  s<    	Pw 	P #
 	&&w0PQr0   c                 j     G d dt               } |t        d            }| j                  |d       y)r  c                   0    e Zd Zedee   dedefd       Zy)HFlattenIntegrationTests.test_elementUsingSlots.<locals>.RenderfulElementrq   r-   rD   c                 &    |j                  d      S )Nzworld.)test2)	fillSlotsrt   s      r.   r   zUFlattenIntegrationTests.test_elementUsingSlots.<locals>.RenderfulElement.renderMethodP  s     }}8}44r0   Nr   rI   r0   r.   r   r  O  s1    5'158;55 5r0   r   z<p xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1" t:render="renderMethod"><t:slot name="test1" default="Hello, " /><t:slot name="test2" /></p>r   r   Nr   r   s      r.   test_elementUsingSlotsz.FlattenIntegrationTests.test_elementUsingSlotsI  s:    	5w 	5 #
 	&&w0GHr0   c                      G fddt               } G d dt                |t        d            }| j                  |d       y)	z
        Directives in the document factory of an Element returned from a render
        method of another Element are satisfied from the correct object: the
        "inner" Element.
        c                   6    e Zd Zedee   dedef fd       Zy)RFlattenIntegrationTests.test_elementContainingDynamicElement.<locals>.OuterElementrq   r-   rD   c                 4     | t        d                  S )Nz
                <t:ignored
                  xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1"
                  t:render="innerMethod" />
                r   )r   )r,   rq   r-   InnerElements      r.   outerMethodz^FlattenIntegrationTests.test_elementContainingDynamicElement.<locals>.OuterElement.outerMethodi  s%     ( 
 
r0   N)	rE   rF   rG   r   r   r   r   r   r#  )r"  s   r.   OuterElementr   h  s/    8H+= C K  r0   r$  c                   0    e Zd Zedee   dedefd       Zy)RFlattenIntegrationTests.test_elementContainingDynamicElement.<locals>.InnerElementrq   r-   rD   c                      yr   rI   rt   s      r.   innerMethodz^FlattenIntegrationTests.test_elementContainingDynamicElement.<locals>.InnerElement.innerMethodx  s    &r0   N)	rE   rF   rG   r   r   r   r   r   r(  rI   r0   r.   r"  r&  w  s.    '8H+= 'C 'K ' 'r0   r"  zw
        <p xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1"
          t:render="outerMethod" />
        r   r   Nr   )r,   r$  rO   r"  s      @r.   $test_elementContainingDynamicElementz<FlattenIntegrationTests.test_elementContainingDynamicElementa  sG    	7 		'7 	'
 
 	&&w0GHr0   c                     t        d       G fddt                      }        }| j                  |d       | j                  |d       | j                  |d       y)z
        Rendering the output of a loader, or even the same element, should
        return different output each time.
        z<p xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1"><t:transparent t:render="classCounter" /> <t:transparent t:render="instanceCounter" /></p>c                   h    e Zd ZdZdZW Zedee   de	de
f fd       Zedee   de	de
fd       Zy)HFlattenIntegrationTests.test_sameLoaderTwice.<locals>.DestructiveElementr   rq   r-   rD   c                 d    xj                   dz  c_          |t        j                               S Nr   )countr\   )r,   rq   r-   DestructiveElements      r.   classCounterzUFlattenIntegrationTests.test_sameLoaderTwice.<locals>.DestructiveElement.classCounter  s-     #((A-(3177899r0   c                 b    | xj                   dz  c_          |t        | j                               S r.  )instanceCountr\   rt   s      r.   instanceCounterzXFlattenIntegrationTests.test_sameLoaderTwice.<locals>.DestructiveElement.instanceCounter  s+     ""a'"3t11233r0   N)rE   rF   rG   r/  r3  r   r   r   r   r   r   r1  r4  )r0  sharedLoaders   r.   r0  r,    sr    EM!F:'1:8;:: : 4'148;44 4r0   r0  s
   <p>1 1</p>s
   <p>2 2</p>s
   <p>3 1</p>N)r   r   r   )r,   e1e2r0  r5  s      @@r.   test_sameLoaderTwicez,FlattenIntegrationTests.test_sameLoaderTwice  sb    
 !
	4 	4&  !!&&r=9&&r=9&&r=9r0   rC   )rE   rF   rG   rH   r   r   rR   r   r   r   r   r   r   r   r   r  r  r  r  r  r)  r8  rI   r0   r.   r   r   V  sp    
P"HFB B
"W

@B2	NI2B2R.I0#IJ#:r0   r   c                   0    e Zd ZdZddZddZddZddZy)TagLoaderTestsz!
    Tests for L{TagLoader}.
    Nc                 J    t        t        j                  d            | _        y )Ntest)r   r   r   r   r>   s    r.   setUpzTagLoaderTests.setUp  s    v/r0   c                 V    | j                  t        t        | j                               y)zJ
        An instance of L{TagLoader} provides L{ITemplateLoader}.
        N)
assertTruer   r   r   r>   s    r.   test_interfacezTagLoaderTests.test_interface  s     	_dkkBCr0   c                 `    | j                  | j                  j                         t               y)zK
        L{TagLoader.load} returns a list, per L{ITemplateLoader}.
        N)assertIsInstancer   r}   listr>   s    r.   test_loadsListzTagLoaderTests.test_loadsList  s!     	dkk..0$7r0   c                 R    t        | j                        }| j                  |d       y)z
        L{TagLoader} can be used in an L{Element}, and flattens as the tag used
        to construct the L{TagLoader} would flatten.
        s   <i>test</i>N)r   r   r   )r,   es     r.   test_flattenzTagLoaderTests.test_flatten  s"    
 DKK &&q.9r0   rC   )rE   rF   rG   rH   r=  r@  rD  rG  rI   r0   r.   r:  r:    s    0D8:r0   r:  c                        e Zd ZdZ ed      Zy)TestElementz:
    An L{Element} that can be rendered successfully.
    zS<p xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1">Hello, world.</p>N)rE   rF   rG   rH   r   r   rI   r0   r.   rI  rI    s     	Fr0   rI  c                   6    e Zd ZdZ ed      ZddededdfdZy)	TestFailureElementz
    An L{Element} that can be used in place of L{FailureElement} to verify
    that L{renderElement} can render failures properly.
    zO<p xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1">I failed.</p>Nfailurer   rD   c                     || _         y r   )rL  )r,   rL  r   s      r.   __init__zTestFailureElement.__init__  s	    r0   r   )	rE   rF   rG   rH   r   r   r   objectrN  rI   r0   r.   rK  rK    s2    
 	F  4 r0   rK  c                   &    e Zd ZdZdee   ddfdZy)FailingElementz<
    An element that raises an exception when rendered.
    rq   rD   r   c                     d}d}||z   S )N*   r   rI   )r,   rq   r(   bs       r.   rM   zFailingElement.render  s    q&r0   N)rE   rF   rG   rH   r   r   rM   rI   r0   r.   rQ  rQ    s    hx0 ] r0   rQ  c                       e Zd ZdZdZy)FakeSitezL
    A minimal L{Site} object that we can use to test displayTracebacks
    FN)rE   rF   rG   rH   displayTracebacksrI   r0   r.   rV  rV    s     r0   rV  c                   $     e Zd ZdZd fdZ xZS )DummyRenderRequestz
    A dummy request object that has a C{site} attribute.

    This does not implement the full IRequest interface, but enough of it
    for this test suite.
    c                 D    t         |   dg       t               | _        y )Nr0   )superrN  rV  site)r,   	__class__s    r.   rN  zDummyRenderRequest.__init__  s    #J	r0   rC   )rE   rF   rG   rH   rN  __classcell__)r]  s   @r.   rY  rY    s     r0   rY  c                   r    e Zd ZdZd
dZded   fdZded   fdZded   fdZded   fdZ	ded   fd	Z
y)RenderElementTestsz
    Test L{renderElement}
    rD   Nc                 "    t               | _        y)z8
        Set up a common L{DummyRenderRequest}.
        N)rY  rq   r>   s    r.   r=  zRenderElementTests.setUp  s     *+r0   c                      t               } j                  j                         }dt        ddf fd}|j	                  |        j                  t        t         j                  |             |S )z
        L{renderElement} returns NOT_DONE_YET and eventually
        writes the rendered L{Element} to the request before finishing the
        request.
        _rD   Nc                     j                  dj                  j                  j                        d       j	                  j                  j
                         y )Nr0   s$   <!DOCTYPE html>
<p>Hello, world.</p>)r)   joinrq   writtenr?  finishedrc  r,   s    r.   checkz3RenderElementTests.test_simpleRender.<locals>.check  sB    --.< OODLL112r0   )rI  rq   notifyFinishrO  addCallbackrN   r   r   r,   rO   dri  s   `   r.   test_simpleRenderz$RenderElementTests.test_simpleRender  s_     -LL%%'	3V 	3 	3 	
e\=w+OPr0   c                      t               } j                  j                         }dt        ddf fd}|j	                  |        j                  t        t         j                  |             |S )z
        L{renderElement} handles failures by writing a minimal
        error message to the request and finishing it.
        rc  rD   Nc                    j                  t              }j                  t        |      d       j                  dj	                  j
                  j                        d       j                  j
                  j                         y )Nr   r0   s   <!DOCTYPE html>
<div style="font-size:800%;background-color:#FFF;color:#F00">An error occurred while rendering the response.</div>)	flushLoggedErrorsr   r)   r   re  rq   rf  r?  rg  )rc  flushedr,   s     r.   ri  z4RenderElementTests.test_simpleFailure.<locals>.check1  si    ,,^<GS\1---.O	 OODLL112r0   )rQ  rq   rj  rO  rk  rN   r   r   rl  s   `   r.   test_simpleFailurez%RenderElementTests.test_simpleFailure(  s`    
 !"LL%%'	3V 	3 	3 	
e\=w+OPr0   c                 4    t        j                   t              d j                  j                  _        t               } j                  j                         }dt        ddf fd}|j                  |       t         j                  |t               |S )z
        L{renderElement} will render a traceback when rendering of
        the element fails and our site is configured to display tracebacks.
        Trc  rD   Nc                    j                  dt                     d   d   }j                  |j                  t               j                  t              }j                  t        |      d       j                  dj                  j                  j                        d       j                  j                  j                         y )Nr   r   log_failurer0   s    <!DOCTYPE html>
<p>I failed.</p>)assertEqualsr   rB  valuer   rq  r)   re  rq   rf  r?  rg  )rc  frr  logObserverr,   s      r.   ri  zARenderElementTests.test_simpleFailureWithTraceback.<locals>.checkR  s    a[!12A}-A!!!''>:,,^<GS\1---.0T OODLL112r0   )_failElement)r
   createWithCleanupr   rq   r\  rW  rQ  rj  rO  rk  r   rK  )r,   rO   rm  ri  rz  s   `   @r.   test_simpleFailureWithTracebackz2RenderElementTests.test_simpleFailureWithTracebackF  s{    
 +<<TCUV.2+ "LL%%'		3V 		3 		3 	
edllG:LMr0   c                      t               } j                  j                         }dt        ddf fd}|j	                  |       t         j                  |d       |S )zs
        L{renderElement} will write the doctype string specified by the
        doctype keyword argument.
        rc  rD   Nc                 p    j                  dj                  j                  j                        d       y )Nr0   s   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<p>Hello, world.</p>r)   re  rq   rf  rh  s    r.   ri  z8RenderElementTests.test_nonDefaultDoctype.<locals>.checkl  s,    --.,r0   sm   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">doctyperI  rq   rj  rO  rk  r   rl  s   `   r.   test_nonDefaultDoctypez)RenderElementTests.test_nonDefaultDoctypec  s^    
 -LL%%'	V 	 	 	
eLLI		
 r0   c                      t               } j                  j                         }dt        ddf fd}|j	                  |       t         j                  |d       |S )zs
        L{renderElement} will not write out a doctype if the doctype keyword
        argument is L{None}.
        rc  rD   Nc                 p    j                  dj                  j                  j                        d       y )Nr0   r   r  rh  s    r.   ri  z2RenderElementTests.test_noneDoctype.<locals>.check  s'    SXXdll&:&:;=TUr0   r  r  rl  s   `   r.   test_noneDoctypez#RenderElementTests.test_noneDoctype  sW    
 -LL%%'	VV 	V 	V 	
edllGT:r0   rC   )rE   rF   rG   rH   r=  r   rn  rs  r}  r  r  rI   r0   r.   r`  r`    s]    ,8D> .HTN <$ : @(4. r0   r`  )FrH   r   ior   typingr   r   zope.interfacer   zope.interface.verifyr   twisted.internet.deferr   r	   twisted.internet.testingr
   twisted.loggerr   twisted.python.failurer   twisted.python.filepathr   twisted.trial.unittestr   twisted.trial.utilr   SUPPRESStwisted.web._elementr   twisted.web.errorr   r   r   twisted.web.iwebr   r   twisted.web.serverr   twisted.web.templater   r   r   r   r   r   r   r   r   twisted.web.test._utilr    twisted.web.test.test_webr!   r   r   r&   rK   r   r   r   r   r   r   r   r:  rI  rK  rQ  rV  rY  r`  rI   r0   r.   <module>r     sS     ! & . 4 9 - * , + 3 5 X X 6 +
 
 
 3 2? )@h )@XeT8 eTP,x ,>21 21j.8%8 .x)< "68%8 6 x)<  "S:o S:l
:_ ::	' 	  W   X
 
 
M Mr0   