Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/twisted/test/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyc


=Nc@sdZddlZyddlZWnek
r;eZnXddlmZmZddlm	Z	m
Z
ddlmZddl
mZdeejfdYZd	fd
YZdZdfd
YZdfdYZdefdYZdefdYZdfdYZdejfdYZdejejfdYZdejejfdYZdejfdYZdS(s/
Test cases for L{jelly} object serialization.
iN(tjellytpb(tsett	frozenset(tunittest(tStringTransporttTestNodecBs eZdZdZddZRS(sD
    An object to test jellyfying of new style class instances.
    icCsH|r)|jd|_|jj|n	d|_||_g|_dS(Ni(tidtchildrentappendtparent(tselfR
((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyt__init__s		N(t__name__t
__module__t__doc__t	classAttrtNoneR(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyRstAcBseZdZdZRS(s
    Dummy class.
    cCsdS(s;
        Method tp be used in serialization tests.
        N((R((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pytamethod+s(R
RRR(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyR&scCsdS(s:
    A dummy function to test function serialization.
    N((R((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pytafunc2stBcBseZdZdZRS(s
    Dummy class.
    cCsdS(s;
        Method to be used in serialization tests.
        N((R((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pytbmethod>s(R
RRR(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyR9stCcBseZdZdZRS(s
    Dummy class.
    cCsdS(s;
        Method to be used in serialization tests.
        N((R((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pytcmethodJs(R
RRR(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyREstDcBseZdZRS(s 
    Dummy new-style class.
    (R
RR(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyRQstEcBs5eZdZdZdddZdZdZRS(s+
    Dummy new-style class with slots.
    txtycCs||_||_dS(N(RR(RRR((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyR_s	cCsi|jd6|jd6S(NRR(RR(R((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyt__getstate__dscCs|d|_|d|_dS(NRR(RR(Rtstate((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyt__setstate__hs
(RRN(R
RRt	__slots__RRRR(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyRXs
	tSimpleJellyTestcBseZdZdZRS(cCs||_||_dS(N(RR(RRR((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyRos	cCs|j|jkS(N(t__dict__(Rtother((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pytisTheSameAsss(R
RRR$(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyR!ns	t
JellyTestCasecBseZdZdZdZdZdZdZdZdZ	dZ
d	Zd
Zddd
dgdddgdddgdddggZ
dZdZdZed,krdZee_ee_ee_ndZdZdZdZdZdZdZdZdZd Zd!Zd"Z d#Z!d$Z"d%Z#d&Z$d'Z%d(Z&d)Z'd*Z(d+Z)RS(-s
    Testcases for L{jelly} module serialization.

    @cvar decimalData: serialized version of decimal data, to be used in tests.
    @type decimalData: C{list}
    cCsetj|}tj}|jtj|||jj||jtjtj||dS(s
        Helper test method to test security options for a type.

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

        @param atom: atom identifier for the type.
        @type atom: C{str}
        N(RtSecurityOptionstallowBasicTypestunjellytallowedTypestpoptassertRaisest
InsecureJelly(Rt	inputListtatomtcttaster((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyt
_testSecuritys

cCsbt}t}|j|_||_tjtj|jj}|j|j|jj	dS(N(
RRRtaRR(tassertEqualtim_classtim_selft	__class__(RR2tbtim_((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyttest_methodSelfIdentitys			cCsst}t}t}|j|_||_tj}t`z#|jttj	tj|Wd|t_XdS(s
        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(
RRRRRR2R+t	TypeErrorRR((RR2R7R/tsavecmethod((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyttest_methodsNotSelfIdentitys					#cCsut}d|_t}||_||_tj|}tj|}|j|t|j|j|jdS(Ni(RRtn2tn3RR(tassertIsInstancetassertIdentical(RtnR=R/tm((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyt
test_newStyles					cCsWt}d|_tj|}tj|}|j|t|j|jddS(s
        A class defined with I{slots} can be jellied and unjellied with the
        values for its attributes preserved.
        iN(RRRR(R?R3(RRAR/RB((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyttest_newStyleWithSlotss		cCs5tg}tjtj|}|j||dS(sn
        Test that an old style class type can be jellied and unjellied
        to the original type.
        N(RRR(R3(Rtttr((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyttest_typeOldStyles	cCs5tg}tjtj|}|j||dS(sm
        Test that a new style class type can be jellied and unjellied
        to the original type.
        N(RRR(R3(RRERF((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyttest_typeNewStyles	cCs5tg}tjtj|}|j||dS(se
        Test that a builtin type can be jellied and unjellied to the original
        type.
        N(tstrRR(R3(RRERF((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyttest_typeBuiltins	cCsptjj}tjj|}||g}tj|}tj|}|j|||j||dS(N(tdatetimetnowRR(R3tassertNotIdentical(RtdtntdtdtinputR/toutput((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyt
test_dateTimescCsxtjdtjdtjdtjdg}tj|}tj|}|j|||j||dS(s
        Jellying L{decimal.Decimal} instances and then unjellying the result
        should produce objects which represent the values of the original
        inputs.
        s9.95ii@s-78.901N(tdecimaltDecimalRR(R3RM(RR-R/RQ((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyttest_decimalstlistRSiiii@iicCs\tjdtjdtjdtjdg}tj|j}|j||dS(s
        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 C{self.decimalData} contains valid jellied
        data.  This is important since L{test_decimalMissing} re-uses
        C{self.decimalData} and is expected to be unable to produce
        L{decimal.Decimal} instances even though the s-expression correctly
        represents a list of them.
        s9.95ii@s-78.901N(RSRTRR(tdecimalDataR3(RtexpectedRQ((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyttest_decimalUnjellyscCs|jtddtj|j}|jt|dx+tdD]}|j||tj	qHW|j|dj
d|j|dj
d|j|dj
d|j|d	j
d
dS(s
        If decimal is unavailable on the unjelly side, L{jelly.unjelly} should
        gracefully return L{jelly.Unpersistable} objects.
        RSiis!Could not unpersist decimal: 9.95isCould not unpersist decimal: 0is#Could not unpersist decimal: 123456is$Could not unpersist decimal: -78.901N(tpatchRRR(RWR3tlentrangeR?t
Unpersistabletreason(RRQti((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyttest_decimalMissingscCs&tjdg}|j|ddS(s
        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.
        s9.95RSN(RSRTR1(RR-((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyttest_decimalSecurity,ssdecimal not availablecCsTtdddgg}tjtj|}|j|||j||dS(s
        Jellying C{set} instances and then unjellying the result
        should produce objects which represent the values of the original
        inputs.
        iiiN(RRR(R3RM(RR-RQ((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyttest_set<scCsTtdddgg}tjtj|}|j|||j||dS(s
        Jellying C{frozenset} instances and then unjellying the result
        should produce objects which represent the values of the original
        inputs.
        iiiN(RRR(R3RM(RR-RQ((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyttest_frozensetHscCs,tdddgg}|j|ddS(s
        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.
        iiiRN(RR1(RR-((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyttest_setSecurityTscCs,tdddgg}|j|ddS(s
        By default, C{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.
        iiiRN(RR1(RR-((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyttest_frozensetSecurity^scCstjjdddgg}tj|}|j|tjtdddggtj|}|jt|dt|dttjjkr|j|dtjjn|j|dtdS(s
        Test jellying C{sets.Set}: it should serialize to the same thing as
        C{set} jelly, and be unjellied as C{set} if available.
        iiiiN(Rt_setstSetR3RR(RVR?(RR-t
inputJellyRQ((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyttest_oldSetshs+$cCstjjdddgg}tj|}|j|tjtdddggtj|}|jt|dt|dttjjkr|j|dtjjn|j|dtdS(s
        Test jellying C{sets.ImmutableSet}: it should serialize to the same
        thing as C{frozenset} jelly, and be unjellied as C{frozenset} if
        available.
        iiiiN(RRftImmutableSetR3RR(RVR?(RR-RhRQ((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyttest_oldImmutableSetsys+$cCso|jtddjtddtdd}tj|}tj|}|j|j|dS(s%
        Simplest test case.
        R2R7iiN(t
failUnlessR!R$RR((RR2tcerealR7((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyttest_simplescCsg}|}|j||j||j|d|d|j|dd|tj|}tj|}|j|d|d|j|dd|dS(sJ
        Test to make sure that objects retain identity properly.
        iiN(R	R@RR((RRRtstz((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyt
test_identitys

cCsTtd}tjtj|}|j|||jt|t|dS(Ntblah(tunicodeRR(R3ttype(RRR((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyttest_unicodescCsg}i|d6|f}|j|tj|}tj|}|j|dd|d|j|ddd|dS(NRVii(R	RR(R@(Rtrereft
toplevelTupleRoRp((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyttest_stressReferencess
cCs]g}|f}|j|ftj|}tj|}|j|ddd|dS(Ni(R	RR(R@(RR2RERoRp((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyttest_moreReferencess	cCs;tj}tji}|jtjtj||dS(s@
        Test for type-level security of serialization.
        N(RR&R+R,R((RR0tdct((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyttest_typeSecurityscCs2tjt}tjt}|jt|dS(N(RRR(R@(Rtjtuj((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyttest_newStyleClassessc
Cst}tjtj|tjtj|jtdddgtdtdddddttidd6tjg}x0|D](}|j|tjtj|qWdS(	sA
        Test for all types currently supported in jelly
        iiittestgL4@R2N(iii(	RRR(RRtboolRRR3(RR2titemsR_((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyttest_lotsaTypess	("
cCsdddYat}t|}t|}t||f}i||6||6||6|d6}tjtj|d}|j|jdj|jdjdS(Nt
TupleStatecBs,eZdZdZdZdZRS(cSs
||_dS(N(R#(RR#((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyRscSs
|jfS(N(R#(R((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyRscSs|d|_dS(Ni(R#(RR((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyRscSs
t|jS(N(thashR#(R((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyt__hash__s(R
RRRRR(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyRs			tt3ii((RRRR(R@R#(RR2tt1tt2Rtdtt3prime((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyt
test_setStates		"cCstj}|jttt}t}t}||_||_||_||_tj||}tj	||}|j
|jtjtj|}|jtj
tj	|||j|j|jdtjt|}tj	||}|j|td|dS(sA
        Test for class-level security of serialization.
        sIdentity mismatchsA came back: %sN(RR&tallowInstancesOfRRRR7R/RR(R?R]R+R,R@(RR0R2R7R/tfriendlyRtmean((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyttest_classSecuritys$							cCsdtjfdY}tj|tj|}d|_tjtj|}|j|jd|j|tjdS(sr
        Test that if Unjellyable is used to deserialize a jellied object,
        state comes out right.
        tJellyableTestClasscBseZRS((R
R(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyRstvalueN(Rt	JellyabletsetUnjellyableForClasstUnjellyablet	attributeR(R3R?(RRRPRQ((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyttest_unjellyables		c	Csidg}|d}|d}tdd}tdd}tdd}||_||_||_tj|d	|}tj|d
|}|j|j|jj|j|dd|j|j|jd
dS(NicSs2|dd|d<||d|d<t|dS(Nii(RI(tobjtjeltperst((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pytpersistentStorescSst|}|d|S(Ni(tint(tpidstrtunjRtpid((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pytpersistentLoad$siiiiiRRispersistentStore was not called.s$Persistent storage identity failure.(R!R7R/RR(R@Rl(	RRRRR2R7R/RR((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyttest_persistentStorages			cCs_t}t|}t|}t|}tj|}tj|}|j||dS(N(RRR(t_check_newstyle(RRAtn1tn11R=RRB((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyttest_newStyleClassesAttributes8s	cCs|j|j|j|j|jd|j|jd|jt|jt|jx3t|j|jD]\}}|j||qtWdS(Ni(R3RRR[RtzipR(RR2R7RR((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyRDs""cCstj}tj}|jttj|d|}tj}|jttj|d|}|j|j|j	dS(s
        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}.
        tinvokerN(
Rt
ReferenceabletBrokertmakeConnectionRRR(tassertIntluidtlocalObjects(RtreftjellyBrokerR|t
unjellyBrokerR}((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyttest_referenceableMsN(*R
RRR1R9R<RCRDRGRHRJRRRURWRYR`RaRSRt
skipReasontskipRbRcRdReRiRkRnRqRuRxRyR{R~RRRRRRRR(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyR%xsT						
	
	
	
	
										
	
						
						
							tClassAcBseZdZRS(cCst||_dS(N(tClassBR(R((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyRbs(R
RR(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyRasRcBseZdZRS(cCs
||_dS(N(R(RR((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyRhs(R
RR(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyRgstCircularReferenceTestCasecBs2eZdZdZdZdZdZRS(sN
    Tests for circular references handling in the jelly/unjelly process.
    cCsXtjtttjtttjtjt}|j|jj|ddS(Ns,Identity not preserved in circular reference(RRRRR(R@R(RR2((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyttest_simpleCirclers
cCsdddY}|}d|_t}tjtttjtttj|d|}tj|}|j|jj|ddS(NtDummyInvokerClasscBseZRS((R
R(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyR{sRs,Identity not preserved in circular reference((	RtserializingPerspectiveRRRRR(tfailUnlessIdenticalR(RRtdummyInvokerta0R|ta1((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyttest_circleWithInvokerzs			cCspt}t|d}|j|tjtj|}|j|jt|jt	|j|gdS(s
        Check that a C{set} can contain a circular reference and be serialized
        and unserialized without losing the reference.
        N(
RR!RtaddRR(R?RR3RV(RRoR2tres((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyRbs	
cCsrtdd}t|g}||_tjtj|}|j|jt|jt|j|gdS(s
        Check that a C{frozenset} can contain a circular reference and be
        serializeserialized without losing the reference.
        N(	R!RRRRR(R?R3RV(RR2RoR((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyRcs	(R
RRRRRbRc(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyRms
			
( RRKRStImportErrorRttwisted.spreadRRttwisted.python.compatRRt
twisted.trialRttwisted.test.proto_helpersRtobjectRRRRRRRRR!tTestCaseR%tCopyablet
RemoteCopyRRR(((s;/usr/lib/python2.7/dist-packages/twisted/test/test_jelly.pyt<module>s,