
    Yfq                        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          ZEdS )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                   :    e Zd ZdZd	dZd	dZd	dZd	dZd	dZdS )
TagFactoryTestszO
    Tests for L{_TagFactory} through the publicly-exposed L{tags} object.
    returnNc                 T    t           j        }|                     |j        d           dS )z=
        HTML tags can be retrieved through C{tags}.
        aN)r   r)   assertEqualtagNameselftags     P/var/www/html/env/lib/python3.11/site-packages/twisted/web/test/test_template.pytest_lookupTagzTagFactoryTests.test_lookupTag4   s)     fc*****    c                 T    t           j        }|                     |j        d           dS )zj
        Twisted supports the latest and greatest HTML tags from the HTML5
        specification.
        videoN)r   r3   r*   r+   r,   s     r/   test_lookupHTML5Tagz#TagFactoryTests.test_lookupHTML5Tag;   s)    
 jg.....r1   c                 T    t           j        }|                     |j        d           dS )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)))))r1   c                 T    |                      t          t          t          d           dS )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CCCCCr1   c                 T    |                      t          t          t          d           dS )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?????r1   r'   N)	__name__
__module____qualname____doc__r0   r4   r8   r@   rC    r1   r/   r&   r&   /   s         + + + +/ / / /* * * *D D D D@ @ @ @ @ @r1   r&   c                   R    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S )ElementTestsz5
    Tests for the awesome new L{Element} class.
    r'   Nc                     t                      }|                     t          |j        d          }|                     |j        |           dS )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`   sE    
 )) 5w~tLLS['22222r1   c           	           G d dt                     }|                     dt          t           |                                           dS )zT
        A L{MissingTemplateLoader} instance can be repr()'d without error.
        c                       e Zd ZdefdZdS )FElementTests.test_missingTemplateLoaderRepr.<locals>.PrettyReprElementr'   c                     dS NPretty Repr ElementrI   r?   s    r/   __repr__zOElementTests.test_missingTemplateLoaderRepr.<locals>.PrettyReprElement.__repr__o       ,,r1   NrE   rF   rG   strrY   rI   r1   r/   PrettyReprElementrU   n   /        -# - - - - - -r1   r]   rX   N)r   assertInreprr   )r-   r]   s     r/   test_missingTemplateLoaderReprz+ElementTests.test_missingTemplateLoaderRepri   sn    
	- 	- 	- 	- 	- 	- 	- 	- 	!4(=>O>O>Q>Q(R(R#S#S	
 	
 	
 	
 	
r1   c                     t                      }|                     t          |j        d          }|                     |j        |           |                     |j        d           dS )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   s_    
 )) 3W5OQVWWS['222/////r1   c                      G d dt                     }t          t           |            d                    }|                     d|           |                     d|           dS )zR
        A L{MissingRenderMethod} instance can be repr()'d without error.
        c                       e Zd ZdefdZdS )DElementTests.test_missingRenderMethodRepr.<locals>.PrettyReprElementr'   c                     dS rW   rI   r?   s    r/   rY   zMElementTests.test_missingRenderMethodRepr.<locals>.PrettyReprElement.__repr__   rZ   r1   Nr[   rI   r1   r/   r]   ri      r^   r1   r]   expectedMethodrX   N)r   r`   r   r_   )r-   r]   ss      r/   test_missingRenderMethodReprz)ElementTests.test_missingRenderMethodRepr   s    
	- 	- 	- 	- 	- 	- 	- 	- $%6%6%8%8:JKKLL+Q///&*****r1   c                      G d dt                     } |                                d          }|                      |dt          j                  d           dS )z
        When called with the name of a defined render method,
        L{Element.lookupRenderMethod} returns that render method.
        c                   >    e Zd Zedee         dedefd            ZdS )BElementTests.test_definedRenderer.<locals>.ElementWithRenderMethodrequestr.   r'   c                     dS )NbarrI   r-   rq   r.   s      r/   rc   zFElementTests.test_definedRenderer.<locals>.ElementWithRenderMethod.foo   s    ur1   N)	rE   rF   rG   r   r   r   r   r   rc   rI   r1   r/   ElementWithRenderMethodrp      sL        8H#5 C K    X  r1   ru   rc   Nrs   )r   rd   r*   r   br)r-   ru   rc   s      r/   test_definedRendererz!ElementTests.test_definedRenderer   st    	 	 	 	 	g 	 	 	
 &%''::5AAT47++U33333r1   c                     t          t                     G d d                       G fddt                    } |            }|                     |                    d          dg           dS )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dS )0ElementTests.test_render.<locals>.TemplateLoaderr'   c                     dgS )NresultrI   r?   s    r/   loadz5ElementTests.test_render.<locals>.TemplateLoader.load   s
     z!r1   N)rE   rF   rG   r   r   r}   rI   r1   r/   TemplateLoaderrz      s4        "d;/ " " " " " "r1   r~   c                   $    e Zd Z              ZdS )-ElementTests.test_render.<locals>.StubElementN)rE   rF   rG   loader)r~   s   r/   StubElementr      s        #^%%FFFr1   r   Nr|   )r   r   r   r*   rM   )r-   r   rO   r~   s      @r/   test_renderzElementTests.test_render   s     
_	%	%	" 	" 	" 	" 	" 	" 	" 
&	%	"	& 	& 	& 	& 	& 	& 	&' 	& 	& 	& +----z:::::r1   c                     |                      t          t                    }t          j        dk    r%|                     t          |          d           dS |                     t          |          d           dS )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   s    
 y(33w&&BX     BQ    r1   c                 T    |                      t          t          j        dd           dS )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SSSSSr1   rD   )rE   rF   rG   rH   rR   ra   rf   rm   rw   r   r   r   rI   r1   r/   rK   rK   [   s         3 3 3 3
 
 
 
0 0 0 0+ + + +4 4 4 4; ; ; ;"   T T T T T Tr1   rK   c                   J    e Zd ZdZddZddZege_        ddZege_        dS )XMLFileReprTestszB
    Tests for L{twisted.web.template.XMLFile}'s C{__repr__}.
    r'   Nc                     t          d          }|                     d|dt          t          |                               dS )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   sG     ((111143F3FGGGGGr1   c                 r    d}|                      d|dt          t          |                               dS )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?      2222D4H4HIIIIIr1   c                     t          d          }|                     d|dt          t          |                               dS )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   sG     	""111143F3FGGGGGr1   rD   )	rE   rF   rG   rH   r   r   _xmlFileSuppressr   r   rI   r1   r/   r   r      s|         H H H HJ J J J //MH H H H ++Ir1   r   c                   N    e Zd ZU eed<   	 dZ	 defdZddZddZ	e
ge	_        dS )	XMLLoaderTestsMixindeprecatedUse<p>Hello, world.</p>r'   c                     t           N)NotImplementedErrorr?   s    r/   loaderFactoryz!XMLLoaderTestsMixin.loaderFactory   s    !!r1   Nc                    t          | t                    sJ |                                 }|                                \  }t          |t                    sJ |                     | j        g          }| j        rm|                     t          |          d           |                     |d         d         t                     |                     |d         d         d           n#|                     t          |          d           |                     |j
        d           |                     |j        dg           d	S )
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   s9    $)))))##%%#s#####%%$:L9M%NN 		/S]]A...Xa[46HIIII&K    S]]A...c***'899999r1   c                     t          | t                    sJ |                                 }|                                }|                                }|                     ||           dS )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	  sa    
 $)))))##%%&&&&&r1   rD   )rE   rF   rG   bool__annotations__templateStringr   r   r   r   r   r   rI   r1   r/   r   r      s         
 ,N" " " " ": : : :0	' 	' 	' 	'  00Nr1   r   c                   "    e Zd ZdZdZdefdZdS )XMLStringLoaderTestsz5
    Tests for L{twisted.web.template.XMLString}
    Fr'   c                 *    t          | j                  S )zS
        @return: an L{XMLString} constructed with C{self.templateString}.
        )r   r   r?   s    r/   r   z"XMLStringLoaderTests.loaderFactory  s     ,---r1   NrE   rF   rG   rH   r   r   r   rI   r1   r/   r   r     s@          M. . . . . . .r1   r   c                   "    e Zd ZdZdZdefdZdS )XMLFileWithFilePathTestszJ
    Tests for L{twisted.web.template.XMLFile}'s L{FilePath} support.
    Fr'   c                     t          |                                           }|                    | 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,  sH    
 dkkmm$$
d)0088999r{{r1   Nr   rI   r1   r/   r   r   %  s@          M      r1   r   c                   "    e Zd ZdZdZdefdZdS )XMLFileWithFileTestszU
    Tests for L{twisted.web.template.XMLFile}'s deprecated file object support.
    Tr'   c                 D    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44555r1   Nr   rI   r1   r/   r   r   6  s@          M6 6 6 6 6 6 6r1   r   c                   "    e Zd ZdZdZdefdZdS )XMLFileWithFilenameTestszR
    Tests for L{twisted.web.template.XMLFile}'s deprecated filename support.
    Tr'   c                     t          |                                           }|                    | 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  sL    
 dkkmm$$
d)0088999rwr1   Nr   rI   r1   r/   r   r   E  s@          M             r1   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dS )FlattenIntegrationTestsz[
    Tests for integration between L{Element} and
    L{twisted.web._flatten.flatten}.
    r'   Nc                 z    g d}|D ]3}|                      t          t          |                    |           4dS )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\  s\    
 
 
	  	P 	PC**7)C..+I+I+I3OOOO	P 	Pr1   c                 l    t          t          d                    }|                     |d           dS )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GGGGGr1   c                 T    |                      t                      t                     dS )zk
        Rendering an Element without a loader attribute raises the appropriate
        exception.
        N)assertFlatteningRaisesr   r   r?   s    r/   rR   z2FlattenIntegrationTests.test_missingTemplateLoaderu  s%    
 	##GII/DEEEEEr1   c                 v    t          t          d                    }|                     |t                     dS )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|  sI      
 
 
 	##G-@AAAAAr1   c                 l    t          t          d                    }|                     |d           dS )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  sI    
 # 
 
 
 	&&w0@AAAAAr1   c                 l    t          t          d                    }|                     |d           dS )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  sT    
  
 
 
 	&&F	
 	
 	
 	
 	
r1   c                 `    |                      d t          d          D             d           dS )z
        When rendering a large number of already-fired Deferreds we should not
        encounter any recursion errors or stack-depth issues.
        c                 ,    g | ]}t          d           S )xr	   ).0is     r/   
<listcomp>zMFlattenIntegrationTests.test_synchronousDeferredRecursion.<locals>.<listcomp>  s    'I'I'I'I'I'Ir1      s   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxN)r   ranger?   s    r/   !test_synchronousDeferredRecursionz9FlattenIntegrationTests.test_synchronousDeferredRecursion  s5    
 	&&'I'IeCjj'I'I'I:VVVVVr1   c                 H    |                      t          t          d           dS )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  s1    
 		
 	
 	
 	
 	
r1   c                 H    |                      t          t          d           dS )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  s1    
 	&	
 	
 	
 	
 	
r1   c                     d}t          t          |                    }|                     ||                    d                     dS )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  sN    3 	
 8!4!4555gxv'>'>?????r1   c                      G d dt                     } |t          d                    }|                     |d           dS )zi
        An Element with a render method which returns a Deferred will render
        correctly.
        c                   >    e Zd Zedee         dedefd            ZdS )HFlattenIntegrationTests.test_deferredRendering.<locals>.RenderfulElementrq   r.   r'   c                      t          d          S Nr   r   rt   s      r/   renderMethodzUFlattenIntegrationTests.test_deferredRendering.<locals>.RenderfulElement.renderMethod  s     ///r1   N	rE   rF   rG   r   r   r   r   r   r   rI   r1   r/   RenderfulElementr     sO        0'108;00 0 0 X0 0 0r1   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  sv    	0 	0 	0 	0 	0w 	0 	0 	0 #" 	
 	
 	
 	&&w0@AAAAAr1   c                 h     G d dt                     }|                      |            d           dS )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dS )EFlattenIntegrationTests.test_loaderClassAttribute.<locals>.SubElementr   N)rE   rF   rG   r   r   rI   r1   r/   
SubElementr    s        Y566FFFr1   r  r   N)r   r   )r-   r  s     r/   test_loaderClassAttributez1FlattenIntegrationTests.test_loaderClassAttribute  sQ    	7 	7 	7 	7 	7 	7 	7 	7 	&&zz||5LMMMMMr1   c                     g  G fddt                     } |t          d                    }|                     |d           dS )z
        An Element with a valid render directive has that directive invoked and
        the result added to the output.
        c                   D    e Zd Zedee         dedef fd            ZdS )IFlattenIntegrationTests.test_directiveRendering.<locals>.RenderfulElementrq   r.   r'   c                 H                         | |f            |d          S r   )append)r-   rq   r.   renderss      r/   r   zVFlattenIntegrationTests.test_directiveRendering.<locals>.RenderfulElement.renderMethod  s+     g///s?+++r1   Nr   )r  s   r/   r   r
    sZ        ,'1,8;,, , , , , X, , ,r1   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   s    
 	, 	, 	, 	, 	, 	, 	,w 	, 	, 	, #" 
 
 
 	&&w0GHHHHHr1   c                      G d dt                     } |t          d                    }|                     |d           dS )z
        An Element with a render method which omits the containing tag
        successfully removes that tag from the output.
        c                   >    e Zd Zedee         dedefd            ZdS )TFlattenIntegrationTests.test_directiveRenderingOmittingTag.<locals>.RenderfulElementrq   r.   r'   c                     dS r   rI   rt   s      r/   r   zaFlattenIntegrationTests.test_directiveRenderingOmittingTag.<locals>.RenderfulElement.renderMethod   s	     'r1   Nr   rI   r1   r/   r   r    sO        ''1'8;'' ' ' X' ' 'r1   r   r   r   r   Nr   r  s      r/   "test_directiveRenderingOmittingTagz:FlattenIntegrationTests.test_directiveRenderingOmittingTag  sv    	' 	' 	' 	' 	'w 	' 	' 	' #" 	
 	
 	
 	&&w0@AAAAAr1   c                      G d dt                     } |t          d                    }|                     |d           dS )t
        An Element which is returned by the render method of another Element is
        rendered properly.
        c                   >    e Zd Zedee         dedefd            ZdS )UFlattenIntegrationTests.test_elementContainingStaticElement.<locals>.RenderfulElementrq   r.   r'   c                 N     |t          t          d                              S )Nz<em>Hello, world.</em>r   )r   r   rt   s      r/   r   zbFlattenIntegrationTests.test_elementContainingStaticElement.<locals>.RenderfulElement.renderMethod9  s(     s7)4L*M*MNNNOOOr1   Nr   rI   r1   r/   r   r  8  sX        P'1P8;PP P P XP P Pr1   r   r  r   s   <p><em>Hello, world.</em></p>Nr   r  s      r/   #test_elementContainingStaticElementz;FlattenIntegrationTests.test_elementContainingStaticElement2  s~    	P 	P 	P 	P 	Pw 	P 	P 	P #" 
 
 
 	&&w0PQQQQQr1   c                      G d dt                     } |t          d                    }|                     |d           dS )r  c                   >    e Zd Zedee         dedefd            ZdS )HFlattenIntegrationTests.test_elementUsingSlots.<locals>.RenderfulElementrq   r.   r'   c                 .    |                     d          S )Nzworld.)test2)	fillSlotsrt   s      r/   r   zUFlattenIntegrationTests.test_elementUsingSlots.<locals>.RenderfulElement.renderMethodP  s     }}8}444r1   Nr   rI   r1   r/   r   r  O  sO        5'158;55 5 5 X5 5 5r1   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  sv    	5 	5 	5 	5 	5w 	5 	5 	5 #" 
 
 
 	&&w0GHHHHHr1   c                      G fddt                     } G d dt                      |t          d                    }|                     |d           dS )	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                   D    e Zd Zedee         dedef fd            ZdS )RFlattenIntegrationTests.test_elementContainingDynamicElement.<locals>.OuterElementrq   r.   r'   c                 H     | 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=    s L(     
 
 
r1   N)	rE   rF   rG   r   r   r   r   r   r'  )r&  s   r/   OuterElementr$  h  sW        8H+= C K      X  r1   r(  c                   >    e Zd Zedee         dedefd            ZdS )RFlattenIntegrationTests.test_elementContainingDynamicElement.<locals>.InnerElementrq   r.   r'   c                     dS r   rI   rt   s      r/   innerMethodz^FlattenIntegrationTests.test_elementContainingDynamicElement.<locals>.InnerElement.innerMethodx  s    &r1   N)	rE   rF   rG   r   r   r   r   r   r,  rI   r1   r/   r&  r*  w  sL        '8H+= 'C 'K ' ' ' X' ' 'r1   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  s    	 	 	 	 	 	 	7 	 	 		' 	' 	' 	' 	'7 	' 	' 	'
 , 
 
 
 	&&w0GHHHHHr1   c                     t          d           G fddt                                 }             }|                     |d           |                     |d           |                     |d           dS )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                       e Zd ZdZdZZedee         de	de
f fd            Zedee         de	de
fd            ZdS )HFlattenIntegrationTests.test_sameLoaderTwice.<locals>.DestructiveElementr   rq   r.   r'   c                 ^    xj         dz  c_          |t          j                             S Nr   )countr\   )r-   rq   r.   DestructiveElements      r/   classCounterzUFlattenIntegrationTests.test_sameLoaderTwice.<locals>.DestructiveElement.classCounter  s5     #((A-((s31788999r1   c                 \    | xj         dz  c_          |t          | j                             S r2  )instanceCountr\   rt   s      r/   instanceCounterzXFlattenIntegrationTests.test_sameLoaderTwice.<locals>.DestructiveElement.instanceCounter  s3     ""a'""s3t122333r1   N)rE   rF   rG   r3  r7  r   r   r   r   r   r   r5  r8  )r4  sharedLoaders   r/   r4  r0    s        EM!F:'1:8;:: : : : : X: 4'148;44 4 4 X4 4 4r1   r4  s
   <p>1 1</p>s
   <p>2 2</p>s
   <p>3 1</p>N)r   r   r   )r-   e1e2r4  r9  s      @@r/   test_sameLoaderTwicez,FlattenIntegrationTests.test_sameLoaderTwice  s    
 !
 
	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4&  !!!!&&r=999&&r=999&&r=99999r1   rD   )rE   rF   rG   rH   r   r   rR   r   r   r   r   r   r   r   r  r  r  r  r  r!  r-  r<  rI   r1   r/   r   r   V  s        
P P P P"H H H HF F F FB B B B B B B B
 
 
 
"W W W W
 
 
 

 
 
 
@ @ @ @B B B B2	N 	N 	N 	NI I I I2B B B B2R R R R.I I I I0#I #I #I #IJ#: #: #: #: #: #:r1   r   c                   2    e Zd ZdZddZddZddZddZdS )	TagLoaderTestsz!
    Tests for L{TagLoader}.
    r'   Nc                 R    t          t          j        d                    | _        d S )Ntest)r   r   r   r   r?   s    r/   setUpzTagLoaderTests.setUp  s    v//r1   c                 `    |                      t          t          | j                             dS )zJ
        An instance of L{TagLoader} provides L{ITemplateLoader}.
        N)
assertTruer   r   r   r?   s    r/   test_interfacezTagLoaderTests.test_interface  s(     	_dkBBCCCCCr1   c                 j    |                      | j                                        t                     dS )zK
        L{TagLoader.load} returns a list, per L{ITemplateLoader}.
        N)assertIsInstancer   r}   listr?   s    r/   test_loadsListzTagLoaderTests.test_loadsList  s.     	dk..00$77777r1   c                 Z    t          | j                  }|                     |d           dS )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/    
 DK  &&q.99999r1   rD   )rE   rF   rG   rH   rA  rD  rH  rK  rI   r1   r/   r>  r>    sr         0 0 0 0D D D D8 8 8 8: : : : : :r1   r>  c                   (    e Zd ZdZ ed          ZdS )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   r1   r/   rM  rM    s0          Y	 FFFr1   rM  c                   >    e Zd ZdZ ed          ZddededdfdZdS )	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   r'   c                     || _         d S r   )rP  )r-   rP  r   s      r/   __init__zTestFailureElement.__init__  s    r1   r   )	rE   rF   rG   rH   r   r   r   objectrR  rI   r1   r/   rO  rO    sd         
 Y	 F   4      r1   rO  c                   .    e Zd ZdZdee         ddfdZdS )FailingElementz<
    An element that raises an exception when rendered.
    rq   r'   r   c                     d}d}||z   S )N*   r   rI   )r-   rq   r)   bs       r/   rM   zFailingElement.render  s    q&{r1   N)rE   rF   rG   rH   r   r   rM   rI   r1   r/   rU  rU    sE         hx0 ]      r1   rU  c                       e Zd ZdZdZdS )FakeSitezL
    A minimal L{Site} object that we can use to test displayTracebacks
    FN)rE   rF   rG   rH   displayTracebacksrI   r1   r/   rZ  rZ    s"          r1   rZ  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.
    r'   Nc                 r    t                                          dg           t                      | _        d S )Nr1   )superrR  rZ  site)r-   	__class__s    r/   rR  zDummyRenderRequest.__init__  s,    #JJ			r1   rD   )rE   rF   rG   rH   rR  __classcell__)ra  s   @r/   r]  r]    sG                  r1   r]  c                       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
dS )RenderElementTestsz
    Test L{renderElement}
    r'   Nc                 ,    t                      | _        dS )z8
        Set up a common L{DummyRenderRequest}.
        N)r]  rq   r?   s    r/   rA  zRenderElementTests.setUp  s     *++r1   c                      t                      } j                                        }dt          ddf fd}|                    |                                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.
        _r'   Nc                                          d                    j        j                  d                               j        j                   d S )Nr1   s$   <!DOCTYPE html>
<p>Hello, world.</p>)r*   joinrq   writtenrC  finishedrg  r-   s    r/   checkz3RenderElementTests.test_simpleRender.<locals>.check  sQ    -..<   OODL122222r1   )rM  rq   notifyFinishrS  addCallbackrN   r   r   r-   rO   drm  s   `   r/   test_simpleRenderz$RenderElementTests.test_simpleRender  s     --L%%''	3V 	3 	3 	3 	3 	3 	3 	3 	
e\=w+O+OPPPr1   c                      t                      } j                                        }dt          ddf fd}|                    |                                t          t           j        |                     |S )z
        L{renderElement} handles failures by writing a minimal
        error message to the request and finishing it.
        rg  r'   Nc                 &                        t                    }                    t          |          d                               d                    j        j                  d                               j        j                   d S )Nr   r1   s   <!DOCTYPE html>
<div style="font-size:800%;background-color:#FFF;color:#F00">An error occurred while rendering the response.</div>)	flushLoggedErrorsr   r*   r   ri  rq   rj  rC  rk  )rg  flushedr-   s     r/   rm  z4RenderElementTests.test_simpleFailure.<locals>.check1  s    ,,^<<GS\\1----..O	 	 	 OODL122222r1   )rU  rq   rn  rS  ro  rN   r   r   rp  s   `   r/   test_simpleFailurez%RenderElementTests.test_simpleFailure(  s    
 !""L%%''	3V 	3 	3 	3 	3 	3 	3 	3 	
e\=w+O+OPPPr1   c                 0    t          j         t                    d j        j        _        t                      } j                                        }dt          ddf fd}|	                    |           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.
        Trg  r'   Nc                                         dt                               d         d         }                    |j        t                                         t                    }                    t          |          d                               d                    j        j	                  d           
                    j        j                   d S )Nr   r   log_failurer1   s    <!DOCTYPE html>
<p>I failed.</p>)assertEqualsr   rF  valuer   ru  r*   ri  rq   rj  rC  rk  )rg  frv  logObserverr-   s      r/   rm  zARenderElementTests.test_simpleFailureWithTraceback.<locals>.checkR  s    a[!1!1222A}-A!!!'>:::,,^<<GS\\1----..0T   OODL122222r1   )_failElement)r
   createWithCleanupr   rq   r`  r[  rU  rn  rS  ro  r   rO  )r-   rO   rq  rm  r~  s   `   @r/   test_simpleFailureWithTracebackz2RenderElementTests.test_simpleFailureWithTracebackF  s    
 +<TCUVV.2+ ""L%%''		3V 		3 		3 		3 		3 		3 		3 		3 		3 	
edlG:LMMMMr1   c                      t                      } j                                        }dt          ddf fd}|                    |           t           j        |d           |S )zs
        L{renderElement} will write the doctype string specified by the
        doctype keyword argument.
        rg  r'   Nc                 n                         d                    j        j                  d           d S )Nr1   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*   ri  rq   rj  rl  s    r/   rm  z8RenderElementTests.test_nonDefaultDoctype.<locals>.checkl  s>    -..,    r1   sm   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">doctyperM  rq   rn  rS  ro  r   rp  s   `   r/   test_nonDefaultDoctypez)RenderElementTests.test_nonDefaultDoctypec  s    
 --L%%''	V 	 	 	 	 	 	 	 	
eLI		
 	
 	
 	
 r1   c                      t                      } j                                        }dt          ddf fd}|                    |           t           j        |d           |S )zs
        L{renderElement} will not write out a doctype if the doctype keyword
        argument is L{None}.
        rg  r'   Nc                 n                         d                    j        j                  d           d S )Nr1   r   r  rl  s    r/   rm  z2RenderElementTests.test_noneDoctype.<locals>.check  s1    SXXdl&:;;=TUUUUUr1   r  r  rp  s   `   r/   test_noneDoctypez#RenderElementTests.test_noneDoctype  s    
 --L%%''	VV 	V 	V 	V 	V 	V 	V 	V 	
edlGT::::r1   rD   )rE   rF   rG   rH   rA  r   rr  rw  r  r  r  rI   r1   r/   rd  rd    s         , , , ,8D>    .HTN    <$    :    @(4.      r1   rd  )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>  rM  rO  rU  rZ  r]  rd  rI   r1   r/   <module>r     s    


       ! ! ! ! ! ! ! ! & & & & & & . . . . . . 4 4 4 4 4 4 4 4 9 9 9 9 9 9 - - - - - - * * * * * * , , , , , , + + + + + + 3 3 3 3 3 3 5 5 5 5 5 5 X X X X X X X X X X 6 6 6 6 6 6 6 6 + + + + + +
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 3 2 2 2 2 2 2 2 2 2 2 28?   )@ )@ )@ )@ )@h )@ )@ )@XeT eT eT eT eT8 eT eT eTP, , , , ,x , , ,>21 21 21 21 21 21 21 21j. . . . .8%8 . . .    x)<   "6 6 6 6 68%8 6 6 6         x)<      "S: S: S: S: S:o S: S: S:l
: : : : :_ : : ::	 	 	 	 	' 	 	 	            W           X
 
 
 
 
 
 
 
M M M M M M M M M Mr1   