Ϫf:ddlmZddlZddlZddlZddlZddlZddlmZm Z m Z m Z ddlm Z ddl mZmZmZddlmZddlmZGdd eZGd d ej,ZGd d ej,ZGddeZGddeeZGddeZGddej8ZGddeZGddZGddZ GddZ!GddZ"d3d Z#eje!e#Gd!d"Z$Gd#d$Z%d4d%Z&Gd&d'eZ'Gd(d)eZ(Gd*d+Z)Gd,d-Z*e e d.e+fZ,Gd/d0eZ-Gd1d2eZ.eee'gZ/y)5) annotationsN)AnyCallableListTuple)NoReturn)aotcrefutilstyles)unittest)TestCasec,eZdZddZddZddZddZy) VersionTestscGddatjt}Gddtjatj |}tj |jsJdy)NceZdZddZy) NullVersionedcd|_y)Nrokselfs =/usr/lib/python3/dist-packages/twisted/test/test_persisted.py__init__zNullVersioned.__init__ NreturnNone__name__ __module__ __qualname__rrrrrs rrceZdZdZddZy)rcd|_yNr%rrs rupgradeToVersion1zNullVersioned.upgradeToVersion1"rrNr)r r!r"persistenceVersionr(r#rrrrs !"  rzinitial upgrade not run!)rpickledumpsr Versionedloads doUpgrader)rpkclmnvs rtest_nullVersionUpgradez$VersionTests.test_nullVersionUpgrades^  ||MO, F,,  ll4 vv111vrc:Gddtjat}|js |jrJdt j |}dt_t j|}tj|jsJd|jsJdt j |}t j|}tj|jdk(sJd|jdk(sJdy) Nc6eZdZdZdgZdZdZddZddZddZ y) MyVersioned garbagedatarc"d|_d|_y)Nxxxcy)Nz cant persistr#)qs rz&MyVersioned.__init__..5sr)somedatar6rs rrzMyVersioned.__init__3s % #; rc.|xjdz c_yr')v3rs rupgradeToVersion3zMyVersioned.upgradeToVersion371 rc.|xjdz c_yr')v4rs rupgradeToVersion4zMyVersioned.upgradeToVersion4:r@rNr) r r!r"r)persistenceForgetsr>rBrr?rCr#rrr4r4,s)!" "/ BB <  rr4zhasn't been upgraded yetzdidn't do version 3 upgradezdidn't do version 4 upgrader%zupgraded unnecessarily) r r,r4r>rBr*r+r)r-r.)rmvpicklobjs rtest_versionUpgradez VersionTests.test_versionUpgrade)s &** "]EERUU?%??# R )* &ll5!vv444vvv444v S!ll5!vv{444{vv{444{rcGddtjatdd}tdd}tj||f}~~dt_dt_tj|\}}tj|j|jd|j|jd|j|j|j|jy)NceZdZddZddZy)ClassWithCustomHashc ||_||_yN)uniquehash)rrOrPs rrzClassWithCustomHash.__init__Os$   rc|jSrN)rPrs r__hash__zClassWithCustomHash.__hash__Ss yy rN)rOstrrPintrrrrT)r r!r"rrRr#rrrLrLNs  ! !rrLv1rv2r%ct|ddSNupgradedTsetattrrs rr;z3VersionTests.test_nonIdentityHash..\sW *d> r) r r,rLr*r+r)r(r-r. assertEqualrO assertTruerZ)rrVrWpkls rtest_nonIdentityHashz!VersionTests.test_nonIdentityHashKs !&"2"2 !!q ) q )llB8$ 12.1 -c"B D) D)  $  $rcGddtjaGddtjat}t}t j |t j |c}~~dt_dfd }|t_dt_d d}|t_t j|}tj|j|jjy) Nc eZdZy) ToyClassANr r!r"r#rrrcrci rrcc eZdZy) ToyClassBNrdr#rrrgrglrerrgr%cbtj|_tjyrN)r*r-yr r.)rpklBs rr(zWVersionTests.test_upgradeDeserializesObjectsRequiringUpgrade..upgradeToVersion1us\\$'DF    rct|ddyrYr[rs r setUpgradedzQVersionTests.test_upgradeDeserializesObjectsRequiringUpgrade..setUpgraded|s D*d +r)rrrr)robjectrr) r r,rcrgr*r+r)r(r-r.r^rirZ)rxripklAr(rlrjs @r/test_upgradeDeserializesObjectsRequiringUpgradezAR@STrct|jtjttt t gy)z For a diamond-shaped inheritance graph, L{styles._aybabtu} returns a list containing I{both} intermediate subclasses. N)r]r r}ryrwrrrurs rtest_aybabtuStrictzAybabtuTests.test_aybabtuStricts+  OO4 5 !#46M N rNr)r r!r"__doc__r~rrrr#rrr{r{s @ AU rr{ceZdZddZy) MyEphemeralc||_yrNrnrrns rrzMyEphemeral.__init__ rNrnrTrrrr#rrrrsrrceZdZddZy)EphemeralTestscptd}|j|jt|j|jdt j |}t j |}|j|jtj|jt|dy)Nrn) rr] __class__rnr*r+r-r Ephemeral assertFalsehasattr)rorGs rtest_ephemeralzEphemeralTests.test_ephemerals| N k2 a  Q LL  f&6&67 C)rNr)r r!r"rr#rrrrs *rrceZdZddZddZy) Pickleablec||_yrNrrs rrzPickleable.__init__rrc|jSrNrrs rgetXzPickleable.getXs vv rNrrU)r r!r"rrr#rrrrs rrceZdZdZddZy) NotPickleablez) A class that is not pickleable. ctd)z9 Raise an exception instead of pickling. zNot serializable.) TypeErrorrs r __reduce__zNotPickleable.__reduce__s+,,rNrr)r r!r"rrr#rrrrs -rrceZdZdZddZy)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"rrr#rrrrs  -rrceZdZdZy)CopyRegisteredLoadedz2 L{CopyRegistered} after unserialization. N)r r!r"rr#rrrrsrrctdfS)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 rreduceCopyRegisteredrs  ##rc$eZdZUdZded<ddZy)A dummy class zCallable[[], None]bmethodcyrNr#rs ramethodz A.amethod  rNr)r r!r"r__annotations__rr#rrrrs  rrc$eZdZUdZded<ddZy)BrracyrNr#rs rrz B.bmethodrrNr)r r!r"rrrr#rrrrs D rrcyrNr#r#rrfunktionrsrc eZdZdZddZddZy) PicklingTestsz$Test pickling of extra object types.ctjt}tj|}|j |tyrN)r*r+r r-r])rrGrs r test_modulezPicklingTests.test_module s. V$ LL  F#rc td}tj|j}tj|}|j |d|j t |t |jy)NrE)rr*r+rr-r]type)rrHrGrs rtest_instanceMethodz!PicklingTests.test_instanceMethod%sYm SXX& LL  a  a$sxx.1rNr)r r!r"rrrr#rrrrs.$ 2rrceZdZdZddZy)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. cd}tj|}|j|tj|j |j dy)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-assertIsInstanceioStringIOr]getvalue)rpickledStringIWithTextloadeds rtest_unpickleBytesIOz,StringIOTransitionTests.test_unpickleBytesIO3sH  - 45 fbkk2 *F3rNr)r r!r"rrr#rrrr-s  4rrc4eZdZUded<ded<ded<ddZy) EvilSourcerorrbrmccj||_||j_||jj_yrN)rrrrs rrzEvilSourceror.__init__Fs# rN)rnrmrr)r r!r"rrr#rrrrAs Irrc(eZdZUded<ddZddZy) NonDictStaterSstatec|jSrNrrs r __getstate__zNonDictState.__getstate__Os zzrc||_yrNr)rrs r __setstate__zNonDictState.__setstate__Rs  rN)rrS)rrSrr)r r!r"rrrr#rrrrLs Jrr_CircularTupleTypec\eZdZd dZd dZd dZd dZd dZd dZd dZ d dZ d d Z d d Z y ) AOTTestsc ddddtdddddtjdzdtf }t j t j |}|j||y) Nr%g@y@Tr5rhelloworld)slicesysmaxsizeEllipsisr unjellyFromSource jellyToSourcer])rrHrtObjs rtest_simpleTypeszAOTTests.test_simpleTypesZsd    !QN   KK!O    %%c&7&7&<= e$rcXt}t}|j|_||_t j t j |jj}|jt j|jt j|yrN) rrrrr rrr] _selfOfMethodr_classOfMethod)rrrim_s rtest_methodSelfIdentityz AOTTests.test_methodSelfIdentityjsu C CII ##C$5$5a$89;;CC **3/993;M;Mc;RSrc0t}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) rrrr assertRaisesrr rr)rrr savedbmethods rtest_methodNotSelfIdentityz#AOTTests.test_methodNotSelfIdentityrsj C CII yy I %   i)>)>@Q@QRS@T U$AI AIs 8B BclGdd}|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. c0eZdZeddZeddZy)2AOTTests.test_unsupportedType..UnknownTypectrNAttributeErrorrs r__dict__z;AOTTests.test_unsupportedType..UnknownType.__dict__ $&&rctrNrrs rrz?AOTTests.test_unsupportedType..UnknownType.__getstate__rrNr)r r!r"propertyrrr#rr UnknownTypers(  ' ' ' 'rrN)rrr r)rrs rtest_unsupportedTypezAOTTests.test_unsupportedTypes( ' ' )S%6%6 Frc tjj}d|d}dddddddd d zttj|tg }t |}|j ||j ||j |tjtj||g}|d |dusJ|dd d |d d k(sJy) Nr)rmethodr%r5rzhe llo "x world!ugoodbye တ world!g?dr) r AOTJellier jellyToAOr rtupleappendrr)rajdltujs rtest_basicIdentityzAOTTests.test_basicIdentitys^^  ' ' , " '  H  NN   !H       " "3#4#4aV#< =!u1~~!uQqzQqV###rct}d|_tjtj|j|jk(sJy)Nz meringue!)rrr rr)rrs rtest_nonDictStatezAOTTests.test_nonDictStates> N$$S%6%6q%9:@@AGGKKKrctjtjt}|j |t y)z L{aot.jellyToSource} and L{aot.unjellyFromSource} honor functions registered in the pickle copy registry. N)r rrrrr)rrs r test_copyRegzAOTTests.test_copyRegs3  " "3#4#4^5E#F G b"67rc0ttg}tj|}tj|}|j|usJ|jj |j usJ|j |j j usJyrN)rr jellyToAOTunjellyFromAOTrrr)rrj1ojs rtest_funkyReferenceszAOTTests.test_funkyReferencessq -+ , ^^A     #ttrzzttvv~~tt24466!!!rcg}|df}|j|tj|}tj|}|j |dt |j |dd||j|dddy)zS L{aot.jellyToAOT} can persist circular references through tuples. irr%N)rr rrrrassertIsr])rrrrrs rtest_circularTuplezAOTTests.test_circularTuples}!# I  ^^A     # beU+ beAh# Aq4(rc||jtjddgiitjdy)z: The generated serialization is indented. rrz| app={ 'hello':{ 'world':[], }, }N)r]r rtextwrapdedentrs r testIndentifyzAOTTests.testIndentifys:    w" 6 7 OO  rNr) r r!r"rrrrrr r rrrr#rrrrYs7% T%"G$$6L 8" ) rrc8eZdZdZddZddZddZddZddZy) CrefUtilTestsz Tests for L{crefutil}. crtji}|jt|jddy)zO L{crefutil._DictKeyAndValue} only support keys C{0} and C{1}. r5rN)r _DictKeyAndValuer RuntimeError __setitem__rrs rtest_dictUnknownKeyz!CrefUtilTests.test_dictUnknownKeys,  % %b ) , q!r<st# --43"+n&8n&b ((  f..  ,  35L " 8" J&"" *X * - - - - $~34      2H 2 4h4(% 4c 9:;H xH V1 H1 h>= 9 r