HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/web/test/__pycache__/test_template.cpython-38.pyc
U


W[ye�@s�dZddlmZmZddlmZddlmZmZddl	m
Z
ddlmZddl
mZddlmZmZmZmZmZmZdd	lmZdd
lmZmZmZddlmZddlmZdd
l m!Z!ddl"m#Z#ddl$m%Z%ddl&m'Z(ddl)m*Z*ddl+m,Z,ee-dd�Z.Gdd�de�Z/Gdd�de�Z0Gdd�de�Z1Gdd�de2�Z3Gdd�dee3�Z4Gdd �d ee3�Z5Gd!d"�d"ee3�Z6Gd#d$�d$ee3�Z7Gd%d&�d&e!�Z8Gd'd(�d(e!�Z9Gd)d*�d*e�Z:Gd+d,�d,e�Z;Gd-d.�d.e�Z<Gd/d0�d0e2�Z=Gd1d2�d2e�Z>d3S)4z#
Tests for L{twisted.web.template}
�)�division�absolute_import)�verifyObject)�succeed�
gatherResults)�FilePath)�TestCase)�suppress)�Element�	TagLoader�renderer�tags�XMLFile�	XMLString)�ITemplateLoader)�FlattenerError�MissingTemplateLoader�MissingRenderMethod)�
renderElement)�UnexposedMethodError)�FlattenTestCase)�DummyRequest)�NOT_DONE_YET)�NativeStringIO)�globalLogPublisher)�EventLoggingObserver�hPassing filenames or file objects to XMLFile is deprecated since Twisted 12.1.  Pass a FilePath instead.)�category�messagec@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�TagFactoryTestszO
    Tests for L{_TagFactory} through the publicly-exposed L{tags} object.
    cCstj}|�|jd�dS)z=
        HTML tags can be retrieved through C{tags}.
        �aN)r
r �assertEqual�tagName��self�tag�r&�@/usr/lib/python3/dist-packages/twisted/web/test/test_template.py�test_lookupTag+szTagFactoryTests.test_lookupTagcCstj}|�|jd�dS)zj
        Twisted supports the latest and greatest HTML tags from the HTML5
        specification.
        �videoN)r
r)r!r"r#r&r&r'�test_lookupHTML5Tag3sz#TagFactoryTests.test_lookupHTML5TagcCstj}|�|jd�dS)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
Ztransparentr!r"r#r&r&r'�test_lookupTransparentTag<sz)TagFactoryTests.test_lookupTransparentTagcCs|�tttd�dS)zv
        Invalid tags which are not part of HTML cause AttributeErrors when
        accessed through C{tags}.
        ZinvalidN��assertRaises�AttributeError�getattrr
�r$r&r&r'�test_lookupInvalidTagFsz%TagFactoryTests.test_lookupInvalidTagcCs|�tttd�dS)z�
        As a special case, the <xmp> tag is simply not available through
        C{tags} or any other part of the templating machinery.
        ZxmpNr-r1r&r&r'�test_lookupXMPNszTagFactoryTests.test_lookupXMPN)	�__name__�
__module__�__qualname__�__doc__r(r*r,r2r3r&r&r&r'r's	
rc@sPeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�ElementTestsz5
    Tests for the awesome new L{Element} class.
    cCs(t�}|�t|jd�}|�|j|�dS)zr
        L{Element.render} raises L{MissingTemplateLoader} if the C{loader}
        attribute is L{None}.
        N)r
r.r�render�assertIdentical�element�r$r;�errr&r&r'�test_missingTemplateLoader[sz'ElementTests.test_missingTemplateLoadercCs*Gdd�dt�}|�dtt|����dS)zT
        A L{MissingTemplateLoader} instance can be repr()'d without error.
        c@seZdZdd�ZdS)zFElementTests.test_missingTemplateLoaderRepr.<locals>.PrettyReprElementcSsdS�N�Pretty Repr Elementr&r1r&r&r'�__repr__jszOElementTests.test_missingTemplateLoaderRepr.<locals>.PrettyReprElement.__repr__N�r4r5r6rAr&r&r&r'�PrettyReprElementisrCr@N)r
�assertIn�reprr)r$rCr&r&r'�test_missingTemplateLoaderRepres�z+ElementTests.test_missingTemplateLoaderReprcCs6t�}|�t|jd�}|�|j|�|�|jd�dS)z�
        When called with the name which is not associated with a render method,
        L{Element.lookupRenderMethod} raises L{MissingRenderMethod}.
        �fooN)r
r.r�lookupRenderMethodr:r;r!Z
renderNamer<r&r&r'�test_missingRendererMethodps�z'ElementTests.test_missingRendererMethodcCs<Gdd�dt�}tt|�d��}|�d|�|�d|�dS)zR
        A L{MissingRenderMethod} instance can be repr()'d without error.
        c@seZdZdd�ZdS)zDElementTests.test_missingRenderMethodRepr.<locals>.PrettyReprElementcSsdSr?r&r1r&r&r'rA�szMElementTests.test_missingRenderMethodRepr.<locals>.PrettyReprElement.__repr__NrBr&r&r&r'rC�srCZexpectedMethodr@N)r
rErrD)r$rC�sr&r&r'�test_missingRenderMethodRepr|s�z)ElementTests.test_missingRenderMethodReprcCs2Gdd�dt�}|��d�}|�|dd�d�dS)z�
        When called with the name of a defined render method,
        L{Element.lookupRenderMethod} returns that render method.
        c@seZdZedd��ZdS)zBElementTests.test_definedRenderer.<locals>.ElementWithRenderMethodcSsdS)N�barr&�r$�requestr%r&r&r'rG�szFElementTests.test_definedRenderer.<locals>.ElementWithRenderMethod.fooN)r4r5r6rrGr&r&r&r'�ElementWithRenderMethod�srOrGNrL)r
rHr!)r$rOrGr&r&r'�test_definedRenderer�sz!ElementTests.test_definedRenderercs@Gdd�dt��G�fdd�dt�}|�}|�|�d�d�dS)zi
        L{Element.render} loads a document from the C{loader} attribute and
        returns it.
        c@seZdZdd�ZdS)z0ElementTests.test_render.<locals>.TemplateLoadercSsdS)N�resultr&r1r&r&r'�load�sz5ElementTests.test_render.<locals>.TemplateLoader.loadN)r4r5r6rRr&r&r&r'�TemplateLoader�srScseZdZ��ZdS)z-ElementTests.test_render.<locals>.StubElementN)r4r5r6�loaderr&�rSr&r'�StubElement�srVNrQ)�objectr
r!r9)r$rVr;r&rUr'�test_render�szElementTests.test_rendercCs |�tt�}|�t|�d�dS)z�
        If the L{renderer} decorator  is called without any arguments, it will
        raise a comprehensible exception.
        z,expose() takes at least 1 argument (0 given)N)r.�	TypeErrorrr!�str)r$Zter&r&r'�test_misuseRenderer�s
�z ElementTests.test_misuseRenderercCs|�ttjdd�dS)z�
        Called directly, without a default, L{renderer.get} raises
        L{UnexposedMethodError} when it cannot find a renderer.
        NZnotARenderer)r.rr�getr1r&r&r'�test_renderGetDirectlyError�s�z(ElementTests.test_renderGetDirectlyErrorN)r4r5r6r7r>rFrIrKrPrXr[r]r&r&r&r'r8Ws



r8c@s8eZdZdZdd�Zdd�Zege_dd�Zege_dS)	�XMLFileReprTestszB
    Tests for L{twisted.web.template.XMLFile}'s C{__repr__}.
    cCs&td�}|�d|ftt|���dS)zK
        An L{XMLFile} with a L{FilePath} returns a useful repr().
        �
/tmp/fake.xml�<XMLFile of %r>N)rr!rEr)r$�pathr&r&r'�
test_filePath�szXMLFileReprTests.test_filePathcCs"d}|�d|ftt|���dS)zH
        An L{XMLFile} with a filename returns a useful repr().
        r_r`N)r!rEr)r$�fnamer&r&r'�
test_filename�szXMLFileReprTests.test_filenamecCs&td�}|�d|ftt|���dS)zK
        An L{XMLFile} with a file object returns a useful repr().
        znot xmlr`N)�StringIOr!rEr)r$Zfobjr&r&r'�	test_file�szXMLFileReprTests.test_fileN)	r4r5r6r7rbrd�_xmlFileSuppressr	rfr&r&r&r'r^�sr^c@s0eZdZdZdZdZdd�Zdd�Zege_	dS)�XMLLoaderTestsMixinz�
    @ivar templateString: Simple template to use to exercise the loaders.

    @ivar deprecatedUse: C{True} if this use of L{XMLFile} is deprecated and
        should emit a C{DeprecationWarning}.
    N�<p>Hello, world.</p>cCs�|��}|��\}|j|jgd�}|jrb|�t|�d�|�|ddt�|�|ddd�n|�t|�d�|�|jd�|�|jdg�d	S)
zQ
        Verify that the loader returns a tag with the correct children.
        )ZoffendingFunctions�rrrr�p�
Hello, world.N)	�
loaderFactoryrRZ
flushWarnings�
deprecatedUser!�len�DeprecationWarningr"Zchildren)r$rTr%�warningsr&r&r'�	test_load�s

�zXMLLoaderTestsMixin.test_loadcCs(|��}|��}|��}|�||�dS)zd
        If {load()} can be called on a loader twice the result should be the
        same.
        N)rmrRr!)r$rTZtags1Ztags2r&r&r'�test_loadTwice�sz"XMLLoaderTestsMixin.test_loadTwice)
r4r5r6r7rm�templateStringrrrsrgr	r&r&r&r'rh�s	rhc@seZdZdZdZdd�ZdS)�XMLStringLoaderTestsz5
    Tests for L{twisted.web.template.XMLString}
    FcCs
t|j�S)zS
        @return: an L{XMLString} constructed with C{self.templateString}.
        )rrtr1r&r&r'rmsz"XMLStringLoaderTests.loaderFactoryN�r4r5r6r7rnrmr&r&r&r'rusruc@seZdZdZdZdd�ZdS)�XMLFileWithFilePathTestszJ
    Tests for L{twisted.web.template.XMLFile}'s L{FilePath} support.
    FcCs&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�
setContentrt�encoder�r$�fpr&r&r'rmsz&XMLFileWithFilePathTests.loaderFactoryNrvr&r&r&r'rwsrwc@seZdZdZdZdd�ZdS)�XMLFileWithFileTestszU
    Tests for L{twisted.web.template.XMLFile}'s deprecated file object support.
    TcCstt|j��S)z{
        @return: an L{XMLString} constructed with a file object that contains
            C{self.templateString}.
        )rrertr1r&r&r'rm(sz"XMLFileWithFileTests.loaderFactoryNrvr&r&r&r'r~#sr~c@seZdZdZdZdd�ZdS)�XMLFileWithFilenameTestszR
    Tests for L{twisted.web.template.XMLFile}'s deprecated filename support.
    TcCs(t|���}|�|j�d��t|j�S)z�
        @return: an L{XMLString} constructed with a filename that points to a
            file containing C{self.templateString}.
        rx)rryrzrtr{rrar|r&r&r'rm6sz&XMLFileWithFilenameTests.loaderFactoryNrvr&r&r&r'r1src@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$S)%�FlattenIntegrationTestsz[
    Tests for integration between L{Element} and
    L{twisted.web._flatten.flatten}.
    cs*ddddddg}�fdd�|D�}t|�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>cs"g|]}��tt|�d�|��qS)�rT)�assertFlattensTor
r)�.0Zxmlr1r&r'�
<listcomp>Vs�z:FlattenIntegrationTests.test_roundTrip.<locals>.<listcomp>)r)r$Z	fragmentsZ	deferredsr&r1r'�test_roundTripGs�	
�z&FlattenIntegrationTests.test_roundTripcCsttd�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��r
rr��r$r;r&r&r'�test_entityConversion\sz-FlattenIntegrationTests.test_entityConversioncCs|�t�t�S)zk
        Rendering an Element without a loader attribute raises the appropriate
        exception.
        )�assertFlatteningRaisesr
rr1r&r&r'r>esz2FlattenIntegrationTests.test_missingTemplateLoadercCsttd�d�}|�|t�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�)r
rr�rr�r&r&r'�test_missingRenderMethodmsz0FlattenIntegrationTests.test_missingRenderMethodcCsttd�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.r�r�r&r&r'�test_transparentRenderingzs�z1FlattenIntegrationTests.test_transparentRenderingcCsttd�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>r�r�r&r&r'�test_attrRendering�s��z*FlattenIntegrationTests.test_attrRenderingcCs|�ttd�dS)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.�AssertionErrorrr1r&r&r'�test_errorToplevelAttr�s
�z.FlattenIntegrationTests.test_errorToplevelAttrcCs|�ttd�dS)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�r1r&r&r'�test_errorUnnamedAttr�s
�z-FlattenIntegrationTests.test_errorUnnamedAttrcCs(d}tt|�d�}|�||�d��dS)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�rxN)r
rr�r{)r$ZtheInputr;r&r&r'�test_lenientPrefixBehavior�s�z2FlattenIntegrationTests.test_lenientPrefixBehaviorcCs*Gdd�dt�}|td�d�}|�|d�S)zi
        An Element with a render method which returns a Deferred will render
        correctly.
        c@seZdZedd��ZdS)zHFlattenIntegrationTests.test_deferredRendering.<locals>.RenderfulElementcSstd�S�Nrl)rrMr&r&r'�renderMethod�szUFlattenIntegrationTests.test_deferredRendering.<locals>.RenderfulElement.renderMethodN�r4r5r6rr�r&r&r&r'�RenderfulElement�sr���
        <p xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1"
          t:render="renderMethod">
            Goodbye, world.
        </p>
        r�r�r��r$r�r;r&r&r'�test_deferredRendering�sz.FlattenIntegrationTests.test_deferredRenderingcCsGdd�dt�}|�|�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@seZdZed�ZdS)zEFlattenIntegrationTests.test_loaderClassAttribute.<locals>.SubElementriN)r4r5r6rrTr&r&r&r'�
SubElement�sr�r�)r
r�)r$r�r&r&r'�test_loaderClassAttribute�sz1FlattenIntegrationTests.test_loaderClassAttributecs2g�G�fdd�dt�}|td�d�}|�|d�S)z�
        An Element with a valid render directive has that directive invoked and
        the result added to the output.
        cseZdZe�fdd��ZdS)zIFlattenIntegrationTests.test_directiveRendering.<locals>.RenderfulElementcs��||f�|d�Sr�)�appendrM�Zrendersr&r'r��szVFlattenIntegrationTests.test_directiveRendering.<locals>.RenderfulElement.renderMethodNr�r&r�r&r'r��sr��x
        <p xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1"
          t:render="renderMethod" />
        r�r�r�r�r&r�r'�test_directiveRendering�sz/FlattenIntegrationTests.test_directiveRenderingcCs*Gdd�dt�}|td�d�}|�|d�S)z�
        An Element with a render method which omits the containing tag
        successfully removes that tag from the output.
        c@seZdZedd��ZdS)zTFlattenIntegrationTests.test_directiveRenderingOmittingTag.<locals>.RenderfulElementcSsdSr�r&rMr&r&r'r��szaFlattenIntegrationTests.test_directiveRenderingOmittingTag.<locals>.RenderfulElement.renderMethodNr�r&r&r&r'r��sr�r�r�r�r�r�r&r&r'�"test_directiveRenderingOmittingTag�sz:FlattenIntegrationTests.test_directiveRenderingOmittingTagcCs*Gdd�dt�}|td�d�}|�|d�S)�t
        An Element which is returned by the render method of another Element is
        rendered properly.
        c@seZdZedd��ZdS)zUFlattenIntegrationTests.test_elementContainingStaticElement.<locals>.RenderfulElementcSs|ttd�d��S)Nz<em>Hello, world.</em>r�)r
rrMr&r&r'r�s�zbFlattenIntegrationTests.test_elementContainingStaticElement.<locals>.RenderfulElement.renderMethodNr�r&r&r&r'r�sr�r�r�s<p><em>Hello, world.</em></p>r�r�r&r&r'�#test_elementContainingStaticElementsz;FlattenIntegrationTests.test_elementContainingStaticElementcCs*Gdd�dt�}|td�d�}|�|d�S)r�c@seZdZedd��ZdS)zHFlattenIntegrationTests.test_elementUsingSlots.<locals>.RenderfulElementcSs|jdd�S)Nzworld.)Ztest2)Z	fillSlotsrMr&r&r'r�szUFlattenIntegrationTests.test_elementUsingSlots.<locals>.RenderfulElement.renderMethodNr�r&r&r&r'r�sr�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�r�r�r&r&r'�test_elementUsingSlotss
�z.FlattenIntegrationTests.test_elementUsingSlotscs>G�fdd�dt�}Gdd�dt��|td�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.
        cseZdZe�fdd��ZdS)zRFlattenIntegrationTests.test_elementContainingDynamicElement.<locals>.OuterElementcs|�td�d��S)Nz�
                <t:ignored
                  xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1"
                  t:render="innerMethod" />
                r�)rrM��InnerElementr&r'�outerMethod+sz^FlattenIntegrationTests.test_elementContainingDynamicElement.<locals>.OuterElement.outerMethodN)r4r5r6rr�r&r�r&r'�OuterElement*sr�c@seZdZedd��ZdS)zRFlattenIntegrationTests.test_elementContainingDynamicElement.<locals>.InnerElementcSsdSr�r&rMr&r&r'�innerMethod3sz^FlattenIntegrationTests.test_elementContainingDynamicElement.<locals>.InnerElement.innerMethodN)r4r5r6rr�r&r&r&r'r�2sr�zw
        <p xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1"
          t:render="outerMethod" />
        r�r�r�)r$r�r;r&r�r'�$test_elementContainingDynamicElement$sz<FlattenIntegrationTests.test_elementContainingDynamicElementcsRtd��G��fdd�dt����}��}|�|d�|�|d�|�|d�dS)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>cs4eZdZdZdZ�Ze�fdd��Zedd��ZdS)zHFlattenIntegrationTests.test_sameLoaderTwice.<locals>.DestructiveElementrcs�jd7_|t�j��S�Nrj)�countrZrM)�DestructiveElementr&r'�classCounterMszUFlattenIntegrationTests.test_sameLoaderTwice.<locals>.DestructiveElement.classCountercSs|jd7_|t|j��Sr�)�
instanceCountrZrMr&r&r'�instanceCounterQszXFlattenIntegrationTests.test_sameLoaderTwice.<locals>.DestructiveElement.instanceCounterN)	r4r5r6r�r�rTrr�r�r&�r�ZsharedLoaderr&r'r�Hsr�s
<p>1 1</p>s
<p>2 2</p>s
<p>3 1</p>N)rr
�assertFlattensImmediately)r$Ze1Ze2r&r�r'�test_sameLoaderTwice=s�z,FlattenIntegrationTests.test_sameLoaderTwiceN)r4r5r6r7r�r�r>r�r�r�r�r�r�r�r�r�r�r�r�r�r�r&r&r&r'r�As$	



r�c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�TagLoaderTestsz!
    Tests for L{TagLoader}.
    cCstt�d��|_dS)NZtest)rr
�irTr1r&r&r'�setUpbszTagLoaderTests.setUpcCs|�tt|j��dS)zJ
        An instance of L{TagLoader} provides L{ITemplateLoader}.
        N)�
assertTruerrrTr1r&r&r'�test_interfacefszTagLoaderTests.test_interfacecCs|�|j��t�dS)zK
        L{TagLoader.load} returns a list, per L{ITemplateLoader}.
        N)�assertIsInstancerTrR�listr1r&r&r'�test_loadsListmszTagLoaderTests.test_loadsListcCst|j�}|�|d�dS)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
rTr�)r$�er&r&r'�test_flattents
zTagLoaderTests.test_flattenN)r4r5r6r7r�r�r�r�r&r&r&r'r�^s
r�c@seZdZdZed�ZdS)�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)r4r5r6r7rrTr&r&r&r'r�~s�r�c@s"eZdZdZed�Zddd�ZdS)�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>NcCs
||_dS)N)�failure)r$r�rTr&r&r'�__init__�szTestFailureElement.__init__)N)r4r5r6r7rrTr�r&r&r&r'r��s
�r�c@seZdZdZdd�ZdS)�FailingElementz<
    An element that raises an exception when rendered.
    cCsd}d}||S)N�*rr&)r$rNr �br&r&r'r9�szFailingElement.renderN)r4r5r6r7r9r&r&r&r'r��sr�c@seZdZdZdZdS)�FakeSitezL
    A minimal L{Site} object that we can use to test displayTracebacks
    FN)r4r5r6r7�displayTracebacksr&r&r&r'r��sr�c@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�RenderElementTestsz
    Test L{renderElement}
    cCstdg�|_t�|j_dS)zB
        Set up a common L{DummyRequest} and L{FakeSite}.
        r+N)rrNr��siter1r&r&r'r��szRenderElementTests.setUpcs>t�}�j��}�fdd�}|�|���tt�j|��|S)z�
        L{renderElement} returns NOT_DONE_YET and eventually
        writes the rendered L{Element} to the request before finishing the
        request.
        cs(��d��jj�d����jj�dS)N�s$<!DOCTYPE html>
<p>Hello, world.</p>)r!�joinrN�writtenr��finished��_r1r&r'�check�s
�z3RenderElementTests.test_simpleRender.<locals>.check)r�rN�notifyFinish�addCallbackr:rr�r$r;�dr�r&r1r'�test_simpleRender�s

z$RenderElementTests.test_simpleRendercs>t�}�j��}�fdd�}|�|���tt�j|��|S)z
        L{renderElement} handles failures by writing a minimal
        error message to the request and finishing it.
        csB��t�}��t|�d���d��jj�d����jj�dS)Nrjr�s�<!DOCTYPE html>
<div style="font-size:800%;background-color:#FFF;color:#F00">An error occurred while rendering the response.</div>)	�flushLoggedErrorsrr!ror�rNr�r�r�)r��flushedr1r&r'r��s
�z4RenderElementTests.test_simpleFailure.<locals>.check)r�rNr�r�r:rrr�r&r1r'�test_simpleFailure�s

z%RenderElementTests.test_simpleFailurecsRt��t��d�jj_t�}�j��}��fdd�}|�|�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.
        Tcsl��dt����dd}��|jt���t�}��t|�d���d��jj	�d���
�jj�dS)NrjrZlog_failurer�s <!DOCTYPE html>
<p>I failed.</p>)ZassertEqualsror��valuerr�r!r�rNr�r�r�)r��fr��ZlogObserverr$r&r'r��s
�zARenderElementTests.test_simpleFailureWithTraceback.<locals>.check)Z_failElement)rZcreateWithCleanuprrNr�r�r�r�r�rr�r�r&r�r'�test_simpleFailureWithTraceback�s�


z2RenderElementTests.test_simpleFailureWithTracebackcs:t�}�j��}�fdd�}|�|�t�j|dd�|S)zs
        L{renderElement} will write the doctype string specified by the
        doctype keyword argument.
        cs��d��jj�d�dS)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�rNr�r�r1r&r'r�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">�Zdoctype�r�rNr�r�rr�r&r1r'�test_nonDefaultDoctype
s

�z)RenderElementTests.test_nonDefaultDoctypecs:t�}�j��}�fdd�}|�|�t�j|dd�|S)zs
        L{renderElement} will not write out a doctype if the doctype keyword
        argument is L{None}.
        cs��d��jj�d�dS)Nr�r�r�r�r1r&r'r�2s�z2RenderElementTests.test_noneDoctype.<locals>.checkNr�r�r�r&r1r'�test_noneDoctype)s

z#RenderElementTests.test_noneDoctypeN)
r4r5r6r7r�r�r�r�r�r�r&r&r&r'r��s!r�N)?r7Z
__future__rrZzope.interface.verifyrZtwisted.internet.deferrrZtwisted.python.filepathrZtwisted.trial.unittestrZtwisted.trial.utilr	ZSUPPRESSZtwisted.web.templater
rrr
rrZtwisted.web.iwebrZtwisted.web.errorrrrrZtwisted.web._elementrZtwisted.web.test._utilrZtwisted.web.test.test_webrZtwisted.web.serverrZtwisted.python.compatrreZtwisted.loggerrZtwisted.test.proto_helpersrrprgrr8r^rWrhrurwr~rr�r�r�r�r�r�r�r&r&r&r'�<module>sJ �0c-