%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3/dist-packages/twisted/web/test/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3/dist-packages/twisted/web/test/__pycache__/test_template.cpython-312.pyc

�

Ϫ�f�q���dZddlZddlmZddlmZmZddlmZddl	m
Z
ddlmZm
Z
ddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZmZm Z ddl!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/ddl0m1Z1ddl2m3Z3ee4d��Z5Gd�de�Z6Gd�de�Z7Gd�de�Z8Gd�d�Z9Gd�d ee9�Z:Gd!�d"ee9�Z;Gd#�d$ee9�Z<Gd%�d&ee9�Z=Gd'�d(e1�Z>Gd)�d*e1�Z?Gd+�d,e'�Z@Gd-�d.e'�ZAGd/�d0e'�ZBGd1�d2�ZCee"�Gd3�d4e3��ZDGd5�d6e�ZEy)7z#
Tests for L{twisted.web.template}
�N)�StringIO)�List�Optional)�implementer)�verifyObject)�Deferred�succeed)�EventLoggingObserver)�globalLogPublisher)�Failure)�FilePath)�TestCase)�suppress)�UnexposedMethodError)�FlattenerError�MissingRenderMethod�MissingTemplateLoader)�IRequest�ITemplateLoader)�NOT_DONE_YET)	�Element�Flattenable�Tag�	TagLoader�XMLFile�	XMLString�
renderElement�renderer�tags)�FlattenTestCase)�DummyRequest�hPassing filenames or file objects to XMLFile is deprecated since Twisted 12.1.  Pass a FilePath instead.)�category�messagec�8�eZdZdZdd�Zdd�Zdd�Zdd�Zdd�Zy)	�TagFactoryTestszO
    Tests for L{_TagFactory} through the publicly-exposed L{tags} object.
    Nc�\�tj}|j|jd�y)z=
        HTML tags can be retrieved through C{tags}.
        �aN)rr(�assertEqual�tagName��self�tags  �@/usr/lib/python3/dist-packages/twisted/web/test/test_template.py�test_lookupTagzTagFactoryTests.test_lookupTag4s!���f�f��������c�*�c�\�tj}|j|jd�y)zj
        Twisted supports the latest and greatest HTML tags from the HTML5
        specification.
        �videoN)rr2r)r*r+s  r.�test_lookupHTML5Tagz#TagFactoryTests.test_lookupHTML5Tag;s!��
�j�j��������g�.r0c�\�tj}|j|jd�y)z�
        To support transparent inclusion in templates, there is a special tag,
        the transparent tag, which has no name of its own but is accessed
        through the "transparent" attribute.
        �N)r�transparentr)r*r+s  r.�test_lookupTransparentTagz)TagFactoryTests.test_lookupTransparentTagCs#������������b�)r0c�D�|jtttd�y)zv
        Invalid tags which are not part of HTML cause AttributeErrors when
        accessed through C{tags}.
        �invalidN��assertRaises�AttributeError�getattrr�r,s r.�test_lookupInvalidTagz%TagFactoryTests.test_lookupInvalidTagLs��
	
���.�'�4��Cr0c�D�|jtttd�y)z�
        As a special case, the <xmp> tag is simply not available through
        C{tags} or any other part of the templating machinery.
        �xmpNr:r>s r.�test_lookupXMPzTagFactoryTests.test_lookupXMPSs��
	
���.�'�4��?r0��returnN)	�__name__�
__module__�__qualname__�__doc__r/r3r7r?rB�r0r.r&r&/s"���+�/�*�D�@r0r&c�P�eZdZdZdd�Zdd�Zdd�Zdd�Zdd�Zdd�Z	dd	�Z
dd
�Zy)�ElementTestsz5
    Tests for the awesome new L{Element} class.
    Nc��t�}|jt|jd�}|j	|j
|�y)zr
        L{Element.render} raises L{MissingTemplateLoader} if the C{loader}
        attribute is L{None}.
        N)rr;r�render�assertIdentical�element�r,rO�errs   r.�test_missingTemplateLoaderz'ElementTests.test_missingTemplateLoader`s8��
�)����� 5�w�~�~�t�L�����S�[�[�'�2r0c	�t�Gd�dt�}|jdtt|����y)zT
        A L{MissingTemplateLoader} instance can be repr()'d without error.
        c��eZdZdefd�Zy)�FElementTests.test_missingTemplateLoaderRepr.<locals>.PrettyReprElementrDc��y�N�Pretty Repr ElementrIr>s r.�__repr__zOElementTests.test_missingTemplateLoaderRepr.<locals>.PrettyReprElement.__repr__o���,r0N�rErFrG�strrYrIr0r.�PrettyReprElementrUn���
-�#�
-r0r]rXN)r�assertIn�reprr)r,r]s  r.�test_missingTemplateLoaderReprz+ElementTests.test_missingTemplateLoaderRepris0��
	-��	-�	
�
�
�!�4�(=�>O�>Q�(R�#S�	
r0c���t�}|jt|jd�}|j	|j
|�|j
|jd�y)z�
        When called with the name which is not associated with a render method,
        L{Element.lookupRenderMethod} raises L{MissingRenderMethod}.
        �fooN)rr;r�lookupRenderMethodrNrOr)�
renderNamerPs   r.�test_missingRendererMethodz'ElementTests.test_missingRendererMethodvsO��
�)����� 3�W�5O�5O�QV�W�����S�[�[�'�2��������/r0c��Gd�dt�}tt|�d��}|jd|�|jd|�y)zR
        A L{MissingRenderMethod} instance can be repr()'d without error.
        c��eZdZdefd�Zy)�DElementTests.test_missingRenderMethodRepr.<locals>.PrettyReprElementrDc��yrWrIr>s r.rYzMElementTests.test_missingRenderMethodRepr.<locals>.PrettyReprElement.__repr__�rZr0Nr[rIr0r.r]ri�r^r0r]�expectedMethodrXN)rr`rr_)r,r]�ss   r.�test_missingRenderMethodReprz)ElementTests.test_missingRenderMethodRepr�sE��
	-��	-�
�$�%6�%8�:J�K�L���
�
�+�Q�/��
�
�&��*r0c��Gd�dt�}|�jd�}|j|dtj�d�y)z�
        When called with the name of a defined render method,
        L{Element.lookupRenderMethod} returns that render method.
        c�0�eZdZedeededefd��Zy)�BElementTests.test_definedRenderer.<locals>.ElementWithRenderMethod�requestr-rDc��y)N�barrI�r,rqr-s   r.rczFElementTests.test_definedRenderer.<locals>.ElementWithRenderMethod.foo�s��r0N)	rErFrGrrrrrrcrIr0r.�ElementWithRenderMethodrp�s.��
�
�8�H�#5�
�C�
�K�
��
r0rurcNrs)rrdr)r�br)r,rurcs   r.�test_definedRendererz!ElementTests.test_definedRenderer�s>��	�g�	�
&�'�:�:�5�A������T�4�7�7�+�U�3r0c���tt�Gd�d���G�fd�dt�}|�}|j|j	d�dg�y)zi
        L{Element.render} loads a document from the C{loader} attribute and
        returns it.
        c��eZdZdeefd�Zy)�0ElementTests.test_render.<locals>.TemplateLoaderrDc��dgS)N�resultrIr>s r.�loadz5ElementTests.test_render.<locals>.TemplateLoader.load�s
�� �z�!r0N)rErFrGrrr}rIr0r.�TemplateLoaderrz�s��
"�d�;�/�
"r0r~c���eZdZW��Zy)�-ElementTests.test_render.<locals>.StubElementN)rErFrG�loader)r~s�r.�StubElementr��s���#�%�Fr0r�Nr|)rrrr)rM)r,r�rOr~s   @r.�test_renderzElementTests.test_render�sQ���
�_�	%�	"�	"�
&�	"�	&�'�	&��-���������-��z�:r0c���|jtt�}tjdk\r|jt
|�d�y|jt
|�d�y)z�
        If the L{renderer} decorator  is called without any arguments, it will
        raise a comprehensible exception.
        )��
z=Expose.__call__() missing 1 required positional argument: 'f'z6__call__() missing 1 required positional argument: 'f'N)r;�	TypeErrorr�sys�version_infor)r\)r,�tes  r.�test_misuseRendererz ElementTests.test_misuseRenderer�sV��
�
�
�y�(�
3�����w�&�����B��X�
�
����B��Q�
r0c�P�|jttjdd�y)z�
        Called directly, without a default, L{renderer.get} raises
        L{UnexposedMethodError} when it cannot find a renderer.
        N�notARenderer)r;rr�getr>s r.�test_renderGetDirectlyErrorz(ElementTests.test_renderGetDirectlyError�s��
	
���.����d�N�Sr0rC)rErFrGrHrRrarfrmrwr�r�r�rIr0r.rKrK[s0���3�
�0�+�4�;�"
�Tr0rKc�H�eZdZdZdd�Zdd�Zege_dd�Zege_y)�XMLFileReprTestszB
    Tests for L{twisted.web.template.XMLFile}'s C{__repr__}.
    Nc�j�td�}|jd|�d�tt|���y)zK
        An L{XMLFile} with a L{FilePath} returns a useful repr().
        �
/tmp/fake.xml�<XMLFile of �>N)r
r)r`r)r,�paths  r.�
test_filePathzXMLFileReprTests.test_filePath�s0����(�����<��x�q�1�4���
�3F�Gr0c�X�d}|jd|�d�tt|���y)zH
        An L{XMLFile} with a filename returns a useful repr().
        r�r�r�N)r)r`r)r,�fnames  r.�
test_filenamezXMLFileReprTests.test_filename�s+�� �����<��y��2�D����4H�Ir0c�j�td�}|jd|�d�tt|���y)zK
        An L{XMLFile} with a file object returns a useful repr().
        znot xmlr�r�N)rr)r`r)r,�fobjs  r.�	test_filezXMLFileReprTests.test_file�s0���	�"�����<��x�q�1�4���
�3F�Gr0rC)	rErFrGrHr�r��_xmlFileSuppressrr�rIr0r.r�r��s3���H�J�/�/�M��H�+�+�I�r0r�c�L�eZdZUeed<	dZ	defd�Zdd�Zdd�Z	e
ge	_y)	�XMLLoaderTestsMixin�
deprecatedUse�<p>Hello, world.</p>rDc��t��N)�NotImplementedErrorr>s r.�
loaderFactoryz!XMLLoaderTestsMixin.loaderFactory�s��!�!r0Nc�*�t|t�sJ�|j�}|j�\}t|t�sJ�|j|jg��}|jrP|jt|�d�|j|ddt�|j|ddd�n|jt|�d�|j|jd�|j|jdg�y	)
zQ
        Verify that the loader returns a tag with the correct children.
        )�offendingFunctions�rr#r$r"�p�
Hello, world.N)�
isinstancerr�r}r�
flushWarningsr�r)�len�DeprecationWarningr*�children)r,r�r-�warningss    r.�	test_loadzXMLLoaderTestsMixin.test_load�s����$��)�)�)��#�#�%���������#�s�#�#�#��%�%�$�:L�:L�9M�%�N��������S��]�A�.����X�a�[��4�6H�I�������I�&�K�
�
���S��]�A�.�������c�*��������'8�9r0c��t|t�sJ�|j�}|j�}|j�}|j	||�y)zd
        If {load()} can be called on a loader twice the result should be the
        same.
        N)r�rr�r}r))r,r��tags1�tags2s    r.�test_loadTwicez"XMLLoaderTestsMixin.test_loadTwice	sH��
�$��)�)�)��#�#�%�����
�����
�������&r0rC)rErFrG�bool�__annotations__�templateStringrr�r�r�r�rrIr0r.r�r��s<�����
,�N��"��"�:�0	'� 0�0�N�r0r�c� �eZdZdZdZdefd�Zy)�XMLStringLoaderTestsz5
    Tests for L{twisted.web.template.XMLString}
    FrDc�,�t|j�S)zS
        @return: an L{XMLString} constructed with C{self.templateString}.
        )rr�r>s r.r�z"XMLStringLoaderTests.loaderFactorys����,�,�-�-r0N�rErFrGrHr�rr�rIr0r.r�r�s����M�.��.r0r�c� �eZdZdZdZdefd�Zy)�XMLFileWithFilePathTestszJ
    Tests for L{twisted.web.template.XMLFile}'s L{FilePath} support.
    FrDc��t|j��}|j|jj	d��t|�S)z�
        @return: an L{XMLString} constructed with a L{FilePath} pointing to a
            file that contains C{self.templateString}.
        �utf8)r
�mktemp�
setContentr��encoder�r,�fps  r.r�z&XMLFileWithFilePathTests.loaderFactory,s;��
�d�k�k�m�
$��
�
�
�d�)�)�0�0��8�9��r�{�r0Nr�rIr0r.r�r�%s����M���r0r�c� �eZdZdZdZdefd�Zy)�XMLFileWithFileTestszU
    Tests for L{twisted.web.template.XMLFile}'s deprecated file object support.
    TrDc�>�tt|j��S)z{
        @return: an L{XMLString} constructed with a file object that contains
            C{self.templateString}.
        )rrr�r>s r.r�z"XMLFileWithFileTests.loaderFactory=s��
�x�� 3� 3�4�5�5r0Nr�rIr0r.r�r�6s����M�6��6r0r�c� �eZdZdZdZdefd�Zy)�XMLFileWithFilenameTestszR
    Tests for L{twisted.web.template.XMLFile}'s deprecated filename support.
    TrDc��t|j��}|j|jj	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�rr�r�s  r.r�z&XMLFileWithFilenameTests.loaderFactoryLs@��
�d�k�k�m�
$��
�
�
�d�)�)�0�0��8�9��r�w�w��r0Nr�rIr0r.r�r�Es����M� �� r0r�c��eZdZdZdd�Zdd�Zdd�Zdd�Zdd�Zdd�Z	dd	�Z
dd
�Zdd�Zdd�Z
dd
�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zy)�FlattenIntegrationTestsz[
    Tests for integration between L{Element} and
    L{twisted.web._flatten.flatten}.
    Nc�d�gd�}|D]'}|jtt|���|��)y)z�
        Given a series of parsable XML strings, verify that
        L{twisted.web._flatten.flatten} will flatten the L{Element} back to the
        input when sent on a round trip.
        )�<p>Hello, world.</p>s<p><!-- hello, world --></p>s <p><![CDATA[Hello, world.]]></p>sB<test1 xmlns:test2="urn:test2"><test2:test3></test2:test3></test1>s0<test1 xmlns="urn:test2"><test3></test3></test1>�
<p>☃</p>�r�N)�assertFlattensImmediatelyrr)r,�	fragments�xmls   r.�test_roundTripz&FlattenIntegrationTests.test_roundTrip\s5��
�	��	P�C��*�*�7�)�C�.�+I�3�O�	Pr0c�R�ttd���}|j|d�y)zx
        When flattening an HTML entity, it should flatten out to the utf-8
        representation if possible.
        z<p>&#9731;</p>r�r�N�rrr��r,rOs  r.�test_entityConversionz-FlattenIntegrationTests.test_entityConversionms%��
��+;�!<�=���&�&�w�0F�Gr0c�@�|jt�t�y)zk
        Rendering an Element without a loader attribute raises the appropriate
        exception.
        N)�assertFlatteningRaisesrrr>s r.rRz2FlattenIntegrationTests.test_missingTemplateLoaderus��
	
�#�#�G�I�/D�Er0c�Z�ttd���}|j|t�y)z�
        Flattening an L{Element} with a C{loader} which has a tag with a render
        directive fails with L{FlattenerError} if there is no available render
        method to satisfy that directive.
        zy
        <p xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1"
          t:render="unknownMethod" />
        r�N)rrr�rr�s  r.�test_missingRenderMethodz0FlattenIntegrationTests.test_missingRenderMethod|s.������
��	
�#�#�G�-@�Ar0c�R�ttd���}|j|d�y)zw
        A C{transparent} element should be eliminated from the DOM and rendered as
        only its children.
        zk<t:transparent xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1">Hello, world.</t:transparent>r��
Hello, world.Nr�r�s  r.�test_transparentRenderingz1FlattenIntegrationTests.test_transparentRendering�s.��
��#��
��	
�&�&�w�0@�Ar0c�R�ttd���}|j|d�y)z~
        An Element with an attr tag renders the vaule of its attr tag as an
        attribute of its containing tag.
        z�<a xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1"><t:attr name="href">http://example.com</t:attr>Hello, world.</a>r�s.<a href="http://example.com">Hello, world.</a>Nr�r�s  r.�test_attrRenderingz*FlattenIntegrationTests.test_attrRendering�s1��
����
��	
�&�&��F�	
r0c�r�|jtd�D�cgc]
}td���c}d�ycc}w)z�
        When rendering a large number of already-fired Deferreds we should not
        encounter any recursion errors or stack-depth issues.
        ��xs�xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxN)r��ranger	)r,�is  r.�!test_synchronousDeferredRecursionz9FlattenIntegrationTests.test_synchronousDeferredRecursion�s*��
	
�&�&�e�C�j�'I�����'I�:�V��'Is�4c�:�|jttd�y)z{
        A template with a toplevel C{attr} tag will not load; it will raise
        L{AssertionError} if you try.
        z�<t:attr
            xmlns:t='http://twistedmatrix.com/ns/twisted.web.template/0.1'
            name='something'
            >hello</t:attr>
            N�r;�AssertionErrorrr>s r.�test_errorToplevelAttrz.FlattenIntegrationTests.test_errorToplevelAttr�s��
	
�����
�	
r0c�:�|jttd�y)z�
        A template with an C{attr} tag with no C{name} attribute will not load;
        it will raise L{AssertionError} if you try.
        z{<html><t:attr
            xmlns:t='http://twistedmatrix.com/ns/twisted.web.template/0.1'
            >hello</t:attr></html>Nr�r>s r.�test_errorUnnamedAttrz-FlattenIntegrationTests.test_errorUnnamedAttr�s��
	
�����
&�	
r0c�t�d}tt|���}|j||jd��y)z�
        If the parser sees a prefix it doesn't recognize on an attribute, it
        will pass it on through to serialization.
        z}<hello:world hello:sample="testing" xmlns:hello="http://made-up.example.com/ns/not-real">This is a made-up tag.</hello:world>r�r�N)rr�assertFlattensTor�)r,�theInputrOs   r.�test_lenientPrefixBehaviorz2FlattenIntegrationTests.test_lenientPrefixBehavior�s6��
3�	�
��8�!4�5�����g�x���v�'>�?r0c�j�Gd�dt�}|td���}|j|d�y)zi
        An Element with a render method which returns a Deferred will render
        correctly.
        c�0�eZdZedeededefd��Zy)�HFlattenIntegrationTests.test_deferredRendering.<locals>.RenderfulElementrqr-rDc��td�S�Nr�)r	rts   r.�renderMethodzUFlattenIntegrationTests.test_deferredRendering.<locals>.RenderfulElement.renderMethod�s����/�/r0N�	rErFrGrrrrrr�rIr0r.�RenderfulElementr��s1��
�
0�'��1�
0�8;�
0��
0��
0r0r���
        <p xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1"
          t:render="renderMethod">
            Goodbye, world.
        </p>
        r�r�Nr��r,r�rOs   r.�test_deferredRenderingz.FlattenIntegrationTests.test_deferredRendering�s:��	0�w�	0�#����	
��	
�&�&�w�0@�Ar0c�P�Gd�dt�}|j|�d�y)z�
        If there is a non-None loader attribute on the class of an Element
        instance but none on the instance itself, the class attribute is used.
        c��eZdZed�Zy)�EFlattenIntegrationTests.test_loaderClassAttribute.<locals>.SubElementr�N)rErFrGrr�rIr0r.�
SubElementr�s
���5�6�Fr0rr�N)rr�)r,rs  r.�test_loaderClassAttributez1FlattenIntegrationTests.test_loaderClassAttribute�s#��	7��	7�	
�&�&�z�|�5L�Mr0c�t��g�G�fd�dt�}|td���}|j|d�y)z�
        An Element with a valid render directive has that directive invoked and
        the result added to the output.
        c�6��eZdZedeededef�fd��Zy)�IFlattenIntegrationTests.test_directiveRendering.<locals>.RenderfulElementrqr-rDc�:���j||f�|d�Sr�)�append)r,rqr-�renderss   �r.r�zVFlattenIntegrationTests.test_directiveRendering.<locals>.RenderfulElement.renderMethods �������g��/��?�+�+r0Nr�)r	s�r.r�rs2���
�
,�'��1�
,�8;�
,��
,��
,r0r��x
        <p xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1"
          t:render="renderMethod" />
        r�r�Nr�)r,r�rOr	s   @r.�test_directiveRenderingz/FlattenIntegrationTests.test_directiveRenderingsB���
��	,�w�	,�#����
��	
�&�&�w�0G�Hr0c�j�Gd�dt�}|td���}|j|d�y)z�
        An Element with a render method which omits the containing tag
        successfully removes that tag from the output.
        c�0�eZdZedeededefd��Zy)�TFlattenIntegrationTests.test_directiveRenderingOmittingTag.<locals>.RenderfulElementrqr-rDc��yr�rIrts   r.r�zaFlattenIntegrationTests.test_directiveRenderingOmittingTag.<locals>.RenderfulElement.renderMethod s��'r0Nr�rIr0r.r�rs1��
�
'�'��1�
'�8;�
'��
'��
'r0r�r�r�r�Nr�r�s   r.�"test_directiveRenderingOmittingTagz:FlattenIntegrationTests.test_directiveRenderingOmittingTags:��	'�w�	'�#����	
��	
�&�&�w�0@�Ar0c�j�Gd�dt�}|td���}|j|d�y)�t
        An Element which is returned by the render method of another Element is
        rendered properly.
        c�0�eZdZedeededefd��Zy)�UFlattenIntegrationTests.test_elementContainingStaticElement.<locals>.RenderfulElementrqr-rDc�8�|ttd����S)Nz<em>Hello, world.</em>r�)rrrts   r.r�zbFlattenIntegrationTests.test_elementContainingStaticElement.<locals>.RenderfulElement.renderMethod9s���7�)�4L�*M�N�O�Or0Nr�rIr0r.r�r8s6��
�
P�'��1�
P�8;�
P��
P��
Pr0r�r
r�s<p><em>Hello, world.</em></p>Nr�r�s   r.�#test_elementContainingStaticElementz;FlattenIntegrationTests.test_elementContainingStaticElement2s<��	P�w�	P�#����
��	
�&�&�w�0P�Qr0c�j�Gd�dt�}|td���}|j|d�y)rc�0�eZdZedeededefd��Zy)�HFlattenIntegrationTests.test_elementUsingSlots.<locals>.RenderfulElementrqr-rDc�&�|jd��S)Nzworld.)�test2)�	fillSlotsrts   r.r�zUFlattenIntegrationTests.test_elementUsingSlots.<locals>.RenderfulElement.renderMethodPs���}�}�8�}�4�4r0Nr�rIr0r.r�rOs1��
�
5�'��1�
5�8;�
5��
5��
5r0r�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_elementUsingSlotsIs:��	5�w�	5�#����
��	
�&�&�w�0G�Hr0c���G�fd�dt�}Gd�dt��|td���}|j|d�y)	z�
        Directives in the document factory of an Element returned from a render
        method of another Element are satisfied from the correct object: the
        "inner" Element.
        c�6��eZdZedeededef�fd��Zy)�RFlattenIntegrationTests.test_elementContainingDynamicElement.<locals>.OuterElementrqr-rDc�4��|�td����S)Nz�
                <t:ignored
                  xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1"
                  t:render="innerMethod" />
                r�)r)r,rqr-�InnerElements   �r.�outerMethodz^FlattenIntegrationTests.test_elementContainingDynamicElement.<locals>.OuterElement.outerMethodis%���� �(�� ��
�
r0N)	rErFrGrrrrrr#)r"s�r.�OuterElementr hs/���
�
�8�H�+=�
�C�
�K�
��
r0r$c�0�eZdZedeededefd��Zy)�RFlattenIntegrationTests.test_elementContainingDynamicElement.<locals>.InnerElementrqr-rDc��yr�rIrts   r.�innerMethodz^FlattenIntegrationTests.test_elementContainingDynamicElement.<locals>.InnerElement.innerMethodxs��&r0N)	rErFrGrrrrrr(rIr0r.r"r&ws.��
�
'�8�H�+=�
'�C�
'�K�
'��
'r0r"zw
        <p xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1"
          t:render="outerMethod" />
        r�r�Nr�)r,r$rOr"s   @r.�$test_elementContainingDynamicElementz<FlattenIntegrationTests.test_elementContainingDynamicElementasG���
	�7�
	�	'�7�	'�
����
��	
�&�&�w�0G�Hr0c�����td��G��fd�dt����}��}|j|d�|j|d�|j|d�y)z
        Rendering the output of a loader, or even the same element, should
        return different output each time.
        z�<p xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1"><t:transparent t:render="classCounter" /> <t:transparent t:render="instanceCounter" /></p>c�h��eZdZdZdZW�Zedeede	de
f�fd��Zedeede	de
fd��Zy)�HFlattenIntegrationTests.test_sameLoaderTwice.<locals>.DestructiveElementrrqr-rDc�d���xjdz
c_|t�j��S�Nr�)�countr\)r,rqr-�DestructiveElements   �r.�classCounterzUFlattenIntegrationTests.test_sameLoaderTwice.<locals>.DestructiveElement.classCounter�s-���#�(�(�A�-�(��3�1�7�7�8�9�9r0c�b�|xjdz
c_|t|j��Sr.)�
instanceCountr\rts   r.�instanceCounterzXFlattenIntegrationTests.test_sameLoaderTwice.<locals>.DestructiveElement.instanceCounter�s+���"�"�a�'�"��3�t�1�1�2�3�3r0N)
rErFrGr/r3r�rrrrrr1r4)r0�sharedLoaders��r.r0r,�sr����E��M�!�F�
�
:�'��1�
:�8;�
:��
:��
:��
4�'��1�
4�8;�
4��
4��
4r0r0s
<p>1 1</p>s
<p>2 2</p>s
<p>3 1</p>N)rrr�)r,�e1�e2r0r5s   @@r.�test_sameLoaderTwicez,FlattenIntegrationTests.test_sameLoaderTwice�sb���
!�
�
��	4��	4�& �
!��
�
!���&�&�r�=�9��&�&�r�=�9��&�&�r�=�9r0rC)rErFrGrHr�r�rRr�r�r�r�r�r�r�r�rrrrrr)r8rIr0r.r�r�Vsp���
P�"H�F�B� 
B�
�"W�

�
�@�B�2	N�I�2B�2R�.I�0#I�J#:r0r�c�0�eZdZdZdd�Zdd�Zdd�Zdd�Zy)�TagLoaderTestsz!
    Tests for L{TagLoader}.
    Nc�J�ttjd��|_y)N�test)rrr�r�r>s r.�setUpzTagLoaderTests.setUp�s������v��/��r0c�V�|jtt|j��y)zJ
        An instance of L{TagLoader} provides L{ITemplateLoader}.
        N)�
assertTruerrr�r>s r.�test_interfacezTagLoaderTests.test_interface�s��	
����_�d�k�k�B�Cr0c�`�|j|jj�t�y)zK
        L{TagLoader.load} returns a list, per L{ITemplateLoader}.
        N)�assertIsInstancer�r}�listr>s r.�test_loadsListzTagLoaderTests.test_loadsList�s!��	
���d�k�k�.�.�0�$�7r0c�R�t|j�}|j|d�y)z�
        L{TagLoader} can be used in an L{Element}, and flattens as the tag used
        to construct the L{TagLoader} would flatten.
        s<i>test</i>N)rr�r�)r,�es  r.�test_flattenzTagLoaderTests.test_flatten�s"��

�D�K�K� ���&�&�q�.�9r0rC)rErFrGrHr=r@rDrGrIr0r.r:r:�s���0�D�8�:r0r:c� �eZdZdZed�Zy)�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)rErFrGrHrr�rIr0r.rIrI�s����	��Fr0rIc�6�eZdZdZed�Zddededdfd�Zy)	�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�rDc��||_yr�)rL)r,rLr�s   r.�__init__zTestFailureElement.__init__�s	����r0r�)	rErFrGrHrr�r�objectrNrIr0r.rKrK�s2���
�	��F������4�r0rKc�&�eZdZdZdeeddfd�Zy)�FailingElementz<
    An element that raises an exception when rendered.
    rqrDrc��d}d}||z�S)N�*rrI)r,rqr(�bs    r.rMzFailingElement.render�s����
���q�&��r0N)rErFrGrHrrrMrIr0r.rQrQ�s����h�x�0��]�r0rQc��eZdZdZdZy)�FakeSitezL
    A minimal L{Site} object that we can use to test displayTracebacks
    FN)rErFrGrH�displayTracebacksrIr0r.rVrV�s����r0rVc�$��eZdZdZd�fd�Z�xZS)�DummyRenderRequestz�
    A dummy request object that has a C{site} attribute.

    This does not implement the full IRequest interface, but enough of it
    for this test suite.
    c�D��t�|�dg�t�|_y)Nr0)�superrNrV�site)r,�	__class__s �r.rNzDummyRenderRequest.__init__s���
���#����J��	r0rC)rErFrGrHrN�
__classcell__)r]s@r.rYrY�s�����r0rYc�r�eZdZdZd
d�Zdedfd�Zdedfd�Zdedfd�Zdedfd�Z	dedfd	�Z
y)�RenderElementTestsz
    Test L{renderElement}
    rDNc�"�t�|_y)z8
        Set up a common L{DummyRenderRequest}.
        N)rYrqr>s r.r=zRenderElementTests.setUps��*�+��r0c����t�}�jj�}dtddf�fd�}|j	|��jtt�j|��|S)z�
        L{renderElement} returns NOT_DONE_YET and eventually
        writes the rendered L{Element} to the request before finishing the
        request.
        �_rDNc����jdj�jj�d��j	�jj
�y)Nr0s$<!DOCTYPE html>
<p>Hello, world.</p>)r)�joinrq�writtenr?�finished�rcr,s �r.�checkz3RenderElementTests.test_simpleRender.<locals>.checksB������������-�-�.�<�
�
�O�O�D�L�L�1�1�2r0)rIrq�notifyFinishrO�addCallbackrNrr�r,rO�dris`   r.�test_simpleRenderz$RenderElementTests.test_simpleRenders_����-���L�L�%�%�'��	3�V�	3��	3�	
�
�
�e�����\�=����w�+O�P��r0c����t�}�jj�}dtddf�fd�}|j	|��jtt�j|��|S)z
        L{renderElement} handles failures by writing a minimal
        error message to the request and finishing it.
        rcrDNc����jt�}�jt|�d��jdj	�j
j�d��j�j
j�y)Nr�r0s�<!DOCTYPE html>
<div style="font-size:800%;background-color:#FFF;color:#F00">An error occurred while rendering the response.</div>)	�flushLoggedErrorsrr)r�rerqrfr?rg)rc�flushedr,s  �r.riz4RenderElementTests.test_simpleFailure.<locals>.check1si����,�,�^�<�G����S��\�1�-����������-�-�.�O�	
�
�O�O�D�L�L�1�1�2r0)rQrqrjrOrkrNrrrls`   r.�test_simpleFailurez%RenderElementTests.test_simpleFailure(s`���
!�"���L�L�%�%�'��
	3�V�
	3��
	3�	
�
�
�e�����\�=����w�+O�P��r0c�4���tj�t��d�jj_t
�}�jj�}dtddf��fd�}|j|�t�j|t��|S)z�
        L{renderElement} will render a traceback when rendering of
        the element fails and our site is configured to display tracebacks.
        TrcrDNc����jdt����dd}�j|jt��jt�}�j
t|�d��j
dj�jj�d��j�jj�y)Nr�r�log_failurer0s <!DOCTYPE html>
<p>I failed.</p>)�assertEqualsr�rB�valuerrqr)rerqrfr?rg)rc�frr�logObserverr,s   ��r.rizARenderElementTests.test_simpleFailureWithTraceback.<locals>.checkRs�������a��[�!1�2��A��}�-�A��!�!�!�'�'�>�:��,�,�^�<�G����S��\�1�-����������-�-�.�0T�
�
�O�O�D�L�L�1�1�2r0)�_failElement)r
�createWithCleanuprrqr\rWrQrjrOrkrrK)r,rOrmrirzs`   @r.�test_simpleFailureWithTracebackz2RenderElementTests.test_simpleFailureWithTracebackFs{���
+�<�<�T�CU�V��.2������+� �"���L�L�%�%�'��		3�V�		3��		3�	
�
�
�e���d�l�l�G�:L�M��r0c���t�}�jj�}dtddf�fd�}|j	|�t�j|d��|S)zs
        L{renderElement} will write the doctype string specified by the
        doctype keyword argument.
        rcrDNc�p���jdj�jj�d�y)Nr0s�<!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)rerqrfrhs �r.riz8RenderElementTests.test_nonDefaultDoctype.<locals>.checkls,������������-�-�.�,�
r0sm<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">��doctype�rIrqrjrOrkrrls`   r.�test_nonDefaultDoctypez)RenderElementTests.test_nonDefaultDoctypecs^���
�-���L�L�%�%�'��	�V�	��	�	
�
�
�e����L�L��I�		
��r0c���t�}�jj�}dtddf�fd�}|j	|�t�j|d��|S)zs
        L{renderElement} will not write out a doctype if the doctype keyword
        argument is L{None}.
        rcrDNc�p���jdj�jj�d�y)Nr0r�r�rhs �r.riz2RenderElementTests.test_noneDoctype.<locals>.check�s'������S�X�X�d�l�l�&:�&:�;�=T�Ur0r�r�rls`   r.�test_noneDoctypez#RenderElementTests.test_noneDoctype�sW���
�-���L�L�%�%�'��	V�V�	V��	V�	
�
�
�e���d�l�l�G�T�:��r0rC)rErFrGrHr=rrnrsr}r�r�rIr0r.r`r`s]���,��8�D�>��.�H�T�N��<��$���:�����@�(�4�.�r0r`)FrHr��ior�typingrr�zope.interfacer�zope.interface.verifyr�twisted.internet.deferrr	�twisted.internet.testingr
�twisted.loggerr�twisted.python.failurer�twisted.python.filepathr
�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&rKr�r�r�r�r�r�r�r:rIrKrQrVrYr`rIr0r.�<module>r�sS�����!�&�.�4�9�-�*�,�+�3�5�X�X�6�+�
�
�
�3�2��
�
?���)@�h�)@�XeT�8�eT�P,�x�,�>21�21�j.�8�%8�.��x�)<��"6�8�%8�6� �x�)<� �"S:�o�S:�l
:�_�:�:	�'�	�
��
� �W����
�X��
��
��
�M��Mr0

Zerion Mini Shell 1.0