o
    Óó·i†q  ã                   @   s4  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d�Z5G dd„ deƒZ6G dd„ deƒZ7G dd„ deƒZ8G dd„ dƒZ9G dd „ d ee9ƒZ:G d!d"„ d"ee9ƒZ;G d#d$„ d$ee9ƒZ<G d%d&„ d&ee9ƒZ=G d'd(„ d(e1ƒZ>G d)d*„ d*e1ƒZ?G d+d,„ d,e'ƒZ@G d-d.„ d.e'ƒZAG d/d0„ d0e'ƒZBG d1d2„ d2ƒZCee"ƒG d3d4„ d4e3ƒƒZDG d5d6„ 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)ÚDummyRequestúhPassing filenames or file objects to XMLFile is deprecated since Twisted 12.1.  Pass a FilePath instead.)ÚcategoryÚmessagec                   @   sB   e Zd ZdZddd„Zddd„Zddd	„Zdd
d„Zddd„ZdS )ÚTagFactoryTestszO
    Tests for L{_TagFactory} through the publicly-exposed L{tags} object.
    ÚreturnNc                 C   ó   t j}|  |jd¡ dS )z=
        HTML tags can be retrieved through C{tags}.
        ÚaN)r   r'   ÚassertEqualÚtagName©ÚselfÚtag© r-   údC:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\twisted/web/test/test_template.pyÚtest_lookupTag4   s   zTagFactoryTests.test_lookupTagc                 C   r&   )zj
        Twisted supports the latest and greatest HTML tags from the HTML5
        specification.
        ÚvideoN)r   r0   r(   r)   r*   r-   r-   r.   Útest_lookupHTML5Tag;   s   z#TagFactoryTests.test_lookupHTML5Tagc                 C   r&   )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   Ztransparentr(   r)   r*   r-   r-   r.   Útest_lookupTransparentTagC   s   z)TagFactoryTests.test_lookupTransparentTagc                 C   ó   |   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+   r-   r-   r.   Útest_lookupInvalidTagL   ó   z%TagFactoryTests.test_lookupInvalidTagc                 C   r4   )z‘
        As a special case, the <xmp> tag is simply not available through
        C{tags} or any other part of the templating machinery.
        ÚxmpNr6   r:   r-   r-   r.   Útest_lookupXMPS   r<   zTagFactoryTests.test_lookupXMP©r%   N)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r/   r1   r3   r;   r>   r-   r-   r-   r.   r$   /   s    



	r$   c                   @   s`   e Zd ZdZddd„Zddd„Zddd	„Zdd
d„Zddd„Zddd„Z	ddd„Z
ddd„ZdS )ÚElementTestsz5
    Tests for the awesome new L{Element} class.
    r%   Nc                 C   s(   t ƒ }|  t|jd¡}|  |j|¡ dS )zr
        L{Element.render} raises L{MissingTemplateLoader} if the C{loader}
        attribute is L{None}.
        N)r   r7   r   ÚrenderÚassertIdenticalÚelement©r+   rG   Úerrr-   r-   r.   Útest_missingTemplateLoader`   s   z'ElementTests.test_missingTemplateLoaderc                 C   s*   G d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d„ZdS )zFElementTests.test_missingTemplateLoaderRepr.<locals>.PrettyReprElementr%   c                 S   ó   dS ©NúPretty Repr Elementr-   r:   r-   r-   r.   Ú__repr__o   ó   zOElementTests.test_missingTemplateLoaderRepr.<locals>.PrettyReprElement.__repr__N©r@   rA   rB   ÚstrrO   r-   r-   r-   r.   ÚPrettyReprElementn   ó    rS   rN   N)r   ÚassertInÚreprr   )r+   rS   r-   r-   r.   Útest_missingTemplateLoaderRepri   s   ÿz+ElementTests.test_missingTemplateLoaderReprc                 C   s6   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   r7   r   ÚlookupRenderMethodrF   rG   r(   Z
renderNamerH   r-   r-   r.   Útest_missingRendererMethodv   s   z'ElementTests.test_missingRendererMethodc                 C   s<   G dd„ dt ƒ}tt|ƒ dƒƒ}|  d|¡ |  d|¡ dS )zR
        A L{MissingRenderMethod} instance can be repr()'d without error.
        c                   @   rK   )zDElementTests.test_missingRenderMethodRepr.<locals>.PrettyReprElementr%   c                 S   rL   rM   r-   r:   r-   r-   r.   rO   †   rP   zMElementTests.test_missingRenderMethodRepr.<locals>.PrettyReprElement.__repr__NrQ   r-   r-   r-   r.   rS   …   rT   rS   ZexpectedMethodrN   N)r   rV   r   rU   )r+   rS   Úsr-   r-   r.   Útest_missingRenderMethodRepr€   s   z)ElementTests.test_missingRenderMethodReprc                 C   s4   G d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d„ƒZdS )zBElementTests.test_definedRenderer.<locals>.ElementWithRenderMethodÚrequestr,   r%   c                 S   rL   )NÚbarr-   ©r+   r^   r,   r-   r-   r.   rX   ”   ó   zFElementTests.test_definedRenderer.<locals>.ElementWithRenderMethod.fooN)	r@   rA   rB   r   r   r   r   r   rX   r-   r-   r-   r.   ÚElementWithRenderMethod“   ó     rb   rX   Nr_   )r   rY   r(   r   Úbr)r+   rb   rX   r-   r-   r.   Útest_definedRenderer�   s   z!ElementTests.test_definedRendererc                    sH   t tƒG dd„ dƒƒ‰ G ‡ fdd„dtƒ}|ƒ }|  | d¡dg¡ dS )zi
        L{Element.render} loads a document from the C{loader} attribute and
        returns it.
        c                   @   s   e Zd Zdee fdd„ZdS )z0ElementTests.test_render.<locals>.TemplateLoaderr%   c                 S   s   dgS )NÚresultr-   r:   r-   r-   r.   Úload£   s   z5ElementTests.test_render.<locals>.TemplateLoader.loadN)r@   rA   rB   r   r   rg   r-   r-   r-   r.   ÚTemplateLoader¡   s    rh   c                       s   e Zd Z” ƒ ZdS )z-ElementTests.test_render.<locals>.StubElementN)r@   rA   rB   Úloaderr-   ©rh   r-   r.   ÚStubElement¦   s    
rk   Nrf   )r   r   r   r(   rE   )r+   rk   rG   r-   rj   r.   Útest_render›   s
   zElementTests.test_renderc                 C   s>   |   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)r7   Ú	TypeErrorr   ÚsysÚversion_infor(   rR   )r+   Úter-   r-   r.   Útest_misuseRenderer¬   s   
ÿÿz ElementTests.test_misuseRendererc                 C   s   |   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.
        NZnotARenderer)r7   r   r   Úgetr:   r-   r-   r.   Útest_renderGetDirectlyError»   s   z(ElementTests.test_renderGetDirectlyErrorr?   )r@   rA   rB   rC   rJ   rW   rZ   r\   re   rl   rs   ru   r-   r-   r-   r.   rD   [   s    

	





rD   c                   @   s>   e Zd ZdZd
dd„Zd
dd„Zege_d
dd	„Zege_dS )ÚXMLFileReprTestszB
    Tests for L{twisted.web.template.XMLFile}'s C{__repr__}.
    r%   Nc                 C   ó(   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(   rV   r   )r+   Úpathr-   r-   r.   Útest_filePathÈ   ó    zXMLFileReprTests.test_filePathc                 C   s$   d}|   d|›d�tt|ƒƒ¡ dS )zH
        An L{XMLFile} with a filename returns a useful repr().
        rx   ry   rz   N)r(   rV   r   )r+   Úfnamer-   r-   r.   Útest_filenameÏ   s    zXMLFileReprTests.test_filenamec                 C   rw   )zK
        An L{XMLFile} with a file object returns a useful repr().
        znot xmlry   rz   N)r   r(   rV   r   )r+   Zfobjr-   r-   r.   Ú	test_fileØ   r}   zXMLFileReprTests.test_filer?   )	r@   rA   rB   rC   r|   r   Ú_xmlFileSuppressr   r€   r-   r-   r-   r.   rv   Ã   s    


rv   c                   @   sH   e Zd ZU eed< 	 dZ	 defdd„Zddd„Zdd	d
„Z	e
ge	_dS )ÚXMLLoaderTestsMixinÚdeprecatedUseú<p>Hello, world.</p>r%   c                 C   s   t ‚©N)ÚNotImplementedErrorr:   r-   r-   r.   ÚloaderFactoryî   rP   z!XMLLoaderTestsMixin.loaderFactoryNc                 C   s°   t | tƒsJ ‚|  ¡ }| ¡ \}t |tƒsJ ‚| j| jgd�}| jr?|  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.
        )ZoffendingFunctionsé   r   r"   r#   r!   ÚpúHello, world.N)Ú
isinstancer   r‡   rg   r   ZflushWarningsrƒ   r(   ÚlenÚDeprecationWarningr)   Úchildren)r+   ri   r,   Úwarningsr-   r-   r.   Ú	test_loadñ   s   

þzXMLLoaderTestsMixin.test_loadc                 C   s6   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‡   rg   r(   )r+   ri   Ztags1Ztags2r-   r-   r.   Útest_loadTwice	  s
   z"XMLLoaderTestsMixin.test_loadTwicer?   )r@   rA   rB   ÚboolÚ__annotations__ÚtemplateStringr   r‡   r�   r‘   r�   r   r-   r-   r-   r.   r‚   â   s   
 

r‚   c                   @   ó"   e Zd ZdZdZdefdd„ZdS )ÚXMLStringLoaderTestsz5
    Tests for L{twisted.web.template.XMLString}
    Fr%   c                 C   s
   t | jƒS )zS
        @return: an L{XMLString} constructed with C{self.templateString}.
        N)r   r”   r:   r-   r-   r.   r‡     s   
z"XMLStringLoaderTests.loaderFactoryN©r@   rA   rB   rC   rƒ   r   r‡   r-   r-   r-   r.   r–     ó    r–   c                   @   r•   )ÚXMLFileWithFilePathTestszJ
    Tests for L{twisted.web.template.XMLFile}'s L{FilePath} support.
    Fr%   c                 C   s&   t |  ¡ ƒ}| | j d¡¡ t|ƒS )zŽ
        @return: an L{XMLString} constructed with a L{FilePath} pointing to a
            file that contains C{self.templateString}.
        Úutf8N)r   ÚmktempÚ
setContentr”   Úencoder   ©r+   Úfpr-   r-   r.   r‡   ,  s   z&XMLFileWithFilePathTests.loaderFactoryNr—   r-   r-   r-   r.   r™   %  r˜   r™   c                   @   r•   )ÚXMLFileWithFileTestszU
    Tests for L{twisted.web.template.XMLFile}'s deprecated file object support.
    Tr%   c                 C   s   t t| jƒƒS )z{
        @return: an L{XMLString} constructed with a file object that contains
            C{self.templateString}.
        N)r   r   r”   r:   r-   r-   r.   r‡   =  s   z"XMLFileWithFileTests.loaderFactoryNr—   r-   r-   r-   r.   r    6  r˜   r    c                   @   r•   )ÚXMLFileWithFilenameTestszR
    Tests for L{twisted.web.template.XMLFile}'s deprecated filename support.
    Tr%   c                 C   s(   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š   N)r   r›   rœ   r”   r�   r   r{   rž   r-   r-   r.   r‡   L  s   
z&XMLFileWithFilenameTests.loaderFactoryNr—   r-   r-   r-   r.   r¡   E  r˜   r¡   c                   @   sÄ   e Zd ZdZd(dd„Zd(dd„Zd(dd	„Zd(d
d„Zd(dd„Zd(dd„Z	d(dd„Z
d(dd„Zd(dd„Zd(dd„Zd(dd„Zd(dd„Zd(dd„Zd(dd„Zd(d d!„Zd(d"d#„Zd(d$d%„Zd(d&d'„ZdS ))ÚFlattenIntegrationTestsz[
    Tests for integration between L{Element} and
    L{twisted.web._flatten.flatten}.
    r%   Nc                 C   s,   g d¢}|D ]}|   tt|ƒd�|¡ qd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>©ri   N)ÚassertFlattensImmediatelyr   r   )r+   Ú	fragmentsÚxmlr-   r-   r.   Útest_roundTrip\  s   ÿz&FlattenIntegrationTests.test_roundTripc                 C   ó   t tdƒ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+   rG   r-   r-   r.   Útest_entityConversionm  s   z-FlattenIntegrationTests.test_entityConversionc                 C   s   |   tƒ t¡ dS )zk
        Rendering an Element without a loader attribute raises the appropriate
        exception.
        N)ÚassertFlatteningRaisesr   r   r:   r-   r-   r.   rJ   u  s   z2FlattenIntegrationTests.test_missingTemplateLoaderc                 C   s   t tdƒ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¬   r-   r-   r.   Útest_missingRenderMethod|  s   ÿÿz0FlattenIntegrationTests.test_missingRenderMethodc                 C   rª   )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¬   r-   r-   r.   Útest_transparentRenderingŒ  s   ÿÿz1FlattenIntegrationTests.test_transparentRenderingc                 C   rª   )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¬   r-   r-   r.   Útest_attrRendering›  s   ÿÿÿz*FlattenIntegrationTests.test_attrRenderingc                 C   s   |   d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                 S   s   g | ]}t d ƒ‘qS )Úx©r   )Ú.0Úir-   r-   r.   Ú
<listcomp>±  s    zMFlattenIntegrationTests.test_synchronousDeferredRecursion.<locals>.<listcomp>éú   sú   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxN)r¦   Úranger:   r-   r-   r.   Ú!test_synchronousDeferredRecursion¬  s   z9FlattenIntegrationTests.test_synchronousDeferredRecursionc                 C   ó   |   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©r7   ÚAssertionErrorr   r:   r-   r-   r.   Útest_errorToplevelAttr³  ó
   ýz.FlattenIntegrationTests.test_errorToplevelAttrc                 C   r»   )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:   r-   r-   r.   Útest_errorUnnamedAttrÂ  r¿   z-FlattenIntegrationTests.test_errorUnnamedAttrc                 C   s(   d}t t|ƒd�}|  || 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   ZassertFlattensTor�   )r+   ZtheInputrG   r-   r-   r.   Útest_lenientPrefixBehaviorÏ  s   ÿz2FlattenIntegrationTests.test_lenientPrefixBehaviorc                 C   ó.   G dd„ dt ƒ}|tdƒd�}|  |d¡ dS )zi
        An Element with a render method which returns a Deferred will render
        correctly.
        c                   @   r]   )zHFlattenIntegrationTests.test_deferredRendering.<locals>.RenderfulElementr^   r,   r%   c                 S   s   t dƒS ©NrŠ   r´   r`   r-   r-   r.   ÚrenderMethodã  s   zUFlattenIntegrationTests.test_deferredRendering.<locals>.RenderfulElement.renderMethodN©	r@   rA   rB   r   r   r   r   r   rÄ   r-   r-   r-   r.   ÚRenderfulElementâ  ó    ÿÿþrÆ   úŸ
        <p xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1"
          t:render="renderMethod">
            Goodbye, world.
        </p>
        r¥   r°   Nr«   ©r+   rÆ   rG   r-   r-   r.   Útest_deferredRenderingÜ  ó   ÿÿ
z.FlattenIntegrationTests.test_deferredRenderingc                 C   s"   G d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                   @   s   e Zd ZedƒZdS )zEFlattenIntegrationTests.test_loaderClassAttribute.<locals>.SubElementr„   N)r@   rA   rB   r   ri   r-   r-   r-   r.   Ú
SubElementû  s    rÌ   r£   N)r   r¦   )r+   rÌ   r-   r-   r.   Útest_loaderClassAttributeõ  s   z1FlattenIntegrationTests.test_loaderClassAttributec                    s6   g ‰ G ‡ fdd„dt ƒ}|tdƒd�}|  |d¡ dS )z�
        An Element with a valid render directive has that directive invoked and
        the result added to the output.
        c                       ó.   e Zd Zedee dedef‡ fdd„ƒZdS )zIFlattenIntegrationTests.test_directiveRendering.<locals>.RenderfulElementr^   r,   r%   c                    s   ˆ   | |f¡ |dƒS rÃ   )Úappendr`   ©Zrendersr-   r.   rÄ     s   zVFlattenIntegrationTests.test_directiveRendering.<locals>.RenderfulElement.renderMethodNrÅ   r-   rÐ   r-   r.   rÆ     s    ÿÿþrÆ   úx
        <p xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1"
          t:render="renderMethod" />
        r¥   r£   Nr«   rÉ   r-   rÐ   r.   Útest_directiveRendering   s   ÿÿz/FlattenIntegrationTests.test_directiveRenderingc                 C   rÂ   )z‡
        An Element with a render method which omits the containing tag
        successfully removes that tag from the output.
        c                   @   r]   )zTFlattenIntegrationTests.test_directiveRenderingOmittingTag.<locals>.RenderfulElementr^   r,   r%   c                 S   rL   rÃ   r-   r`   r-   r-   r.   rÄ      s   zaFlattenIntegrationTests.test_directiveRenderingOmittingTag.<locals>.RenderfulElement.renderMethodNrÅ   r-   r-   r-   r.   rÆ     rÇ   rÆ   rÈ   r¥   r°   Nr«   rÉ   r-   r-   r.   Ú"test_directiveRenderingOmittingTag  rË   z:FlattenIntegrationTests.test_directiveRenderingOmittingTagc                 C   rÂ   )út
        An Element which is returned by the render method of another Element is
        rendered properly.
        c                   @   r]   )zUFlattenIntegrationTests.test_elementContainingStaticElement.<locals>.RenderfulElementr^   r,   r%   c                 S   s   |t tdƒd�ƒS )Nz<em>Hello, world.</em>r¥   )r   r   r`   r-   r-   r.   rÄ   9  s   zbFlattenIntegrationTests.test_elementContainingStaticElement.<locals>.RenderfulElement.renderMethodNrÅ   r-   r-   r-   r.   rÆ   8  rÇ   rÆ   rÑ   r¥   s   <p><em>Hello, world.</em></p>Nr«   rÉ   r-   r-   r.   Ú#test_elementContainingStaticElement2  s   ÿÿz;FlattenIntegrationTests.test_elementContainingStaticElementc                 C   rÂ   )rÔ   c                   @   r]   )zHFlattenIntegrationTests.test_elementUsingSlots.<locals>.RenderfulElementr^   r,   r%   c                 S   s   |j dd�S )Nzworld.)Ztest2)Z	fillSlotsr`   r-   r-   r.   rÄ   P  ó   zUFlattenIntegrationTests.test_elementUsingSlots.<locals>.RenderfulElement.renderMethodNrÅ   r-   r-   r-   r.   rÆ   O  rÇ   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É   r-   r-   r.   Útest_elementUsingSlotsI  s   ÿÿ	z.FlattenIntegrationTests.test_elementUsingSlotsc                    sB   G ‡ fdd„dt ƒ}G dd„ dt ƒ‰ |tdƒ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                       rÎ   )zRFlattenIntegrationTests.test_elementContainingDynamicElement.<locals>.OuterElementr^   r,   r%   c                    s   |ˆ t dƒd�ƒS )Nz©
                <t:ignored
                  xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1"
                  t:render="innerMethod" />
                r¥   )r   r`   ©ÚInnerElementr-   r.   ÚouterMethodi  s   ÿÿÿz^FlattenIntegrationTests.test_elementContainingDynamicElement.<locals>.OuterElement.outerMethodN)	r@   rA   rB   r   r   r   r   r   rÚ   r-   rØ   r-   r.   ÚOuterElementh  s    $rÛ   c                   @   r]   )zRFlattenIntegrationTests.test_elementContainingDynamicElement.<locals>.InnerElementr^   r,   r%   c                 S   rL   rÃ   r-   r`   r-   r-   r.   ÚinnerMethodx  ra   z^FlattenIntegrationTests.test_elementContainingDynamicElement.<locals>.InnerElement.innerMethodN)	r@   rA   rB   r   r   r   r   r   rÜ   r-   r-   r-   r.   rÙ   w  rc   rÙ   zw
        <p xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1"
          t:render="outerMethod" />
        r¥   r£   Nr«   )r+   rÛ   rG   r-   rØ   r.   Ú$test_elementContainingDynamicElementa  s   ÿÿz<FlattenIntegrationTests.test_elementContainingDynamicElementc                    sR   t dƒ‰G ‡ ‡fd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                       sX   e Zd ZdZdZ”Zedee de	de
f‡ fdd„ƒZedee de	de
fdd„ƒZd	S )
zHFlattenIntegrationTests.test_sameLoaderTwice.<locals>.DestructiveElementr   r^   r,   r%   c                    s   ˆ  j d7  _ |tˆ j ƒƒS ©Nrˆ   )ÚcountrR   r`   )ÚDestructiveElementr-   r.   ÚclassCounter—  ó   zUFlattenIntegrationTests.test_sameLoaderTwice.<locals>.DestructiveElement.classCounterc                 S   s   |  j d7  _ |t| j ƒƒS rÞ   )ÚinstanceCountrR   r`   r-   r-   r.   ÚinstanceCounterž  râ   zXFlattenIntegrationTests.test_sameLoaderTwice.<locals>.DestructiveElement.instanceCounterN)r@   rA   rB   rß   rã   ri   r   r   r   r   r   rá   rä   r-   ©rà   ZsharedLoaderr-   r.   rà   ’  s(    ÿÿþÿÿþrà   s
   <p>1 1</p>s
   <p>2 2</p>s
   <p>3 1</p>N)r   r   r¦   )r+   Úe1Úe2r-   rå   r.   Útest_sameLoaderTwice†  s   ÿz,FlattenIntegrationTests.test_sameLoaderTwicer?   )r@   rA   rB   rC   r©   r­   rJ   r¯   r±   r²   rº   r¾   rÀ   rÁ   rÊ   rÍ   rÒ   rÓ   rÕ   r×   rÝ   rè   r-   r-   r-   r.   r¢   V  s(    
















%r¢   c                   @   s8   e Zd ZdZddd„Zddd„Zddd	„Zdd
d„ZdS )ÚTagLoaderTestsz!
    Tests for L{TagLoader}.
    r%   Nc                 C   s   t t d¡ƒ| _d S )NÚtest)r   r   r¶   ri   r:   r-   r-   r.   ÚsetUp±  s   zTagLoaderTests.setUpc                 C   s   |   tt| jƒ¡ dS )zJ
        An instance of L{TagLoader} provides L{ITemplateLoader}.
        N)Ú
assertTruer   r   ri   r:   r-   r-   r.   Útest_interface´  ó   zTagLoaderTests.test_interfacec                 C   s   |   | j ¡ t¡ dS )zK
        L{TagLoader.load} returns a list, per L{ITemplateLoader}.
        N)ÚassertIsInstanceri   rg   Úlistr:   r-   r-   r.   Útest_loadsListº  rî   zTagLoaderTests.test_loadsListc                 C   s   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   ri   r¦   )r+   Úer-   r-   r.   Útest_flattenÀ  s   
zTagLoaderTests.test_flattenr?   )r@   rA   rB   rC   rë   rí   rñ   ró   r-   r-   r-   r.   ré   ¬  s    


ré   c                   @   s   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)r@   rA   rB   rC   r   ri   r-   r-   r-   r.   rô   É  s
    ÿrô   c                   @   s0   e Zd ZdZedƒZd	dededdfd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Úfailureri   r%   c                 C   s
   || _ d S r…   )rö   )r+   rö   ri   r-   r-   r.   Ú__init__á  s   
zTestFailureElement.__init__r…   )	r@   rA   rB   rC   r   ri   r   Úobjectr÷   r-   r-   r-   r.   rõ   Õ  s    ÿrõ   c                   @   s&   e Zd ZdZdee ddfdd„ZdS )ÚFailingElementz<
    An element that raises an exception when rendered.
    r^   r%   r   c                 C   s   d}d}|| › S )Né*   r   r-   )r+   r^   r'   Úbr-   r-   r.   rE   ê  s   
zFailingElement.renderN)r@   rA   rB   rC   r   r   rE   r-   r-   r-   r.   rù   å  s    rù   c                   @   s   e Zd ZdZdZdS )ÚFakeSitezL
    A minimal L{Site} object that we can use to test displayTracebacks
    FN)r@   rA   rB   rC   ÚdisplayTracebacksr-   r-   r-   r.   rü   ð  s    rü   c                       s"   e Zd ZdZd‡ fdd„Z‡  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                    s   t ƒ  dg¡ tƒ | _d S )Nó    )Úsuperr÷   rü   Úsiter:   ©Ú	__class__r-   r.   r÷     s   zDummyRenderRequest.__init__r?   )r@   rA   rB   rC   r÷   Ú__classcell__r-   r-   r  r.   rþ   ø  s    rþ   c                   @   st   e Zd ZdZddd„Zded fdd„Zded fdd	„Zded fd
d„Zded fdd„Z	ded fdd„Z
dS )ÚRenderElementTestsz
    Test L{renderElement}
    r%   Nc                 C   s   t ƒ | _dS )z8
        Set up a common L{DummyRenderRequest}.
        N)rþ   r^   r:   r-   r-   r.   rë     rÖ   zRenderElementTests.setUpc                    óH   t ƒ }ˆ j ¡ }dtddf‡ fd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                    s(   ˆ   d ˆ jj¡d¡ ˆ  ˆ jj¡ d S )Nrÿ   s$   <!DOCTYPE html>
<p>Hello, world.</p>)r(   Újoinr^   Úwrittenrì   Úfinished©r  r:   r-   r.   Úcheck  s
   þz3RenderElementTests.test_simpleRender.<locals>.check)rô   r^   ÚnotifyFinishrø   ÚaddCallbackrF   r   r   ©r+   rG   Údr  r-   r:   r.   Útest_simpleRender  s   

z$RenderElementTests.test_simpleRenderc                    r  )z
        L{renderElement} handles failures by writing a minimal
        error message to the request and finishing it.
        r  r%   Nc                    sB   ˆ   t¡}ˆ  t|ƒd¡ ˆ  d ˆ jj¡d¡ ˆ  ˆ jj¡ d S )Nrˆ   rÿ   s‚   <!DOCTYPE html>
<div style="font-size:800%;background-color:#FFF;color:#F00">An error occurred while rendering the response.</div>)	ÚflushLoggedErrorsr   r(   rŒ   r  r^   r	  rì   r
  )r  Úflushedr:   r-   r.   r  1  s   
ý
z4RenderElementTests.test_simpleFailure.<locals>.check)rù   r^   r  rø   r  rF   r   r   r  r-   r:   r.   Útest_simpleFailure(  s   

z%RenderElementTests.test_simpleFailurec                    s\   t  ˆt¡‰ dˆjj_tƒ }ˆj ¡ }dtddf‡ ‡fdd„}| 	|¡ t
ˆj|td� |S )z˜
        L{renderElement} will render a traceback when rendering of
        the element fails and our site is configured to display tracebacks.
        Tr  r%   Nc                    sl   ˆ  dtˆ ƒ¡ ˆ d d }ˆ |jt¡ ˆ t¡}ˆ t|ƒd¡ ˆ d ˆjj	¡d¡ ˆ 
ˆjj¡ d S )Nrˆ   r   Zlog_failurerÿ   s    <!DOCTYPE html>
<p>I failed.</p>)ZassertEqualsrŒ   rï   Úvaluer   r  r(   r  r^   r	  rì   r
  )r  Úfr  ©ZlogObserverr+   r-   r.   r  R  s   
ÿzARenderElementTests.test_simpleFailureWithTraceback.<locals>.check)Z_failElement)r	   ZcreateWithCleanupr
   r^   r  rý   rù   r  rø   r  r   rõ   r  r-   r  r.   Útest_simpleFailureWithTracebackF  s   


z2RenderElementTests.test_simpleFailureWithTracebackc                    sD   t ƒ }ˆ j ¡ }dtddf‡ fdd„}| |¡ tˆ j|dd� |S )zs
        L{renderElement} will write the doctype string specified by the
        doctype keyword argument.
        r  r%   Nc                    ó   ˆ   d ˆ jj¡d¡ d S )Nrÿ   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(   r  r^   r	  r  r:   r-   r.   r  l  s   ýz8RenderElementTests.test_nonDefaultDoctype.<locals>.checksm   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">©Údoctype©rô   r^   r  rø   r  r   r  r-   r:   r.   Útest_nonDefaultDoctypec  s   


ü	z)RenderElementTests.test_nonDefaultDoctypec                    sD   t ƒ }ˆ j ¡ }dtddf‡ fdd„}| |¡ tˆ j|dd� |S )zs
        L{renderElement} will not write out a doctype if the doctype keyword
        argument is L{None}.
        r  r%   Nc                    r  )Nrÿ   r£   r  r  r:   r-   r.   r  Œ  s   z2RenderElementTests.test_noneDoctype.<locals>.checkr  r  r  r-   r:   r.   Útest_noneDoctypeƒ  s   

z#RenderElementTests.test_noneDoctyper?   )r@   rA   rB   rC   rë   r   r  r  r  r  r  r-   r-   r-   r.   r    s    
 r  )FrC   rp   Úior   Útypingr   r   Zzope.interfacer   Zzope.interface.verifyr   Ztwisted.internet.deferr   r   Ztwisted.internet.testingr	   Ztwisted.loggerr
   Ztwisted.python.failurer   Ztwisted.python.filepathr   Ztwisted.trial.unittestr   Ztwisted.trial.utilr   ZSUPPRESSZtwisted.web._elementr   Ztwisted.web.errorr   r   r   Ztwisted.web.iwebr   r   Ztwisted.web.serverr   Ztwisted.web.templater   r   r   r   r   r   r   r   r   Ztwisted.web.test._utilr   Ztwisted.web.test.test_webr    r�   r�   r$   rD   rv   r‚   r–   r™   r    r¡   r¢   ré   rô   rõ   rù   rü   rþ   r  r-   r-   r-   r.   Ú<module>   sV   ,þ,h5  X