��Qc@s�dZddlZejddkZer6ddUnddlZejddkrdddlZnzejdkr�ddlZn\ddlZej�Zej �z)ej
dd d
de�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_CREATEtDB_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�Zej
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|<dS(N(RRR(R&R0tvalueR1((s$/sys/lib/python2.7/bsddb/dbshelve.pyt__setitem__�scCs|j|=dS(N(R(R&R0((s$/sys/lib/python2.7/bsddb/dbshelve.pyt__delitem__�scCs-|dk r|jj|�S|jj�SdS(N(tNoneRtkeys(R&ttxn((s$/sys/lib/python2.7/bsddb/dbshelve.pyR7�siiccs#x|jj�D]}|VqWdS(N(RR7(R&tk((s$/sys/lib/python2.7/bsddb/dbshelve.pyt__iter__�scOs |jj||�t|_dS(N(RRtFalseR$(R&targstkwargs((s$/sys/lib/python2.7/bsddb/dbshelve.pyR�scOs |jj||�t|_dS(N(RR(R#R$(R&R<R=((s$/sys/lib/python2.7/bsddb/dbshelve.pyR(�scCs1|jrdt|�Stt|j���SdS(Ns<DBShelf @ 0x%x - closed>(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�scCs%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(tsystversion_infot
isinstancetbytesRR/(tpriKeytpriDatatrealCallbackR1((s$/sys/lib/python2.7/bsddb/dbshelve.pyt_shelf_callback�s"(Rt associate(R&tsecondaryDBtcallbackRRT((s$/sys/lib/python2.7/bsddb/dbshelve.pyRU�scOsK|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_scCs+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
�Zdd�Zdd�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.pyRf0scCs(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;scCs|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(RkRtDB_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.pyR�cscCs"|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�R�R�tset_bothRi(((s$/sys/lib/python2.7/bsddb/dbshelve.pyR^s2 (ii(ii((RdRMRNtabsolute_importRRtwarningstcatch_warningsRt __enter__tfilterwarningstDeprecationWarningt__exit__R%RtUserDictRtMutableMappingtcollectionsRtDB_HASHR6RRRRR^(((s$/sys/lib/python2.7/bsddb/dbshelve.pyt<module>s<
"
|