mò &U²Ic@sdZdkZydklZWn&ej odfd„ƒYZnXdkZeideiddd„Z defd„ƒYZ d fd „ƒYZ dS( sNManage shelves of pickled objects using bsddb database files for the storage. N(s DictMixint DictMixincBstZRS(N(t__name__t __module__(((t+/data/zmath/lib/python2.4/bsddb/dbshelve.pyR%si°cCsÞt|ƒtdƒjoœ|}|djo ti}qµ|djo d}qµ|djo ti}qµ|djo ti}qµ|djotitiB}qµtid‚nt|ƒ}|i |||||ƒ|S( s( A simple factory function for compatibility with the standard shleve.py module. It can be used like this, where key is a string and data is a pickleable object: from bsddb import dbshelve db = dbshelve.open(filename) db[key] = data db.close() ttrtrwitwtctnsJflags should be one of 'r', 'w', 'c' or 'n' or use the bsddb.db.DB_* flagsN(ttypetflagstsflagtdbt DB_RDONLYt DB_CREATEt DB_TRUNCATEtDBErrortDBShelftdbenvtdtopentfilenametdbnametfiletypetmode(RR RRRRRR ((RR+s"           RcBsÚtZdZed„Zd„Zd„Zd„Zd„Zd„Z d„Z ed„Z ed „Z ed „Z ed „Zed „Zd d„Zd„Zed d„Zed d„Zed d„Zd d„ZRS(sŽA shelf to hold pickled objects, built upon a bsddb DB object. It automatically pickles/unpickles data objects going to/from the DB. cCsti|ƒ|_d|_dS(Ni(R tDBRtselftbinary(RR((Rt__init__RscCs|iƒdS(N(Rtclose(R((Rt__del__WscCst|i|ƒS(sTMany methods we can just pass through to the DB object. (See below) N(tgetattrRR tname(RR!((Rt __getattr__[scCs t|iƒS(N(tlenRR (R((Rt__len__escCs|i|}ti|ƒS(N(RR tkeytdatatcPickletloads(RR%R&((Rt __getitem__is cCs&ti||iƒ}||i|R<R=R&((Rt_shelf_callback s(tcallbackR?RR t associatet secondaryDBR (RRBR@R R?((RRAŸs cOsPt|ii||ƒ}yti|ƒSWn t ti fj o |SnXdS(N( tapplyRR tgettargstkwR&R'R(t TypeErrortUnpicklingError(RRERFR&((RRD§s cCs=ti||iƒ}|ii||||ƒ}ti |ƒS(N( R'R*R+RRR&R RDR%R.R R((RR%R+R.R R&((Rtget_both³scCs+t|ii||ƒƒ}|i|_|S(N(t DBShelfCursorRR tcursorR.R RR(RR.R R((RRK¹s cCs.ti||iƒ}|ii||||ƒS(N( R'R*R+RRR&R tputR%R.R (RR%R+R.R R&((RRL¿scCs t‚dS(N(tNotImplementedError(Rt cursorListR ((RtjoinÄs(RRt__doc__R/RRR"R$R)R,R-R0R1R6R;R5RARDRIRKRLRO(((RRNs&            RJcBstZdZd„Zd„Zd„Zdd„Zdd„Zd„Zd„Z d „Z d „Z dd „Z dd „Z dd „Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„ZeZd„ZRS(s cCs ||_dS(N(RKRtdbc(RRK((RRÕscCs|iƒdS(N(RR(R((RRØscCst|i|ƒS(sHSome methods we can just pass through to the cursor object. (See below)N(R RRQR!(RR!((RR"ÜsicCst|ii|ƒƒS(N(RJRRQtdupR (RR ((RRRãscCs+ti||iƒ}|ii|||ƒS(N( R'R*R+RRR&RQRLR%R (RR%R+R R&((RRLçscGs0t|ƒ}t|d|ƒ}t||ƒdS(Nsget_%d(R#REtcountR RtmethodRC(RRERSRT((RRDìs cCs|ii|ƒ}|i|ƒS(N(RRQRDR trect_extract(RR RU((Rtget_1ñscCs"|ii||ƒ}|i|ƒS(N(RRQRDR%R RURV(RR%R RU((Rtget_2õscCs7ti||iƒ}|ii||ƒ}|i |ƒS(N( R'R*R+RRR&RQRDR%R RURV(RR%R+R RUR&((Rtget_3ùscCs|i|tiBƒS(N(RRWR R t DB_CURRENT(RR ((RtcurrentÿscCs|i|tiBƒS(N(RRWR R tDB_FIRST(RR ((RtfirstscCs|i|tiBƒS(N(RRWR R tDB_LAST(RR ((RtlastscCs|i|tiBƒS(N(RRWR R tDB_NEXT(RR ((RtnextscCs|i|tiBƒS(N(RRWR R tDB_PREV(RR ((RtprevscCs|i|tiBƒS(N(RRWR R t DB_CONSUME(RR ((RtconsumescCs|i|tiBƒS(N(RRWR R t DB_NEXT_DUP(RR ((Rtnext_dupscCs|i|tiBƒS(N(RRWR R t DB_NEXT_NODUP(RR ((Rt next_nodupscCs|i|tiBƒS(N(RRWR R t DB_PREV_NODUP(RR ((Rt prev_nodupscCs7ti||iƒ}|ii||ƒ}|i |ƒS(N( R'R*R+RRR&RQRIR%R RURV(RR%R+R RUR&((RRI scCs"|ii||ƒ}|i|ƒS(N(RRQtsetR%R RURV(RR%R RU((RRlscCs"|ii||ƒ}|i|ƒS(N(RRQt set_rangeR%R RURV(RR%R RU((RRmscCs"|ii||ƒ}|i|ƒS(N(RRQt set_recnotrecnoR RURV(RRoR RU((RRnscCs8|djodSn |\}}|ti|ƒfSdS(N(RUR/R%R&R'R((RRUR%R&((RRVs  (RRRPRRR"RRRLRDRWRXRYR[R]R_RaRcReRgRiRkRIRlRmRntset_bothRV(((RRJÒs2                       ( RPR'tUserDictRt ImportErrorR RtDB_HASHR/RRRJ(R'RR RJRR((Rt?s  #„