mò Tã¸Ec@s†dZdkZdkZdklZdklZlZdkl Z dk l Z dk l Z dklZde fd „ƒYZdS( s¾Demo ZODB storage The Demo storage serves two purposes: - Provide an example implementation of a full storage without distracting storage details, - Provide a volatile storage that is useful for giving demonstrations. The demo storage can have a "base" storage that is used in a read-only fashion. The base storage must not contain version data. There are three main data structures: _data -- Transaction logging information necessary for undo This is a mapping from transaction id to transaction, where a transaction is simply a 5-tuple: packed, user, description, extension_data, records where extension_data is a dictionary or None and records are the actual records in chronological order. Packed is a flag indicating whethe the transaction has been packed or not _index -- A mapping from oid to record _vindex -- A mapping from version name to version data where version data is a mapping from oid to record A record is a tuple: oid, pre, vdata, p, tid where: oid -- object id pre -- The previous record for this object (or None) vdata -- version data None if not a version, ortherwise: version, non-version-record p -- the pickle data or None tid -- the transaction id that wrote the record The pickle data will be None for a record for an object created in an aborted version. It is instructive to watch what happens to the internal data structures as changes are made. For example, in Zope, you can create an external method:: import Zope2 def info(RESPONSE): RESPONSE['Content-type']= 'text/plain' return Zope2.DB._storage._splat() and call it to monitor the storage. N(s POSException(sz64soid_repr(s BaseStorage(s TimeStamp(sloads(sOOBTreet DemoStoragecBsàtZdddd„Zd„Zd„Zd„Zd„Zd„Zd„Z d „Z d „Z d „Z d „Z d „Zd„Zd„Zd„Zd„Zdd„Zd„Zdd„Zdd„Zd„Zd„ZRS(Ns Demo StoragecCs“ti|||ƒtiƒ|_h|_h|_||_ d|_ ||_ d|_|iƒ|dj o |iƒotidƒ‚ndS(Nis"Demo base storage has version data(t BaseStoraget__init__tselftnametbasetOOBTreet_datat_indext_vindext_baset_sizetquotat_quotatNonet_ltidt _clear_temptversionst POSExceptiont StorageError(RRRR ((t//data/zmath/zope/lib/python/ZODB/DemoStorage.pyR]s       cCs+|idj o|ii||ƒndS(N(RR Rt registerDBtdbtlimit(RRR((RRqscCs2|idjoti|ƒSn|iiƒSdS(N(RR RRtnew_oid(R((RRyscCs.|i}|o t|ƒpdt|iƒS(Ni(RR RtlenR(RR((Rt__len__s c CsPd}xñ|iiƒD]à\} \}}}}} |dddddt |ƒdt |ƒdt |ƒd}x~| D]v\}}}}} |ddddd|odt |ƒpd}|o$|ddt |dƒd}q|q|WqW|dt |iƒ}x/|iiƒD]} |ddt | ƒ}q!W||_|S(Nidiii iii (tsRRtitemsttidtptutdtettRtoidtpretvdataRR tvaluestvR ( RR$R%R!R R#RRRR"R'R((RtgetSizeƒsD6, c Cs:||ij oti||ƒ‚n|ptidƒ‚n|iƒzÞ|ii |dƒ} | pdSng}x | i ƒD]’} | \}}\}} }} |i|ƒ| o;| \}}}}} |ii|| d||igƒq„|ii|| dd|igƒq„W|i|fSWd|iƒXdS(NsInvalid version(t transactionRt _transactionRtStorageTransactionErrortsrctVersionCommitErrort _lock_acquireR tgetRR'toidsR&trR#R$tversiontnvRRtappendR%t_tindext_tidt _lock_release( RR,R)R$R2R%R#R0RR1R'RR3((Rt abortVersion“s(   &&cCsc||ij oti||ƒ‚n|ptidƒ‚n||jotidt|ƒƒ‚n|i ƒzÝ|i i |ƒ} | djodSn|i}|i}g} xŠ| iƒD]|} | \}}}}} |dj pt‚| i|ƒ|o||df} nd} |i|| | ||igƒqÃW|i| fSWd|iƒXdS(NsInvalid source versions Can't commit to same version: %si(R)RR*RR+R,R-tdesttreprR.R R/R'RR6t newserialR5ttindexR0R&R1R#R$R%RRtAssertionErrorR4t new_vdataR7(RR,R9R)R$R%R#R;RR1R>R'RR0R<((Rt commitVersion®s4       #c Cs |iƒzñy |i|\}}}}}Wn@tj o4|i o|i i |dƒSnt|ƒ‚nXd}|oS|\} } | |jo0| o| \}}}}}qÆt|ƒ‚n| }n|djot|ƒ‚n|||fSWd|iƒXdS(Nt(RR.RR#R$R%RRtKeyErrorR tloadtvertoversionR3R2tskiptidRR7( RR#R2R$R%RCRERRRDR3((RtloadExÐs(       cCs|i||ƒd S(Ni(RRFR#R2(RR#R2((RRBìscCse|iƒzIy7|i|\}}}}}|o |dSndSWn dSnXWd|iƒXdS(NiR@( RR.RR#R$R%RRR7(RR#R$R%RR((RtmodifiedInVersionïs   cCs||ij oti||ƒ‚n|iƒzÙ|ii|dƒ}|djo\|i oNy|i i |dƒ\} } Wntj oq­X|dd| | f}q±nd} |o|\}}}} } |o2|d|joti|ƒ‚n|d} n|} || jo(tid|d| |fd|ƒ‚qKn|||o || fpd||ig} |ii| ƒ|i} | d|odt|ƒpd } |o| d t|ƒ} n|idj o#| |ijoti d ƒ‚nWd|i!ƒX|iS( NR@iiR#tserialstdataiHiii s™Quota Exceeded
The maximum quota for this demonstration storage has been exceeded.
Have a nice day.("R)RR*RR+R.RR/R#RtoldR RBRRRAR3R$R%R2tVersionLockErrortserialt ConflictErrorRIR6R1R5R4t_tsizeRRR RR7(RR#RLRIR2R)R$RJR%RRRR1R3((Rtstoreùs@    ,, &  cCsdS(Ni((R((RtsupportsVersions*scCsg|_|id|_dS(Ni (RR5R RN(R((RR-s cCs|iS(N(RR(R((RtlastTransaction1scCs2|idt|ƒt|ƒt|ƒ|_dS(Nix(RR RRR R!RN(RRRR R!((Rt_begin4scCs3|i|_d|||t|iƒf|i |