%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�f�:����ddlmZddlZddlZddlZddlZddlZddlmZm	Z	m
Z
mZddlmZddl
mZmZmZddlmZddlmZGd�d	e�ZGd
�dej,�ZGd�d
ej,�ZGd�de�ZGd�dee�ZGd�de�ZGd�dej8�ZGd�de�ZGd�d�ZGd�d�Z Gd�d�Z!Gd�d�Z"d3d �Z#eje!e#�Gd!�d"�Z$Gd#�d$�Z%d4d%�Z&Gd&�d'e�Z'Gd(�d)e�Z(Gd*�d+�Z)Gd,�d-�Z*e
ed.e+fZ,Gd/�d0e�Z-Gd1�d2e�Z.eee'gZ/y)5�)�annotationsN)�Any�Callable�List�Tuple)�NoReturn)�aot�crefutil�styles)�unittest)�TestCasec�,�eZdZdd�Zdd�Zdd�Zdd�Zy)�VersionTestsc��Gd�d�atjt��}Gd�dtj�atj
|�}tj�|jsJd��y)Nc��eZdZdd�Zy)�
NullVersionedc��d|_y)Nr��ok��selfs �=/usr/lib/python3/dist-packages/twisted/test/test_persisted.py�__init__zNullVersioned.__init__�	�����N��return�None��__name__�
__module__�__qualname__r�rrrrs��
rrc��eZdZdZdd�Zy)r�c��d|_y�Nr%rrs r�upgradeToVersion1zNullVersioned.upgradeToVersion1"rrNr)r r!r"�persistenceVersionr(r#rrrrs
��!"��
rzinitial upgrade not run!)r�pickle�dumpsr�	Versioned�loads�	doUpgrader)r�pkcl�mnvs   r�test_nullVersionUpgradez$VersionTests.test_nullVersionUpgrades^��	�	��|�|�M�O�,��	�F�,�,�	��l�l�4� �������v�v�1�1�1�vrc�:�Gd�dtj�at�}|js|jrJd��tj|�}dt_tj|�}tj�|jsJd��|jsJd��tj|�}tj|�}tj�|jdk(sJd��|jdk(sJd��y)	Nc�6�eZdZdZdgZdZdZdd�Zdd�Zdd�Z	y)	�MyVersioned��garbagedatarc�"�d|_d�|_y)N�xxxc��y)Nzcant persistr#)�qs r�<lambda>z&MyVersioned.__init__.<locals>.<lambda>5s�r)�somedatar6rs rrzMyVersioned.__init__3s�� %��
�#;�� rc�.�|xjdz
c_yr')�v3rs r�upgradeToVersion3zMyVersioned.upgradeToVersion37������1��rc�.�|xjdz
c_yr')�v4rs r�upgradeToVersion4zMyVersioned.upgradeToVersion4:r@rNr)
r r!r"r)�persistenceForgetsr>rBrr?rCr#rrr4r4,s)��!"��"/����B��B�
<�
�
rr4zhasn't been upgraded yet�zdidn't do version 3 upgradezdidn't do version 4 upgrader%zupgraded unnecessarily)
rr,r4r>rBr*r+r)r-r.)r�mv�pickl�objs    r�test_versionUpgradez VersionTests.test_versionUpgrade)s���	�&�*�*�	�"�]���E�E�R�U�U�?�%?�?�#����R� ��)*��&��l�l�5�!�������v�v�4�4�4�v��v�v�4�4�4�v����S�!���l�l�5�!�������v�v��{�4�4�4�{��v�v��{�4�4�4�{rc��Gd�dtj�atdd�}tdd�}tj||f�}~~dt_d�t_tj|�\}}tj�|j|jd�|j|jd�|j|j�|j|j�y)Nc��eZdZdd�Zdd�Zy)�ClassWithCustomHashc� �||_||_y�N)�unique�hash)rrOrPs   rrzClassWithCustomHash.__init__Os��$��� ��	rc��|jSrN)rPrs r�__hash__zClassWithCustomHash.__hash__Ss���y�y� rN)rO�strrP�intrr�rrT)r r!r"rrRr#rrrLrLNs��
!�
!rrL�v1r�v2r%c��t|dd�S�N�upgradedT��setattrrs rr;z3VersionTests.test_nonIdentityHash.<locals>.<lambda>\s��W��*�d�>
�r)
rr,rLr*r+r)r(r-r.�assertEqualrO�
assertTruerZ)rrVrW�pkls    r�test_nonIdentityHashz!VersionTests.test_nonIdentityHashKs���	!�&�"2�"2�	!�!��q�
)��
 ��q�
)���l�l�B��8�$����12��.�1
��-����c�"���B�����������D�)�������D�)�������$�������$rc����Gd�dtj�aGd�dtj�at�}t�}t	j
|�t	j
|�c}�~~dt_d�fd�}|t_dt_d	d�}|t_t	j|�}tj�|j|jj�y)
Nc��eZdZy)�	ToyClassAN�r r!r"r#rrrcrci���rrcc��eZdZy)�	ToyClassBNrdr#rrrgrglrerrgr%c�b��tj��|_tj�yrN)r*r-�yrr.)r�pklBs �rr(zWVersionTests.test_upgradeDeserializesObjectsRequiringUpgrade.<locals>.upgradeToVersion1us����\�\�$�'�D�F����rc��t|dd�yrYr[rs r�setUpgradedzQVersionTests.test_upgradeDeserializesObjectsRequiringUpgrade.<locals>.setUpgraded|s���D�*�d�+r)rrrr)r�objectrr)
rr,rcrgr*r+r)r(r-r.r^rirZ)r�xri�pklAr(rlrjs      @r�/test_upgradeDeserializesObjectsRequiringUpgradez<VersionTests.test_upgradeDeserializesObjectsRequiringUpgradefs����	��(�(�	�	��(�(�	�
�K���K���\�\�!�_�f�l�l�1�o�
��d�
�q�'(�	�$�	�'8�	�#�'(�	�$�	,�'2�	�#��L�L����������������%rNr)r r!r"r1rIr`rpr#rrrrs��2�& 5�D%�6&rrc��eZdZy)�VersionedSubClassNrdr#rrrrrr����rrrc��eZdZy)�SecondVersionedSubClassNrdr#rrruru�rsrruc��eZdZy)�VersionedSubSubClassNrdr#rrrwrw�rsrrwc��eZdZy)�VersionedDiamondSubClassNrdr#rrryry�rsrryc�0�eZdZdZdd�Zdd�Zdd�Zdd�Zy)�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.
    c�j�|jtjtj�g�y)zM
        L{styles._aybabtu} of L{Versioned} itself is an empty list.
        N)r]r�_aybabtur,rs r�test_aybabtuStrictEmptyz$AybabtuTests.test_aybabtuStrictEmpty�s#��	
�������)9�)9�:�B�?rc�V�|jtjt�g�y)z�
        There are no classes I{between} L{VersionedSubClass} and L{Versioned},
        so L{styles._aybabtu} returns an empty list.
        N)r]rr}rrrs r�test_aybabtuStrictSubclassz'AybabtuTests.test_aybabtuStrictSubclass�s��
	
������):�;�R�@rc�`�|jtjt�tg�y)z�
        With a sub-sub-class of L{Versioned}, L{styles._aybabtu} returns a list
        containing the intervening subclass.
        N)r]rr}rwrrrs r�test_aybabtuSubsubclassz$AybabtuTests.test_aybabtuSubsubclass�s"��
	
������)=�>�AR�@S�Trc�t�|jtjt�tt
tg�y)z�
        For a diamond-shaped inheritance graph, L{styles._aybabtu} returns a
        list containing I{both} intermediate subclasses.
        N)r]rr}ryrwrrrurs r�test_aybabtuStrictzAybabtuTests.test_aybabtuStrict�s+��
	
����O�O�4�5�
!�#4�6M�N�	
rNr)r r!r"�__doc__r~r�r�r�r#rrr{r{�s���
@�A�U�
rr{c��eZdZdd�Zy)�MyEphemeralc��||_yrN�rn�rrns  rrzMyEphemeral.__init__��	����rN�rnrTrrrr#rrr�r��s��rr�c��eZdZdd�Zy)�EphemeralTestsc�p�td�}|j|jt�|j|jd�t	j
|�}t	j|�}|j|jtj�|jt|d��y)N�rn)r�r]�	__class__rnr*r+r-r�	Ephemeral�assertFalse�hasattr)r�orGs   r�test_ephemeralzEphemeralTests.test_ephemeral�s|����N��������k�2�������a� ����Q����L�L����������f�&6�&6�7������C��)rNr)r r!r"r�r#rrr�r��s��	*rr�c��eZdZdd�Zdd�Zy)�
Pickleablec��||_yrNr�r�s  rrzPickleable.__init__�r�rc��|jSrNr�rs r�getXzPickleable.getX�s���v�v�
rNr�rU)r r!r"rr�r#rrr�r��s���rr�c��eZdZdZdd�Zy)�
NotPickleablez)
    A class that is not pickleable.
    c��td��)z9
        Raise an exception instead of pickling.
        zNot serializable.)�	TypeErrorrs r�
__reduce__zNotPickleable.__reduce__�s���+�,�,rN�rr)r r!r"r�r�r#rrr�r��s���-rr�c��eZdZdZdd�Zy)�CopyRegisteredzb
    A class that is pickleable only because it is registered with the
    C{copyreg} module.
    c�"�t�|_y)zE
        Ensure that this object is normally not pickleable.
        N)r��
notPickleablers rrzCopyRegistered.__init__�s��+�_��rNr)r r!r"r�rr#rrr�r��s���
-rr�c��eZdZdZy)�CopyRegisteredLoadedz2
    L{CopyRegistered} after unserialization.
    N)r r!r"r�r#rrr�r��s��rr�c��tdfS)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#)r�)�crs r�reduceCopyRegisteredr��s�� ��#�#rc�$�eZdZUdZded<dd�Zy)�A�
    dummy class
    zCallable[[], None]�bmethodc��yrNr#rs r�amethodz	A.amethod
���rNr)r r!r"r��__annotations__r�r#rrr�r�s��� ��
rr�c�$�eZdZUdZded<dd�Zy)�Br�r��ac��yrNr#rs rr�z	B.bmethodr�rNr)r r!r"r�r�r�r#rrr�r�s���	�D�
rr�c��yrNr#r#rr�funktionr�s��rc� �eZdZdZdd�Zdd�Zy)�
PicklingTestsz$Test pickling of extra object types.c��tjt�}tj|�}|j	|t�yrN)r*r+rr-r])rrGr�s   r�test_modulezPicklingTests.test_module s.�����V�$���L�L��������F�#rc��td�}tj|j�}tj|�}|j|�d�|jt
|�t
|j��y)NrE)r�r*r+r�r-r]�type)rrHrGr�s    r�test_instanceMethodz!PicklingTests.test_instanceMethod%sY����m�����S�X�X�&���L�L���������a� �����a��$�s�x�x�.�1rNr)r r!r"r�r�r�r#rrr�r�s��.�$�
2rr�c��eZdZdZdd�Zy)�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.
    c��d}tj|�}|j|tj�|j|j
�d�y)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
.�testN)r*r-�assertIsInstance�io�StringIOr]�getvalue)r�pickledStringIWithText�loadeds   r�test_unpickleBytesIOz,StringIOTransitionTests.test_unpickleBytesIO3sH��
-�	����4�5�����f�b�k�k�2�������*�F�3rNr)r r!r"r�r�r#rrr�r�-s���
4rr�c�4�eZdZUded<ded<ded<dd�Zy)�
EvilSourcerorr��brm�cc�j�||_||j_||jj_yrN)r�r�r�r�s  rrzEvilSourceror.__init__Fs#����������������
rN)rnrmrr)r r!r"r�rr#rrr�r�As������
�I�rr�c�(�eZdZUded<dd�Zdd�Zy)�NonDictStaterS�statec��|jSrN�r�rs r�__getstate__zNonDictState.__getstate__Os���z�z�rc��||_yrNr�)rr�s  r�__setstate__zNonDictState.__setstate__Rs	����
rN)rrS)r�rSrr)r r!r"r�r�r�r#rrr�r�Ls���J��rr��_CircularTupleTypec�\�eZdZdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Z	dd�Z
dd	�Zdd
�Zy)
�AOTTestsc
���ddddtddd�ddtjdzdtf
}t	j
t	j|��}|j||�y)	Nr%g@y@Tr5r��hello�world)�slice�sys�maxsize�Ellipsisr	�unjellyFromSource�
jellyToSourcer])rrH�rtObjs   r�test_simpleTypeszAOTTests.test_simpleTypesZsd��
�����!�Q��N����K�K�!�O���
���%�%�c�&7�&7��&<�=������e�$rc�X�t�}t�}|j|_||_t	j
t	j|��jj}|jt	j|�jt	j|��yrN)r�r�r�r�r	r�r�r]�
_selfOfMethodr��_classOfMethod)rr�r��im_s    r�test_methodSelfIdentityz AOTTests.test_methodSelfIdentityjsu��
�C��
�C���I�I��	�����#�#�C�$5�$5�a�$8�9�;�;�C�C������*�*�3�/�9�9�3�;M�;M�c�;R�Src�0�t�}t�}|j|_||_tj}t`	|j	t
tjt
j|��|t_y#|t_wxYw)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)	r�r�r�r��assertRaisesr�r	r�r�)rr�r��savedbmethods    r�test_methodNotSelfIdentityz#AOTTests.test_methodNotSelfIdentityrsj��
�C��
�C���I�I��	�����y�y��
�I�	%����i��)>�)>��@Q�@Q�RS�@T�U�$�A�I���A�I�s�8B�
Bc�l�Gd�d�}|jttj|��y)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�0�eZdZedd��Zedd��Zy)�2AOTTests.test_unsupportedType.<locals>.UnknownTypec��t��rN��AttributeErrorrs r�__dict__z;AOTTests.test_unsupportedType.<locals>.UnknownType.__dict__����$�&�&rc��t��rNr�rs rr�z?AOTTests.test_unsupportedType.<locals>.UnknownType.__getstate__�r�rNr�)r r!r"�propertyr�r�r#rr�UnknownTyper��s(��
�
'��
'��
'��
'rr�N)r�r�r	r�)rr�s  r�test_unsupportedTypezAOTTests.test_unsupportedType�s(��	'�	'�	
���)�S�%6�%6��
�Frc��tj�j}d|d�}dddddddd	d	zttj|tg}t|�}|j
|�|j
|�|j
|�tjtj||g��}|d
|dusJ�|dd
d|d
dk(sJ�y)Nr�)r��methodr%r5r�zhe	llo

"x world!ugoodbye 
	တ world!g�?�dr�)	r	�
AOTJellier�	jellyToAOrr��tuple�appendr�r�)r�aj�d�l�t�ujs      r�test_basicIdentityzAOTTests.test_basicIdentity�s����^�^�
�
'�
'����,��
�
�
�"�'�
����H���N�N�
��

��
�!�H��	�����	�����	�����
�
"�
"�3�#4�#4�a��V�#<�
=���!�u��1��~��~��!�u�Q�q�z�Q�q��V�#�#�#rc��t�}d|_tjtj|��j|jk(sJ�y)Nz	meringue!)r�r�r	r�r�)rr�s  r�test_nonDictStatezAOTTests.test_nonDictState�s>���N������$�$�S�%6�%6�q�%9�:�@�@�A�G�G�K�K�Krc��tjtjt���}|j	|t
�y)z�
        L{aot.jellyToSource} and L{aot.unjellyFromSource} honor functions
        registered in the pickle copy registry.
        N)r	r�r�r�r�r�)rrs  r�test_copyRegzAOTTests.test_copyReg�s3��
�
"�
"�3�#4�#4�^�5E�#F�
G�����b�"6�7rc�0�ttg��}tj|�}tj|�}|j|usJ�|jj
|j
usJ�|j|jjusJ�yrN)r�r	�
jellyToAOT�unjellyFromAOTr�r�r�)rr��j1�ojs    r�test_funkyReferenceszAOTTests.test_funkyReferences�sq���-��+�,��
�^�^�A�
��
�
�
��
#���t�t�r�z��z��t�t�v�v����~��~��t�t�2�4�4�6�6�!�!�!rc��g}|df}|j|�tj|�}tj|�}|j	|dt
�|j
|dd|�|j|ddd�y)zS
        L{aot.jellyToAOT} can persist circular references through tuples.
        i�rr%N)rr	rrr�r�assertIsr])rrrrrs     r�test_circularTuplezAOTTests.test_circularTuple�s}��!#��
��I��	�����
�^�^�A�
��
�
�
��
#�����b��e�U�+��
�
�b��e�A�h��#�����A��q��4�(rc�|�|jtjddgii�tjd��y)z:
        The generated serialization is indented.
        r�r�z|                app={
                  'hello':{
                    'world':[],
                    },
                  }N)r]r	r��textwrap�dedentrs r�
testIndentifyzAOTTests.testIndentify�s:��	
������w��"�
�6�7��O�O��
�
	
rNr)
r r!r"r�r�r�r�rr
rrrrr#rrr�r�Ys7��%� T�%�"G�$$�6L�
8�"�)�
rr�c�8�eZdZdZdd�Zdd�Zdd�Zdd�Zdd�Zy)	�
CrefUtilTestsz 
    Tests for L{crefutil}.
    c�r�tji�}|jt|jdd�y)zO
        L{crefutil._DictKeyAndValue} only support keys C{0} and C{1}.
        r5r�N)r
�_DictKeyAndValuer��RuntimeError�__setitem__�rrs  r�test_dictUnknownKeyz!CrefUtilTests.test_dictUnknownKey�s,��
�%�%�b�)�����,��
�
�q�!�<rc�z�tj�}d|d<|jt|jdd�y)zI
        L{crefutil._Defer} can be assigned a key only one time.
        r%rN)r
�_Deferr�rrr s  r�test_deferSetMultipleTimesz(CrefUtilTests.test_deferSetMultipleTimes�s1��
�O�O�����!�����,��
�
�q�!�<rc��tjgd�t�}|jt|j
id�y)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.
        )r%r5r�z	ignore-meN)r
�
_Container�listr��AssertionError�addDependant)r�	containers  r�&test_containerWhereAllElementsAreKnownz4CrefUtilTests.test_containerWhereAllElementsAreKnown�s0���'�'�	�4�8�	����.�)�*@�*@�"�k�Rrc�|�|jtt�jt	j
�d�y)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(�dictrr
�NotKnownrs r�.test_dontPutCircularReferencesInDictionaryKeysz<CrefUtilTests.test_dontPutCircularReferencesInDictionaryKeyss,��	
����D�F�.�.��0A�0A�0C�W�	
rc��|jttjdtj�t
��y)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.
        �no_nameN)r�r(r
�_InstanceMethodr/r�rs r�*test_dontCallInstanceMethodsThatArentReadyz8CrefUtilTests.test_dontCallInstanceMethodsThatArentReadys0��	
�����$�$�Y��0A�0A�0C�T�J�	
rNr)	r r!r"r�r!r$r+r0r4r#rrrr�s!���=�=�S�	
�	
rr)r�rmrz,tuple[type[CopyRegisteredLoaded], tuple[()]]r)0�
__future__r�copyregr�r*r�r�typingrrrrr�twisted.persistedr	r
r�
twisted.trialr�twisted.trial.unittestr
rr,rrrurwryr{r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rTr�r�r�	testCasesr#rr�<module>r<st��#��	�
�
��-�-��4�3�"�+�n&�8�n&�b	��(�(�	�	�f�.�.�	�	�,�	�	�3�5L�	�"
�8�"
�J�&�"�"��

*�X�
*���	-�	-�
-�
-���	$�����~�3�4�
�
�
�
�	�
2�H�
2� 4�h�4�(�����%� 4�c� 9�:�;��H
�x�H
�V1
�H�1
�h�>�=�9�	r

Zerion Mini Shell 1.0