7ec@sdZddlZejddkZer6ddUn ddlZejddkrdddlZnzejdkrddlZn\ddlZejZej z)ej dd d d e ddlZWdej X[ej Z d Zejdkrdd lmZnddlZejZejdejdddZdejfdYZdefdYZdddYZdS(sNManage shelves of pickled objects using bsddb database files for the storage. iNiisfrom . import dbiitignoretmessages1the cPickle module has been removed in Python 3.0tcategorycCstj|d|S(Ntprotocol(tcPickletdumps(tobjectR((s&/usr/lib64/python2.7/bsddb/dbshelve.pyt_dumpsDs(t DictMixinicCst|tdkr|}|dkr6tj}q|dkrKd}q|dkrctj}q|dkr{tj}q|dkrtjtjB}qtjdnt|}|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&/usr/lib64/python2.7/bsddb/dbshelve.pyRPs           t DBShelveErrorcBseZRS((t__name__t __module__(((s&/usr/lib64/python2.7/bsddb/dbshelve.pyRssRcBseZdZddZdZdZdZdZdZ dZ ddZ e j dkrud Znd Zd ZdZddZddZddZddZddZdZdddZdddZdddZddZRS(sA 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&/usr/lib64/python2.7/bsddb/dbshelve.pyt__init__zs   cCs|jdS(N(tclose(R&((s&/usr/lib64/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&/usr/lib64/python2.7/bsddb/dbshelve.pyt __getattr__scCs t|jS(N(tlenR(R&((s&/usr/lib64/python2.7/bsddb/dbshelve.pyt__len__scCs|j|}tj|S(N(RRtloads(R&tkeytdata((s&/usr/lib64/python2.7/bsddb/dbshelve.pyt __getitem__s cCs#t||j}||j|(R$tidtreprtdictt iteritems(R&((s&/usr/lib64/python2.7/bsddb/dbshelve.pyt__repr__s cCsm|dk r!|jj|}n|jj}g}x0|D](\}}|j|tj|fq=W|S(N(R6RtitemstappendRR/(R&R8RCtnewitemsR9tv((s&/usr/lib64/python2.7/bsddb/dbshelve.pyRCs  cCs@|dk r!|jj|}n|jj}ttj|S(N(R6RtvaluestmapRR/(R&R8RG((s&/usr/lib64/python2.7/bsddb/dbshelve.pyRGs cCs%t||j}|jj||S(N(RRRRD(R&R3R8R1((s&/usr/lib64/python2.7/bsddb/dbshelve.pyt__appendscCs5|jtjkr(|j|d|StddS(NR8sOappend() only supported when dbshelve opened with filetype=dbshelve.db.DB_RECNO(tget_typeRtDB_RECNOt_DBShelf__appendR(R&R3R8((s&/usr/lib64/python2.7/bsddb/dbshelve.pyRDsicCs"|d}|jj|||S(NcSsYtjddks"t|tr4tj|}ntjt|d}|||S(Niis iso8859-1(tsyst version_infot isinstancetbytesRR/(tpriKeytpriDatat realCallbackR1((s&/usr/lib64/python2.7/bsddb/dbshelve.pyt_shelf_callbacks"(Rt associate(R&t secondaryDBtcallbackRRT((s&/usr/lib64/python2.7/bsddb/dbshelve.pyRUs cOsK|jj||}ytj|SWntttjfk rF|SXdS(N(RtgetRR/tEOFErrort TypeErrortUnpicklingError(R&R<tkwR1((s&/usr/lib64/python2.7/bsddb/dbshelve.pyRXs cCs:t||j}|jj||||}tj|S(N(RRRRXRR/(R&R0R3R8RR1((s&/usr/lib64/python2.7/bsddb/dbshelve.pytget_bothscCs+t|jj||}|j|_|S(N(t DBShelfCursorRtcursorR(R&R8RR ((s&/usr/lib64/python2.7/bsddb/dbshelve.pyR_s cCs+t||j}|jj||||S(N(RRRtput(R&R0R3R8RR1((s&/usr/lib64/python2.7/bsddb/dbshelve.pyR` scCs tdS(N(tNotImplementedError(R&t cursorListR((s&/usr/lib64/python2.7/bsddb/dbshelve.pytjoinsN(ii(R R!t__doc__R6R'R)R,R.R2R4R5R7RMRNR:RR(RBRCRGRLRDRURXR]R_R`Rc(((s&/usr/lib64/python2.7/bsddb/dbshelve.pyRvs0            R^cBseZdZdZdZdZddZddZdZdZ d Z d Z dd Z dd Z dd ZddZddZddZddZddZddZddZddZddZddZeZdZRS(s cCs ||_dS(N(tdbc(R&R_((s&/usr/lib64/python2.7/bsddb/dbshelve.pyR'!scCs|jdS(N(R((R&((s&/usr/lib64/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&/usr/lib64/python2.7/bsddb/dbshelve.pyR,(sicCs(t|jj|}|j|_|S(N(R^RetdupR(R&RR ((s&/usr/lib64/python2.7/bsddb/dbshelve.pyRf/s cCs(t||j}|jj|||S(N(RRReR`(R&R0R3RR1((s&/usr/lib64/python2.7/bsddb/dbshelve.pyR`5scGs-t|}t|d|}||dS(Nsget_%d(R-R*(R&R<tcounttmethod((s&/usr/lib64/python2.7/bsddb/dbshelve.pyRX:s cCs|jj|}|j|S(N(ReRXt_extract(R&Rtrec((s&/usr/lib64/python2.7/bsddb/dbshelve.pytget_1?scCs"|jj||}|j|S(N(ReRXRi(R&R0RRj((s&/usr/lib64/python2.7/bsddb/dbshelve.pytget_2CscCs4t||j}|jj||}|j|S(N(RRReRXRi(R&R0R3RR1Rj((s&/usr/lib64/python2.7/bsddb/dbshelve.pytget_3GscCs|j|tjBS(N(RkRt DB_CURRENT(R&R((s&/usr/lib64/python2.7/bsddb/dbshelve.pytcurrentMR cCs|j|tjBS(N(RkRtDB_FIRST(R&R((s&/usr/lib64/python2.7/bsddb/dbshelve.pytfirstNR cCs|j|tjBS(N(RkRtDB_LAST(R&R((s&/usr/lib64/python2.7/bsddb/dbshelve.pytlastOR cCs|j|tjBS(N(RkRtDB_NEXT(R&R((s&/usr/lib64/python2.7/bsddb/dbshelve.pytnextPR cCs|j|tjBS(N(RkRtDB_PREV(R&R((s&/usr/lib64/python2.7/bsddb/dbshelve.pytprevQR cCs|j|tjBS(N(RkRt DB_CONSUME(R&R((s&/usr/lib64/python2.7/bsddb/dbshelve.pytconsumeRR cCs|j|tjBS(N(RkRt DB_NEXT_DUP(R&R((s&/usr/lib64/python2.7/bsddb/dbshelve.pytnext_dupSR cCs|j|tjBS(N(RkRt DB_NEXT_NODUP(R&R((s&/usr/lib64/python2.7/bsddb/dbshelve.pyt next_nodupTR cCs|j|tjBS(N(RkRt DB_PREV_NODUP(R&R((s&/usr/lib64/python2.7/bsddb/dbshelve.pyt prev_nodupUR cCs4t||j}|jj||}|j|S(N(RRReR]Ri(R&R0R3RR1Rj((s&/usr/lib64/python2.7/bsddb/dbshelve.pyR]XscCs"|jj||}|j|S(N(RetsetRi(R&R0RRj((s&/usr/lib64/python2.7/bsddb/dbshelve.pyR^scCs"|jj||}|j|S(N(Ret set_rangeRi(R&R0RRj((s&/usr/lib64/python2.7/bsddb/dbshelve.pyRbscCs"|jj||}|j|S(N(Ret set_recnoRi(R&trecnoRRj((s&/usr/lib64/python2.7/bsddb/dbshelve.pyRfscCsq|dkrdS|\}}tjddks>t|trQ|tj|fS|tjt|dfSdS(Niis iso8859-1(R6RMRNRORPRR/(R&RjR0R1((s&/usr/lib64/python2.7/bsddb/dbshelve.pyRils   "(R R!RdR'R)R,RfR`RXRkRlRmRoRqRsRuRwRyR{R}RR]RRRtset_bothRi(((s&/usr/lib64/python2.7/bsddb/dbshelve.pyR^s2                      (ii(ii((RdRMRNtabsolute_importRRtwarningstcatch_warningsR t __enter__tfilterwarningstDeprecationWarningt__exit__R%RtUserDictRtMutableMappingt collectionsRtDB_HASHR6RRRRR^(((s&/usr/lib64/python2.7/bsddb/dbshelve.pyts<            "