mò Tã¸Ec@sÿdZdkZdkZdkZdklZdklZlZdk l Z dk l Z dk lZeeeƒfZeƒd„Zdfd „ƒYZd fd „ƒYZd fd „ƒYZhdd„>> from ZODB.tests.util import P >>> class DummyJar: ... def new_oid(self): ... return 42 ... def db(self): ... return self ... databases = {} >>> jar = DummyJar() >>> class O: ... _p_jar = jar >>> writer = ObjectWriter(O) Normally, object references include the oid and a cached named reference to the class. Having the class information available allows fast creation of the ghost, avoiding requiring an additional database lookup. >>> bob = P('bob') >>> oid, cls = writer.persistent_id(bob) >>> oid 42 >>> cls is P True If a persistent object does not already have an oid and jar, these will be assigned by persistent_id(): >>> bob._p_oid 42 >>> bob._p_jar is jar True If the object already has a persistent id, the id is not changed: >>> bob._p_oid = 24 >>> oid, cls = writer.persistent_id(bob) >>> oid 24 >>> cls is P True If the jar doesn't match that of the writer, an error is raised: >>> bob._p_jar = DummyJar() >>> writer.persistent_id(bob) Traceback (most recent call last): ... InvalidObjectReference: Attempt to store an object from a foreign database connection Constructor arguments used by __new__(), as returned by __getnewargs__(), can affect memory allocation, but may also change over the life of the object. This makes it useless to cache even the object's class. >>> class PNewArgs(P): ... def __getnewargs__(self): ... return () >>> sam = PNewArgs('sam') >>> writer.persistent_id(sam) 42 >>> sam._p_oid 42 >>> sam._p_jar is jar True Check that simple objects don't get accused of persistence: >>> writer.persistent_id(42) >>> writer.persistent_id(object()) Check that a classic class doesn't get identified improperly: >>> class ClassicClara: ... pass >>> clara = ClassicClara() >>> writer.persistent_id(clara) t__get__tws=Attempt to store an object from a foreign database connectionsjAttempt to store a reference to an object from a separate connection to the same database or multidatabases\A new object is reachable from multiple databases. Won't try to guess which one was correct!t__getnewargs__tntmN(t isinstanceRt PersistentttypetWeakRefRt_p_oidtoidtAttributeErrortstrthasattrt WeakRefMarkerR RRRRRt database_nametdbtotherdbt databasestgettInvalidObjectReferencetget_connectiont_implicitlyAddingtklass(R RR"R/R)R'((RR¸s\3%              "   cCsÂt|ƒ}t|ddƒ}tt|ddƒtƒoL|ioB|i|i f}|djo|df}q¬||ƒf}n'|djo |}n||ƒf}|i ||i ƒƒS(NRR!i(RRR/RRtnewargsRt _oidtypest __module__t__name__tmetaR t_dumpt __getstate__(R RR4R/R0((Rt serialize}s &   cCsW|iidƒ|iiƒ|ii|ƒ|ii|ƒ|iiƒ|ii ƒS(Ni( R R tseekRt clear_memotdumpt classmetatstatettruncatetgetvalue(R R;R<((RR5™s   cCs t|iƒS(N(tNewObjectIteratorR R(R ((Rt__iter__¤s( R3R2t__doc__RRRRR7R5R@(((RR£s  Å  R?cBs#tZd„Zd„Zd„ZRS(NcCs ||_dS(N(tstackR R(R RB((RR¬scCs|S(N(R (R ((RR@¯scCs+|io|iiƒ}|Snt‚dS(N(R Rtpopteltt StopIteration(R RD((Rtnext²s (R3R2RR@RF(((RR?§s  t ObjectReadercBs³tZdddd„Zd„Zd„ZhZd„Zd„Zd„Z e edascCsðg}titi|ƒƒ}||_|iƒ|iƒ|djo g}nx—|D]}t |t ƒo|d}nTt |tƒo |}n:y|\}}Wntj o qYnXt||Œ}|o|i|ƒqYqYW|S(s©Return a list of object ids found in a pickle A list may be passed in, in which case, information is appended to it. Weak references are not included. iN(trefsR RTRR tptuRWtnoloadtoidsRRYRRZR"R$R]R^R_t oid_loadersR(RR‚R^RYR~R"R]R€((Rt referencesfds,      cCsdS(N(R(R"((RR}scCság}titi|ƒƒ}||_|iƒ|iƒg}x™|D]‘}t |t ƒo |}nZt |tƒo|df}n:y|\}}Wntj o qHnXt||Œ}|o|i|ƒqHqHW|S(sßReturn oid and class information for references in a pickle The result of a list of oid and class information tuples. If the reference doesn't contain class information, then the klass information is None. N(R~R RTRR ta_pickleR€RWRtresultRYRRZtdataR$RR]R^R_toid_klass_loadersR(R…RYR~R^R]R€R†R‡((Rtget_refss*    (RAR RRvt persistentRtpersistent.wrefR&R tZODBRct ZODB.brokenRbtZODB.POSExceptionR,R$RRR1tobjectRRR?RGRƒR„RˆR‰(RR1R&RbR„R,R R‰RRˆRRGRvRcR RRƒR?((Rt?†s$        ÿ§ (