ó }®¸Qc@s‹dZddlZejddkZer6ddUn ddlZejddkrdddlZnzejdkr‚ddlZn\ddlZejƒZej ƒz)ej dd d d e ƒddlZWdej ƒX[ej Z d „Zejdkrdd lmZnddlZejZejdejddd„Zdejfd„ƒYZdefd„ƒYZddd„ƒYZdS(sNManage shelves of pickled objects using bsddb database files for the storage. iÿÿÿÿNiisfrom . import dbiitignoretmessages1the cPickle module has been removed in Python 3.0tcategorycCstj|d|ƒS(Ntprotocol(tcPickletdumps(tobjectR((s$/sys/lib/python2.7/bsddb/dbshelve.pyt_dumpsEs(t DictMixini°cCsÒt|ƒtdƒkr©|}|dkr6tj}q©|dkrKd}q©|dkrctj}q©|dkr{tj}q©|dkrštjtjB}q©tjd‚nt|ƒ}|j|||||ƒ|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_* flags(ttypetdbt DB_RDONLYt DB_CREATEt DB_TRUNCATEtDBErrortDBShelftopen(tfilenametflagstmodetfiletypetdbenvtdbnametsflagtd((s$/sys/lib/python2.7/bsddb/dbshelve.pyRQs           t DBShelveErrorcBseZRS((t__name__t __module__(((s$/sys/lib/python2.7/bsddb/dbshelve.pyRtsRcBseZdZdd„Zd„Zd„Zd„Zd„Zd„Z d„Z dd„Z e j dkrud „Znd „Zd „Zd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd„Zddd„Zddd„Zddd„Zdd„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. cCs:tj|ƒ|_t|_tr-t|_n d|_dS(Ni(RtDBtTruet_closedtHIGHEST_PROTOCOLR(tselfR((s$/sys/lib/python2.7/bsddb/dbshelve.pyt__init__{s   cCs|jƒdS(N(tclose(R&((s$/sys/lib/python2.7/bsddb/dbshelve.pyt__del__„scCst|j|ƒS(sTMany methods we can just pass through to the DB object. (See below) (tgetattrR(R&tname((s$/sys/lib/python2.7/bsddb/dbshelve.pyt __getattr__ˆscCs t|jƒS(N(tlenR(R&((s$/sys/lib/python2.7/bsddb/dbshelve.pyt__len__’scCs|j|}tj|ƒS(N(RRtloads(R&tkeytdata((s$/sys/lib/python2.7/bsddb/dbshelve.pyt __getitem__–s cCs#t||jƒ}||j|(R$tidtreprtdictt iteritems(R&((s$/sys/lib/python2.7/bsddb/dbshelve.pyt__repr__Às cCsm|dk r!|jj|ƒ}n|jjƒ}g}x0|D](\}}|j|tj|ƒfƒq=W|S(N(R6RtitemstappendRR/(R&R8RCtnewitemsR9tv((s$/sys/lib/python2.7/bsddb/dbshelve.pyRCÇs  cCs@|dk r!|jj|ƒ}n|jjƒ}ttj|ƒS(N(R6RtvaluestmapRR/(R&R8RG((s$/sys/lib/python2.7/bsddb/dbshelve.pyRGÒs cCs%t||jƒ}|jj||ƒS(N(RRRRD(R&R3R8R1((s$/sys/lib/python2.7/bsddb/dbshelve.pyt__appendÝscCs5|jƒtjkr(|j|d|ƒStd‚dS(NR8sOappend() only supported when dbshelve opened with filetype=dbshelve.db.DB_RECNO(tget_typeRtDB_RECNOt_DBShelf__appendR(R&R3R8((s$/sys/lib/python2.7/bsddb/dbshelve.pyRDásicCs"|d„}|jj|||ƒS(NcSsYtjddks"t|tƒr4tj|ƒ}ntjt|dƒƒ}|||ƒS(Niis iso8859-1(tsyst version_infot isinstancetbytesRR/(tpriKeytpriDatat realCallbackR1((s$/sys/lib/python2.7/bsddb/dbshelve.pyt_shelf_callbackès"(Rt associate(R&t secondaryDBtcallbackRRT((s$/sys/lib/python2.7/bsddb/dbshelve.pyRUçs cOsK|jj||Ž}ytj|ƒSWntttjfk rF|SXdS(N(RtgetRR/tEOFErrort TypeErrortUnpicklingError(R&R<tkwR1((s$/sys/lib/python2.7/bsddb/dbshelve.pyRXôs cCs:t||jƒ}|jj||||ƒ}tj|ƒS(N(RRRRXRR/(R&R0R3R8RR1((s$/sys/lib/python2.7/bsddb/dbshelve.pytget_bothscCs+t|jj||ƒƒ}|j|_|S(N(t DBShelfCursorRtcursorR(R&R8RR ((s$/sys/lib/python2.7/bsddb/dbshelve.pyR_s cCs+t||jƒ}|jj||||ƒS(N(RRRtput(R&R0R3R8RR1((s$/sys/lib/python2.7/bsddb/dbshelve.pyR` scCs t‚dS(N(tNotImplementedError(R&t cursorListR((s$/sys/lib/python2.7/bsddb/dbshelve.pytjoinsN(ii(R R!t__doc__R6R'R)R,R.R2R4R5R7RMRNR:RR(RBRCRGRLRDRURXR]R_R`Rc(((s$/sys/lib/python2.7/bsddb/dbshelve.pyRws0            R^cBseZdZd„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(tdbc(R&R_((s$/sys/lib/python2.7/bsddb/dbshelve.pyR'"scCs|jƒdS(N(R((R&((s$/sys/lib/python2.7/bsddb/dbshelve.pyR)%scCst|j|ƒS(sHSome methods we can just pass through to the cursor object. (See below)(R*Re(R&R+((s$/sys/lib/python2.7/bsddb/dbshelve.pyR,)sicCs(t|jj|ƒƒ}|j|_|S(N(R^RetdupR(R&RR ((s$/sys/lib/python2.7/bsddb/dbshelve.pyRf0s cCs(t||jƒ}|jj|||ƒS(N(RRReR`(R&R0R3RR1((s$/sys/lib/python2.7/bsddb/dbshelve.pyR`6scGs-t|ƒ}t|d|ƒ}||ŒdS(Nsget_%d(R-R*(R&R<tcounttmethod((s$/sys/lib/python2.7/bsddb/dbshelve.pyRX;s cCs|jj|ƒ}|j|ƒS(N(ReRXt_extract(R&Rtrec((s$/sys/lib/python2.7/bsddb/dbshelve.pytget_1@scCs"|jj||ƒ}|j|ƒS(N(ReRXRi(R&R0RRj((s$/sys/lib/python2.7/bsddb/dbshelve.pytget_2DscCs4t||jƒ}|jj||ƒ}|j|ƒS(N(RRReRXRi(R&R0R3RR1Rj((s$/sys/lib/python2.7/bsddb/dbshelve.pytget_3HscCs|j|tjBƒS(N(RkRt DB_CURRENT(R&R((s$/sys/lib/python2.7/bsddb/dbshelve.pytcurrentNscCs|j|tjBƒS(N(RkRtDB_FIRST(R&R((s$/sys/lib/python2.7/bsddb/dbshelve.pytfirstOscCs|j|tjBƒS(N(RkRtDB_LAST(R&R((s$/sys/lib/python2.7/bsddb/dbshelve.pytlastPscCs|j|tjBƒS(N(RkRtDB_NEXT(R&R((s$/sys/lib/python2.7/bsddb/dbshelve.pytnextQscCs|j|tjBƒS(N(RkRtDB_PREV(R&R((s$/sys/lib/python2.7/bsddb/dbshelve.pytprevRscCs|j|tjBƒS(N(RkRt DB_CONSUME(R&R((s$/sys/lib/python2.7/bsddb/dbshelve.pytconsumeSscCs|j|tjBƒS(N(RkRt DB_NEXT_DUP(R&R((s$/sys/lib/python2.7/bsddb/dbshelve.pytnext_dupTscCs|j|tjBƒS(N(RkRt DB_NEXT_NODUP(R&R((s$/sys/lib/python2.7/bsddb/dbshelve.pyt next_nodupUscCs|j|tjBƒS(N(RkRt DB_PREV_NODUP(R&R((s$/sys/lib/python2.7/bsddb/dbshelve.pyt prev_nodupVscCs4t||jƒ}|jj||ƒ}|j|ƒS(N(RRReR]Ri(R&R0R3RR1Rj((s$/sys/lib/python2.7/bsddb/dbshelve.pyR]YscCs"|jj||ƒ}|j|ƒS(N(RetsetRi(R&R0RRj((s$/sys/lib/python2.7/bsddb/dbshelve.pyR€_scCs"|jj||ƒ}|j|ƒS(N(Ret set_rangeRi(R&R0RRj((s$/sys/lib/python2.7/bsddb/dbshelve.pyRcscCs"|jj||ƒ}|j|ƒS(N(Ret set_recnoRi(R&trecnoRRj((s$/sys/lib/python2.7/bsddb/dbshelve.pyR‚gscCsq|dkrdS|\}}tjddks>t|tƒrQ|tj|ƒfS|tjt|dƒƒfSdS(Niis iso8859-1(R6RMRNRORPRR/(R&RjR0R1((s$/sys/lib/python2.7/bsddb/dbshelve.pyRims   "(R R!RdR'R)R,RfR`RXRkRlRmRoRqRsRuRwRyR{R}RR]R€RR‚tset_bothRi(((s$/sys/lib/python2.7/bsddb/dbshelve.pyR^s2                      (ii(ii((RdRMRNtabsolute_importRRtwarningstcatch_warningsR t __enter__tfilterwarningstDeprecationWarningt__exit__R%RtUserDictRtMutableMappingt collectionsRtDB_HASHR6RRRRR^(((s$/sys/lib/python2.7/bsddb/dbshelve.pyts<            "¨