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

��W[ 9�@s<ddlmZmZddlZddlmZzddlZWnek
rLddlZYnXddl	Z	zddl
mZWnek
r~dZ
YnXdZ
zddlZWnddlZYnXddlmZmZmZddlmZGdd	�d	ej�ZGd
d�dej�ZGdd
�d
ej�ZGdd�de�ZGdd�dee�ZGdd�dej�ZGdd�dej�ZGdd�dej�Z Gdd�d�Z!Gdd�de"�Z#Gdd�de"�Z$Gdd�de"�Z%d d!�Z&e�e$e&�Gd"d#�d#�Z'Gd$d%�d%�Z(d&d'�Z)Gd(d)�d)ej�Z*Gd*d+�d+ej�Z+Gd,d-�d-�Z,Gd.d/�d/�Z-Gd0d1�d1ej�Z.Gd2d3�d3ej�Z/ee e*gZ0dS)4�)�division�absolute_importN)�unittest)�StringIOzNo cStringIO available.)�styles�aot�crefutil)�_PY3c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�VersionTestscCsTGdd�dt�at�t��}Gdd�dtjt�at�|�}t��|jsPt	d��dS)Nc@seZdZdd�ZdS)�
NullVersionedcSs
d|_dS)Nr��ok��self�r�=/usr/lib/python3/dist-packages/twisted/test/test_persisted.py�__init__(szNullVersioned.__init__N��__name__�
__module__�__qualname__rrrrrr'src@seZdZdZdd�ZdS)r�cSs
d|_dS�Nrrrrrr�upgradeToVersion1-szNullVersioned.upgradeToVersion1N)rrr�persistenceVersionrrrrrr+szinitial upgrade not run!)
�objectr�pickle�dumpsr�	Versioned�loads�	doUpgrader
�AssertionError)rZpkclZmnvrrr�test_nullVersionUpgrade%s
z$VersionTests.test_nullVersionUpgradecCs�Gdd�dtj�at�}|js$|jr,td��t�|�}dt_t�	|�}t�
�|js\td��|jsjtd��t�|�}t�	|�}t�
�|jdks�td��|jdks�td��dS)	Nc@s6eZdZdZdgZdZdZdd�Zdd�Zdd	�Z	d
S)�MyVersioned��garbagedatarcSsd|_dd�|_dS)NZxxxcSsdS)Nzcant persistr)�qrrr�<lambda>=�z&MyVersioned.__init__.<locals>.<lambda>)Zsomedatar%rrrrr;szMyVersioned.__init__cSs|jd7_dSr)�v3rrrr�upgradeToVersion3?szMyVersioned.upgradeToVersion3cSs|jd7_dSr)�v4rrrr�upgradeToVersion4BszMyVersioned.upgradeToVersion4N)
rrrrZpersistenceForgetsr)r+rr*r,rrrrr#5sr#zhasn't been upgraded yet�zdidn't do version 3 upgradezdidn't do version 4 upgraderzupgraded unnecessarily)rrr#r)r+r!rrrrr )rZmv�pickl�objrrr�test_versionUpgrade3s



z VersionTests.test_versionUpgradecCs�Gdd�dtj�atdd�}tdd�}t�||f�}~~dt_dd�t_t�|�\}}t��|�	|j
d�|�	|j
d�|�|j�|�|j�dS)	Nc@seZdZdd�Zdd�ZdS)�ClassWithCustomHashcSs||_||_dS�N)�unique�hash)rr3r4rrrrUszClassWithCustomHash.__init__cSs|jSr2)r4rrrr�__hash__XszClassWithCustomHash.__hash__N)rrrrr5rrrrr1Tsr1�v1r�v2rcSst|dd�S�N�upgradedT��setattrrrrrr'ar(z3VersionTests.test_nonIdentityHash.<locals>.<lambda>)
rrr1rrrrrr �assertEqualr3�
assertTruer9)rr6r7Zpklrrr�test_nonIdentityHashRs


z!VersionTests.test_nonIdentityHashcs�Gdd�dtj�aGdd�dtj�at�}t�}t�|�t�|�}�~~dt_�fdd�}|t_dt_dd	�t_t�|�}t�	�|�
|jj�dS)
Nc@seZdZdS)�	ToyClassAN�rrrrrrrr?ksr?c@seZdZdS)�	ToyClassBNr@rrrrrAmsrArcst���|_t��dSr2)rr�yrr r�ZpklBrrrtszWVersionTests.test_upgradeDeserializesObjectsRequiringUpgrade.<locals>.upgradeToVersion1cSst|dd�Sr8r:rrrrr'yr(zNVersionTests.test_upgradeDeserializesObjectsRequiringUpgrade.<locals>.<lambda>)
rrr?rArrrrrr r=rBr9)r�xrBZpklArrrCr�/test_upgradeDeserializesObjectsRequiringUpgradeis

z<VersionTests.test_upgradeDeserializesObjectsRequiringUpgradeN)rrrr"r0r>rErrrrr
$sr
c@seZdZdS)�VersionedSubClassNr@rrrrrF�srFc@seZdZdS)�SecondVersionedSubClassNr@rrrrrG�srGc@seZdZdS)�VersionedSubSubClassNr@rrrrrH�srHc@seZdZdS)�VersionedDiamondSubClassNr@rrrrrI�srIc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�AybabtuTestsz�
    L{styles._aybabtu} gets all of classes in the inheritance hierarchy of its
    argument that are strictly between L{Versioned} and the class itself.
    cCs|�t�tj�g�dS)zM
        L{styles._aybabtu} of L{Versioned} itself is an empty list.
        N)r<r�_aybabturrrrr�test_aybabtuStrictEmpty�sz$AybabtuTests.test_aybabtuStrictEmptycCs|�t�t�g�dS)z�
        There are no classes I{between} L{VersionedSubClass} and L{Versioned},
        so L{styles._aybabtu} returns an empty list.
        N)r<rrKrFrrrr�test_aybabtuStrictSubclass�sz'AybabtuTests.test_aybabtuStrictSubclasscCs|�t�t�tg�dS)z�
        With a sub-sub-class of L{Versioned}, L{styles._aybabtu} returns a list
        containing the intervening subclass.
        N)r<rrKrHrFrrrr�test_aybabtuSubsubclass�s�z$AybabtuTests.test_aybabtuSubsubclasscCs|�t�t�tttg�dS)z�
        For a diamond-shaped inheritance graph, L{styles._aybabtu} returns a
        list containing I{both} intermediate subclasses.
        N)r<rrKrIrHrFrGrrrr�test_aybabtuStrict�s�zAybabtuTests.test_aybabtuStrictN)rrr�__doc__rLrMrNrOrrrrrJ�s
	rJc@seZdZdd�ZdS)�MyEphemeralcCs
||_dSr2�rD�rrDrrrr�szMyEphemeral.__init__NrrrrrrQ�srQc@seZdZdd�ZdS)�EphemeralTestscCs\td�}|�|jt�|�|jd�t�|�}t�|�}|�|jtj�|�	t
|d��dS)N�rD)rQr<�	__class__rDrrrr�	EphemeralZassertFalse�hasattr)r�or.rrr�test_ephemeral�s

zEphemeralTests.test_ephemeralN)rrrrZrrrrrT�srTc@seZdZdd�Zdd�ZdS)�
PickleablecCs
||_dSr2rRrSrrrr�szPickleable.__init__cCs|jSr2rRrrrr�getX�szPickleable.getXN)rrrrr\rrrrr[�sr[c@seZdZdZdd�ZdS)�
NotPickleablez)
    A class that is not pickleable.
    cCstd��dS)z9
        Raise an exception instead of pickling.
        zNot serializable.N)�	TypeErrorrrrr�
__reduce__�szNotPickleable.__reduce__N)rrrrPr_rrrrr]�sr]c@seZdZdZdd�ZdS)�CopyRegisteredzb
    A class that is pickleable only because it is registered with the
    C{copyreg} module.
    cCst�|_dS)zE
        Ensure that this object is normally not pickleable.
        N)r]Z
notPickleablerrrrr�szCopyRegistered.__init__N)rrrrPrrrrrr`�sr`c@seZdZdZdS)�CopyRegisteredLoadedz2
    L{CopyRegistered} after unserialization.
    N)rrrrPrrrrra�sracCstdfS)z�
    Externally implement C{__reduce__} for L{CopyRegistered}.

    @param cr: The L{CopyRegistered} instance.

    @return: a 2-tuple of callable and argument list, in this case
        L{CopyRegisteredLoaded} and no arguments.
    r)ra)Zcrrrr�reduceCopyRegistered�s	rbc@seZdZdZdd�ZdS)�A�
    dummy class
    cCsdSr2rrrrr�amethodsz	A.amethodN)rrrrPrerrrrrc
srcc@seZdZdZdd�ZdS)�BrdcCsdSr2rrrrr�bmethodsz	B.bmethodN)rrrrPrgrrrrrfsrfcCsdSr2rrrrr�funktionsrhc@sJeZdZdZdd�Zdd�Zejdkr,de_dd	�Z	d
d�Z
erFee
_dS)
�
PicklingTestsz$Test pickling of extra object types.cCs$t�t�}t�|�}|�|t�dSr2)rrrrr<�rr.rYrrr�test_module!s

zPicklingTests.test_modulecCs(t�tj�}t�|�}|�|tj�dS)zt
        After importing L{twisted.persisted.styles}, it is possible to pickle
        classmethod objects.
        N)rrr[r\rr<rjrrr�test_classMethod's
zPicklingTests.test_classMethod)rUr-z_As of Python 3.4 it is no longer possible to globally change the behavior of function pickling.cCsFtd�}t�|j�}t�|�}|�|�d�|�t|�t|j��dS)Nr-)r[rrr\rr<�type)rr/r.rYrrr�test_instanceMethod7s

z!PicklingTests.test_instanceMethodcCsLt�}|�d�t�|�}t�|�}|�t|�t|��|�|��d�dS)N�abc)�_oldStyleCStringIO�writerrrr<rm�getvalue)r�fr.rYrrr�
test_stringIO>s


zPicklingTests.test_stringION)rrrrPrkrl�sys�version_info�skiprnrt�skipStringIOrrrrris	
�ric@s eZdZdZesdZdd�ZdS)�StringIOTransitionTestsz�
    When pickling a cStringIO in Python 2, it should unpickle as a BytesIO or a
    StringIO in Python 3, depending on the type of its contents.
    z4In Python 2 we can still unpickle cStringIO as such.cCs0d}t�|�}|�|tj�|�|��d�dS)zg
        A cStringIO pickled with bytes in it will yield an L{io.BytesIO} on
        python 3.
        sEctwisted.persisted.styles
unpickleStringI
p0
(S'test'
p1
I0
tp2
Rp3
.ZtestN)rr�assertIsInstance�iorr<rr)rZpickledStringIWithTextZloadedrrr�test_unpickleBytesIOUs
�
z,StringIOTransitionTests.test_unpickleBytesION)rrrrPr	rwr|rrrrryKsryc@seZdZdd�ZdS)�
EvilSourcerorcCs||_||j_||jj_dSr2)�a�b�crSrrrreszEvilSourceror.__init__Nrrrrrr}dsr}c@seZdZdd�Zdd�ZdS)�NonDictStatecCs|jSr2��staterrrr�__getstate__kszNonDictState.__getstate__cCs
||_dSr2r�)rr�rrr�__setstate__mszNonDictState.__setstate__N)rrrr�r�rrrrr�jsr�c@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�AOTTestsc
CsFddddtddd�ddtjddtf
}t�t�|��}|�||�dS)	Nrg@y@Tr$rU�hello�world)�sliceru�maxsize�Ellipsisr�unjellyFromSource�
jellyToSourcer<)rr/ZrtObjrrr�test_simpleTypesqs�zAOTTests.test_simpleTypescCsLt�}t�}|j|_||_t�t�|��jj}|�t�|�j	t�
|��dSr2)rcrfrgr~rr�r�r<Z
_selfOfMethodrVZ_classOfMethod)rr~rZim_rrr�test_methodSelfIdentityxs�z AOTTests.test_methodSelfIdentitycCsLt�}t�}|j|_||_tj}t`z|�ttjt�|��W5|t_XdS)z�
        If a class change after an instance has been created,
        L{aot.unjellyFromSource} shoud raise a C{TypeError} when trying to
        unjelly the instance.
        N)	rcrfrgr~�assertRaisesr^rr�r�)rr~rZsavedbmethodrrr�test_methodNotSelfIdentity�s
�z#AOTTests.test_methodNotSelfIdentitycCs&Gdd�dt�}|�ttj|��dS)z�
        L{aot.jellyToSource} should raise a C{TypeError} when trying to jelly
        an unknown type without a C{__dict__} property or C{__getstate__}
        method.
        c@seZdZedd��ZdS)z2AOTTests.test_unsupportedType.<locals>.UnknownTypecSs
t��dSr2)�AttributeErrorrrrr�__dict__�sz;AOTTests.test_unsupportedType.<locals>.UnknownType.__dict__N)rrr�propertyr�rrrr�UnknownType�sr�N)rr�r^rr�)rr�rrr�test_unsupportedType�szAOTTests.test_unsupportedTypecCs�t��j}d|d�}dddddddd	d	ttj|tg}t|�}|�|�|�|�|�|�t�t�||g��}|d
|dks�t	�|dd
d�|d
d�ks�t	�dS)Nr�)r��methodrr$rUzhe	llo

"x world!ugoodbye 
	တ world!g�?�dr�)
rZ
AOTJellierZ	jellyToAOrrh�tuple�appendr�r�r!)rZaj�d�l�t�ujrrr�test_basicIdentity�s(

�


zAOTTests.test_basicIdentitycCs,t�}d|_t�t�|��j|jks(t�dS)Nz	meringue!)r�r�rr�r�r!)rr~rrr�test_nonDictState�szAOTTests.test_nonDictStatecCs"t�t�t���}|�|t�dS)z�
        L{aot.jellyToSource} and L{aot.unjellyFromSource} honor functions
        registered in the pickle copy registry.
        N)rr�r�r`rzra)rr�rrr�test_copyReg�szAOTTests.test_copyRegcCsVttg��}t�|�}t�|�}|j|ks.t�|jj|jks@t�|j|jjk	sRt�dSr2)r}r�
jellyToAOT�unjellyFromAOTr~r!rr�)rrY�j1�ojrrr�test_funkyReferences�s

zAOTTests.test_funkyReferencescCsfg}|df}|�|�t�|�}t�|�}|�|dt�|�|dd|�|�|ddd�dS)zS
        L{aot.jellyToAOT} can persist circular references through tuples.
        i�rrN)r�rr�r�rzr�ZassertIsr<)rr�r�r�r�rrr�test_circularTuple�s


zAOTTests.test_circularTupleN)rrrr�r�r�r�r�r�r�r�r�rrrrr�ps

	
r�c@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�
CrefUtilTestsz 
    Tests for L{crefutil}.
    cCs t�i�}|�t|jdd�dS)zO
        L{crefutil._DictKeyAndValue} only support keys C{0} and C{1}.
        r$rUN)rZ_DictKeyAndValuer��RuntimeError�__setitem__�rr�rrr�test_dictUnknownKey�s
z!CrefUtilTests.test_dictUnknownKeycCs&t��}d|d<|�t|jdd�dS)zI
        L{crefutil._Defer} can be assigned a key only one time.
        rrN)rZ_Deferr�r�r�r�rrr�test_deferSetMultipleTimes�sz(CrefUtilTests.test_deferSetMultipleTimescCs(t�dddgt�}|�t|jid�dS)z�
        A L{crefutil._Container} where all of its elements are known at
        construction time is nonsensical and will result in errors in any call
        to addDependant.
        rr$rUz	ignore-meN)rZ
_Container�listr�r!ZaddDependant)rZ	containerrrr�&test_containerWhereAllElementsAreKnown�s�z4CrefUtilTests.test_containerWhereAllElementsAreKnowncCs|�tt�jt��d�dS)z�
        If a dictionary key contains a circular reference (which is probably a
        bad practice anyway) it will be resolved by a
        L{crefutil._DictKeyAndValue}, not by placing a L{crefutil.NotKnown}
        into a dictionary key.
        �valueN)r�r!�dictr�r�NotKnownrrrr�.test_dontPutCircularReferencesInDictionaryKeys�s
�z<CrefUtilTests.test_dontPutCircularReferencesInDictionaryKeyscCs|�tt�dt��t��dS)z�
        L{crefutil._InstanceMethod} raises L{AssertionError} to indicate it
        should not be called.  This should not be possible with any of its API
        clients, but is provided for helping to debug.
        Zno_nameN)r�r!rZ_InstanceMethodr�rmrrrr�*test_dontCallInstanceMethodsThatArentReady
s��z8CrefUtilTests.test_dontCallInstanceMethodsThatArentReadyN)	rrrrPr�r�r�r�r�rrrrr��s	r�)1Z
__future__rrruZ
twisted.trialrZcPickler�ImportErrorr{�	cStringIOrrprx�copyregZcopy_regZtwisted.persistedrrrZtwisted.python.compatr	ZTestCaser
rrFrGrHrIrJrWrQrTr[rr]r`rarbrcrfrhriryr}r�r�r�Z	testCasesrrrr�<module>sT
])


-n8