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: //lib/python3/dist-packages/twisted/spread/test/__pycache__/test_jelly.cpython-38.pyc
U


W[N�@s2dZddlmZmZddlZddlZddlmZddlm	Z	m
Z
ddlmZddl
mZGdd	�d	e	je�ZGd
d�d�Zdd
�ZGdd�d�ZGdd�d�ZGdd�de�ZGdd�de�ZGdd�d�ZGdd�dej�ZGdd�dej�ZGdd�de
je
j�ZGdd�de
je
j�ZGd d!�d!ej�Z dS)"z/
Test cases for L{jelly} object serialization.
�)�absolute_import�divisionN)�unicode)�jelly�pb)�unittest)�StringTransportc@seZdZdZdZddd�ZdS)�TestNodezD
    An object to test jellyfying of new style class instances.
    �NcCs4|r|jd|_|j�|�nd|_||_g|_dS)N�)�id�children�append�parent)�selfr�r�@/usr/lib/python3/dist-packages/twisted/spread/test/test_jelly.py�__init__szTestNode.__init__)N)�__name__�
__module__�__qualname__�__doc__�	classAttrrrrrrr	sr	c@seZdZdZdd�ZdS)�A�
    Dummy class.
    cCsdS�z;
        Method to be used in serialization tests.
        Nr�rrrr�amethod)sz	A.amethodN)rrrrrrrrrr$srcCsdS)z:
    A dummy function to test function serialization.
    Nrrrrr�afunc0src@seZdZdZdd�ZdS)�BrcCsdSrrrrrr�bmethod<sz	B.bmethodN)rrrrr rrrrr7src@seZdZdZdd�ZdS)�CrcCsdSrrrrrr�cmethodHsz	C.cmethodN)rrrrr"rrrrr!Csr!c@seZdZdZdS)�Dz 
    Dummy new-style class.
    N)rrrrrrrrr#Osr#c@s.eZdZdZdZd
dd�Zdd�Zdd	�ZdS)�Ez+
    Dummy new-style class with slots.
    ��x�yNcCs||_||_dS�Nr%�rr&r'rrrr]sz
E.__init__cCs|j|jd�S)Nr%r%rrrr�__getstate__bszE.__getstate__cCs|d|_|d|_dS)Nr&r'r%�r�staterrr�__setstate__fs
zE.__setstate__)NN)rrrr�	__slots__rr*r-rrrrr$Vs

r$c@seZdZdd�Zdd�ZdS)�SimpleJellyTestcCs||_||_dSr(r%r)rrrrmszSimpleJellyTest.__init__cCs|j|jkSr()�__dict__�r�otherrrr�isTheSameAsqszSimpleJellyTest.isTheSameAsN)rrrrr3rrrrr/lsr/c@sNeZdZdZddddgdddgdddgddd	ggZd
d�Zdd
�Zdd�Zdd�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zejs�d*e_d+d,�Zejs�d-e_d.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Z d>d?�Z!d@dA�Z"dBdC�Z#dDdE�Z$dFdG�Z%dHdI�Z&dJdK�Z'dLS)M�
JellyTestsz�
    Testcases for L{jelly} module serialization.

    @cvar decimalData: serialized version of decimal data, to be used in tests.
    @type decimalData: L{list}
    slist�decimali����r�@�i������cCsJt�|�}t��}|��t�||�|j�|�|�tjtj||�dS)z�
        Helper test method to test security options for a type.

        @param inputList: a sample input for the type.
        @type inputList: L{list}

        @param atom: atom identifier for the type.
        @type atom: L{str}
        N)r�SecurityOptionsZallowBasicTypes�unjellyZallowedTypes�pop�assertRaises�
InsecureJelly)r�	inputListZatom�c�tasterrrr�
_testSecurity�s

zJellyTests._testSecuritycCsRt�}t�}t�}|j|_||_tj}t`z|�ttj	t�|��W5|t_XdS)z�
        If a class change after an instance has been created, L{jelly.unjelly}
        shoud raise a C{TypeError} when trying to unjelly the instance.
        N)
rrr!r"r �ar<�	TypeErrorrr:)rrB�br?Zsavecmethodrrr�test_methodsNotSelfIdentity�sz&JellyTests.test_methodsNotSelfIdentitycCs`t�}d|_t�}||_||_t�|�}t�|�}|�|t�|�|j|j�|�|jd�dS)z�
        Test that a new style class can be jellied and unjellied with its
        objects and attribute values preserved.
        rN)	r#r&�n2Zn3rr:�assertIsInstance�assertIs�assertEqual)r�nrFr?�mrrr�
test_newStyle�s

zJellyTests.test_newStylecCs>t�}d|_t�|�}t�|�}|�|t�|�|jd�dS)z�
        A class defined with I{slots} can be jellied and unjellied with the
        values for its attributes preserved.
        rN)r$r&rr:rGrI)rrJr?rKrrr�test_newStyleWithSlots�s

z!JellyTests.test_newStyleWithSlotscCs&tg}t�t�|��}|�||�dS)zn
        Test that an old style class type can be jellied and unjellied
        to the original type.
        N)r!rr:rI�r�t�rrrr�test_typeOldStyle�szJellyTests.test_typeOldStylecCs&tg}t�t�|��}|�||�dS)zm
        Test that a new style class type can be jellied and unjellied
        to the original type.
        N)r#rr:rIrNrrr�test_typeNewStyle�szJellyTests.test_typeNewStylecCs&tg}t�t�|��}|�||�dS)ze
        Test that a builtin type can be jellied and unjellied to the original
        type.
        N)�strrr:rIrNrrr�test_typeBuiltin�szJellyTests.test_typeBuiltincCsPtj��}tj��|}||g}t�|�}t�|�}|�||�|�||�dS)z�
        Jellying L{datetime.timedelta} instances and then unjellying the result
        should produce objects which represent the values of the original
        inputs.
        N)�datetimeZnowrr:rI�assertIsNot)rZdtnZdtdr>r?�outputrrr�
test_dateTime�s


zJellyTests.test_dateTimecCsTt�d�t�d�t�d�t�d�g}t�|�}t�|�}|�||�|�||�dS)z�
        Jellying L{decimal.Decimal} instances and then unjellying the result
        should produce objects which represent the values of the original
        inputs.
        �9.95rr7�-78.901N)�decimal�Decimalrr:rIrV)rr>r?rWrrr�test_decimal�s�

zJellyTests.test_decimalcCs@t�d�t�d�t�d�t�d�g}t�|j�}|�||�dS)a
        Unjellying the s-expressions produced by jelly for L{decimal.Decimal}
        instances should result in L{decimal.Decimal} instances with the values
        represented by the s-expressions.

        This test also verifies that L{decimalData} contains valid jellied
        data.  This is important since L{test_decimalMissing} re-uses
        L{decimalData} and is expected to be unable to produce
        L{decimal.Decimal} instances even though the s-expression correctly
        represents a list of them.
        rYrr7rZN)r[r\rr:�decimalDatarI)rZexpectedrWrrr�test_decimalUnjellys�zJellyTests.test_decimalUnjellycCst�d�g}|�|d�dS)z�
        By default, C{decimal} objects should be allowed by
        L{jelly.SecurityOptions}. If not allowed, L{jelly.unjelly} should raise
        L{jelly.InsecureJelly} when trying to unjelly it.
        rYr5N)r[r\rA�rr>rrr�test_decimalSecurityszJellyTests.test_decimalSecuritycCs<tdddg�g}t�t�|��}|�||�|�||�dS)z�
        Jellying C{set} instances and then unjellying the result
        should produce objects which represent the values of the original
        inputs.
        r��N)�setrr:rIrV�rr>rWrrr�test_set szJellyTests.test_setcCs<tdddg�g}t�t�|��}|�||�|�||�dS)z�
        Jellying L{frozenset} instances and then unjellying the result
        should produce objects which represent the values of the original
        inputs.
        rrbrcN)�	frozensetrr:rIrVrerrr�test_frozenset,szJellyTests.test_frozensetcCs tdddg�g}|�|d�dS)z�
        By default, C{set} objects should be allowed by
        L{jelly.SecurityOptions}. If not allowed, L{jelly.unjelly} should raise
        L{jelly.InsecureJelly} when trying to unjelly it.
        rrbrcssetN)rdrAr`rrr�test_setSecurity8szJellyTests.test_setSecuritycCs tdddg�g}|�|d�dS)z�
        By default, L{frozenset} objects should be allowed by
        L{jelly.SecurityOptions}. If not allowed, L{jelly.unjelly} should raise
        L{jelly.InsecureJelly} when trying to unjelly it.
        rrbrcs	frozensetN)rgrAr`rrr�test_frozensetSecurityBsz!JellyTests.test_frozensetSecurityc	Cs�tj�dddg�g}t�|�}|�|t�tdddg�g��t�|�}|�t|d�t|d��ttjjkr�|�|dtjj�n|�|dt�dS)z�
        Test jellying C{sets.Set}: it should serialize to the same thing as
        C{set} jelly, and be unjellied as C{set} if available.
        rrbrcrN)r�_sets�SetrIrdr:�listrG�rr>Z
inputJellyrWrrr�test_oldSetsLs

zJellyTests.test_oldSetsz'sets.Set is gone in Python 3 and higherc	Cs�tj�dddg�g}t�|�}|�|t�tdddg�g��t�|�}|�t|d�t|d��ttjjkr�|�|dtjj�n|�|dt�dS)z�
        Test jellying C{sets.ImmutableSet}: it should serialize to the same
        thing as L{frozenset} jelly, and be unjellied as L{frozenset} if
        available.
        rrbrcrN)rrkZImmutableSetrIrgr:rmrGrnrrr�test_oldImmutableSets`s

z JellyTests.test_oldImmutableSetsz1sets.ImmutableSets is gone in Python 3 and highercCsN|�tdd��tdd���tdd�}t�|�}t�|�}|�|�|��dS)z%
        Simplest test case.
        rBrDrrbN)�
assertTruer/r3rr:)rrBZcerealrDrrr�test_simplevs�


zJellyTests.test_simplecCs�g}|}|�|�|�|�|�|d|d�|�|dd|�t�|�}t�|�}|�|d|d�|�|dd|�dS)zJ
        Test to make sure that objects retain identity properly.
        rrN)rrHrr:)rr&r'�s�zrrr�
test_identity�s



zJellyTests.test_identitycCs<td�}t�t�|��}|�||�|�t|�t|��dS)NZblah)rrr:rI�typer)rrr�test_unicode�szJellyTests.test_unicodecCsbg}d|i|f}|�|�t�|�}t�|�}|�|dd|d�|�|ddd|�dS)Nrmrr�rrr:rH)rZrerefZ
toplevelTuplersrtrrr�test_stressReferences�s


z JellyTests.test_stressReferencescCsFg}|f}|�|f�t�|�}t�|�}|�|ddd|�dS�Nrrx)rrBrOrsrtrrr�test_moreReferences�s

zJellyTests.test_moreReferencescCs*t��}t�i�}|�tjtj||�dS)z@
        Test for type-level security of serialization.
        N)rr9r<r=r:)rr@Zdctrrr�test_typeSecurity�s
zJellyTests.test_typeSecuritycCst�t�}|�t|�dSr()rr:r#rH)r�ujrrr�test_newStyleClasses�s
zJellyTests.test_newStyleClassescCs�t�}t�t�|��t�t�|j��tdddgtd�td�ddddttdditjg}|D]}|�|t�t�|���q^dS)	zA
        Test for all types currently supported in jelly
        rrbrcZtestg�����L4@)rrbrcNrB)rrr:rr�boolrrI)rrB�items�irrr�test_lotsaTypes�s�zJellyTests.test_lotsaTypescCsxGdd�d�at�}t|�}t|�}t||f�}||||||d|i}t�t�|��d}|�|jdj|jdj�dS)Nc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�
TupleStatecSs
||_dSr(�r2r1rrrr�szTupleState.__init__cSs|jfSr(r�rrrrr*�szTupleState.__getstate__cSs|d|_dSrzr�r+rrrr-�szTupleState.__setstate__cSs
t|j�Sr()�hashr2rrrr�__hash__�szTupleState.__hash__N)rrrrr*r-r�rrrrr��sr��t3rr)r�rrr:rHr2)rrB�t1�t2r��dZt3primerrr�
test_setState�s	zJellyTests.test_setStatecCs�t��}|�tt�t�}t�}t�}||_||_||_||_t�||�}t�	||�}|�
|jtj�t�|�}|�tj
tj	||�|�|j|jd�t�t|�}t�	||�}|�|td|�dS)zA
        Test for class-level security of serialization.
        zIdentity mismatchzA came back: %sN)rr9ZallowInstancesOfrrr!rDr?r&r:rGZ
Unpersistabler<r=rH)rr@rBrDr?Zfriendlyr&Zmeanrrr�test_classSecurity�s$
zJellyTests.test_classSecuritycCs\Gdd�dtj�}t�|tj�|�}d|_t�t�|��}|�|jd�|�|tj�dS)zr
        Test that if Unjellyable is used to deserialize a jellied object,
        state comes out right.
        c@seZdZdS)z7JellyTests.test_unjellyable.<locals>.JellyableTestClassN�rrrrrrr�JellyableTestClass�sr��valueN)r�	Jellyable�setUnjellyableForClassZUnjellyableZ	attributer:rIrG)rr��inputrWrrr�test_unjellyable�szJellyTests.test_unjellyablec	Cs�idg}|fdd�}|fdd�}tdd�}tdd�}td	d
�}||_||_||_tj||d�}tj||d�}|�|j|jj�|�|d
d�|�|j|jd�dS)NrcSs,|dd|d<||d|d<t|d�S)Nrr)rS)�obj�jel�perstrrr�persistentStore	sz:JellyTests.test_persistentStorage.<locals>.persistentStorecSst|�}|d|Srz)�int)ZpidstrZunjr��pidrrr�persistentLoadsz9JellyTests.test_persistentStorage.<locals>.persistentLoadrbrcr
��)r�)r�rzpersistentStore was not called.z$Persistent storage identity failure.)r/rDr?rr:rHrq)	rr�r�r�rBrDr?r�r&rrr�test_persistentStorages


z!JellyTests.test_persistentStoragecCsBt�}t|�}t|�t|�t�|�}t�|�}|�||�dSr()r	rr:�_check_newstyle)rrJZn1r�rKrrr�test_newStyleClassesAttributes"s

z)JellyTests.test_newStyleClassesAttributescCsl|�|j|j�|�|jd�|�|jd�|�t|j�t|j��t|j|j�D]\}}|�||�qRdS)Nr
)rIrr�lenr
�zipr�)rrBrDr&r'rrrr�.szJellyTests._check_newstylecCs`t��}t��}|�t��tj||d�}t��}|�t��tj||d�}|�|j|j	�dS)a
        A L{pb.Referenceable} instance jellies to a structure which unjellies to
        a L{pb.RemoteReference}.  The C{RemoteReference} has a I{luid} that
        matches up with the local object key in the L{pb.Broker} which sent the
        L{Referenceable}.
        �ZinvokerN)
rZ
ReferenceableZBrokerZmakeConnectionrrr:ZassertInZluidZlocalObjects)r�refZjellyBroker�jZ
unjellyBrokerr}rrr�test_referenceable7szJellyTests.test_referenceableN)(rrrrr^rArErLrMrQrRrTrXr]r_rarfrhrirjrorrk�skiprprrrurwryr{r|r~r�r�r�r�r�r�r�r�rrrrr4vsT�






�
		
	r4c@s eZdZdZdd�Zdd�ZdS)�JellyDeprecationTestsz+
    Tests for deprecated Jelly things
    cCsPtj|�|jg�}|�t|�d�|�|ddd�|�|ddt�dS)zD
        L{jelly.instance_atom} is deprecated since 15.0.0.
        rr�messagezltwisted.spread.jelly.instance_atom was deprecated in Twisted 15.0.0: instance_atom is unused within Twisted.�categoryN)rZ
instance_atom�
flushWarnings�test_deprecatedInstanceAtomrIr��DeprecationWarning�r�warningsrrrr�Ps
�
�z1JellyDeprecationTests.test_deprecatedInstanceAtomcCsZt�dddgdgg�|��}|�t|�d�|�|ddd�|�|dd	t�d
S)zI
        Unjellying the instance atom is deprecated with 15.0.0.
        �instance�classz twisted.spread.test.test_jelly.AZ
dictionaryrrr�ztUnjelly support for the instance atom is deprecated since Twisted 15.0.0.  Upgrade peer for modern instance support.r�N)rr:r�rIr�r�r�rrr�%test_deprecatedUnjellyingInstanceAtom`s ��
�
�z;JellyDeprecationTests.test_deprecatedUnjellyingInstanceAtomN)rrrrr�r�rrrrr�Ksr�c@seZdZdd�ZdS)�ClassAcCst|�|_dSr()�ClassBr�rrrrruszClassA.__init__N�rrrrrrrrr�tsr�c@seZdZdd�ZdS)r�cCs
||_dSr()r�)rr�rrrr{szClassB.__init__Nr�rrrrr�zsr�c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�CircularReferenceTestszN
    Tests for circular references handling in the jelly/unjelly process.
    cCs@t�tt�t�tt�t�t�t���}|�|jj|d�dS)N�,Identity not preserved in circular reference)rr�r�r�r:rHr�)rrBrrr�test_simpleCircle�s�z(CircularReferenceTests.test_simpleCirclecCsfGdd�d�}|�}d|_t�}t�tt�t�tt�tj||d�}t�|�}|�|jj|d�dS)Nc@seZdZdS)zHCircularReferenceTests.test_circleWithInvoker.<locals>.DummyInvokerClassNr�rrrr�DummyInvokerClass�sr�r�r�)ZserializingPerspectiver�rr�r�r:ZfailUnlessIdenticalr�)rr�ZdummyInvokerZa0r�Za1rrr�test_circleWithInvoker�s
�z-CircularReferenceTests.test_circleWithInvokercCsPt�}t|d�}|�|�t�t�|��}|�|jt�|�t|j�|g�dS)z�
        Check that a C{set} can contain a circular reference and be serialized
        and unserialized without losing the reference.
        N)	rdr/�addrr:rGr&rIrm)rrsrB�resrrrrf�s

zCircularReferenceTests.test_setcCsPtdd�}t|g�}||_t�t�|��}|�|jt�|�t|j�|g�dS)z�
        Check that a L{frozenset} can contain a circular reference and be
        serialized and unserialized without losing the reference.
        N)r/rgr&rr:rGrIrm)rrBrsr�rrrrh�s

z%CircularReferenceTests.test_frozensetN)rrrrr�r�rfrhrrrrr��s

r�)!rZ
__future__rrrUr[Ztwisted.python.compatrZtwisted.spreadrrZ
twisted.trialrZtwisted.test.proto_helpersrr��objectr	rrrr!r#r$r/ZTestCaser4r�ZCopyableZ
RemoteCopyr�r�r�rrrr�<module>s.
X)