ó
è¾bc           @   s‹  d  Z  d d l Z e j d d k Z e r6 d d Un d d l Z e j d d k rd d d l Z nz e j d k  r‚ d d l Z n\ d d l Z e j ƒ  Z e j	 ƒ  z) e j
 d d	 d
 d e ƒd d l Z Wd e j ƒ  X[ e j Z d „  Z e j d k  rd d l m Z n d d l Z e j Z e j d e j d d d „ Z d e j f d „  ƒ  YZ d e f d „  ƒ  YZ d d d „  ƒ  YZ d S(   sN   Manage shelves of pickled objects using bsddb database files for the
storage.
iÿÿÿÿNi    i   s   from . import dbi   i   t   ignoret   messages1   the cPickle module has been removed in Python 3.0t   categoryc         C   s   t  j |  d | ƒS(   Nt   protocol(   t   cPicklet   dumps(   t   objectR   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyt   _dumpsD   s    (   t	   DictMixini°  c         C   sÒ   t  | ƒ t  d ƒ k r© | } | d k r6 t j } q© | d k rK d } q© | d k rc t j } q© | d k r{ t j } q© | d k rš t j t j B} q© t j d ‚ n  t | ƒ } | 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()
    t    t   rt   rwi    t   wt   ct   nsJ   flags should be one of 'r', 'w', 'c' or 'n' or use the bsddb.db.DB_* flags(   t   typet   dbt	   DB_RDONLYt	   DB_CREATEt   DB_TRUNCATEt   DBErrort   DBShelft   open(   t   filenamet   flagst   modet   filetypet   dbenvt   dbnamet   sflagt   d(    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyR   P   s     	t   DBShelveErrorc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyR   s   s    R   c           B   s  e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d d „ Z e j d k ru d „  Z n  d „  Z d „  Z d „  Z d d „ Z d d „ Z d d „ Z d d „ Z d d „ Z d „  Z d d d „ Z d d d „ Z d d d „ Z d d „ Z RS(   sŽ   A shelf to hold pickled objects, built upon a bsddb DB object.  It
    automatically pickles/unpickles data objects going to/from the DB.
    c         C   s:   t  j | ƒ |  _  t |  _ t r- t |  _ n	 d |  _ d  S(   Ni   (   R   t   DBt   Truet   _closedt   HIGHEST_PROTOCOLR   (   t   selfR   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyt   __init__z   s
    	c         C   s   |  j  ƒ  d  S(   N(   t   close(   R&   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyt   __del__ƒ   s    c         C   s   t  |  j | ƒ S(   sT   Many methods we can just pass through to the DB object.
        (See below)
        (   t   getattrR   (   R&   t   name(    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyt   __getattr__‡   s    c         C   s   t  |  j ƒ S(   N(   t   lenR   (   R&   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyt   __len__‘   s    c         C   s   |  j  | } t j | ƒ S(   N(   R   R   t   loads(   R&   t   keyt   data(    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyt   __getitem__•   s    c         C   s#   t  | |  j ƒ } | |  j | <d  S(   N(   R   R   R   (   R&   R0   t   valueR1   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyt   __setitem__š   s    c         C   s   |  j  | =d  S(   N(   R   (   R&   R0   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyt   __delitem__Ÿ   s    c         C   s-   | d  k	 r |  j j | ƒ S|  j j ƒ  Sd  S(   N(   t   NoneR   t   keys(   R&   t   txn(    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyR7   £   s    i   i   c         c   s#   x |  j  j ƒ  D] } | Vq Wd  S(   N(   R   R7   (   R&   t   k(    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyt   __iter__ª   s    c         O   s    |  j  j | | Ž  t |  _ d  S(   N(   R   R   t   FalseR$   (   R&   t   argst   kwargs(    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyR   µ   s    c         O   s    |  j  j | | Ž  t |  _ d  S(   N(   R   R(   R#   R$   (   R&   R<   R=   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyR(   º   s    c         C   s1   |  j  r d t |  ƒ St t |  j ƒ  ƒ ƒ Sd  S(   Ns   <DBShelf @ 0x%x - closed>(   R$   t   idt   reprt   dictt	   iteritems(   R&   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyt   __repr__¿   s    	c         C   sm   | d  k	 r! |  j j | ƒ } n |  j j ƒ  } g  } x0 | D]( \ } } | j | t j | ƒ f ƒ q= W| S(   N(   R6   R   t   itemst   appendR   R/   (   R&   R8   RC   t   newitemsR9   t   v(    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyRC   Æ   s     c         C   s@   | d  k	 r! |  j j | ƒ } n |  j j ƒ  } t t j | ƒ S(   N(   R6   R   t   valuest   mapR   R/   (   R&   R8   RG   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyRG   Ñ   s    c         C   s%   t  | |  j ƒ } |  j j | | ƒ S(   N(   R   R   R   RD   (   R&   R3   R8   R1   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyt   __appendÜ   s    c         C   s5   |  j  ƒ  t j k r( |  j | d | ƒSt d ‚ d  S(   NR8   sO   append() only supported when dbshelve opened with filetype=dbshelve.db.DB_RECNO(   t   get_typeR   t   DB_RECNOt   _DBShelf__appendR   (   R&   R3   R8   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyRD   à   s    i    c         C   s"   | d „ } |  j  j | | | ƒ S(   Nc         S   sY   t  j d d k  s" t | t ƒ r4 t j | ƒ } n t j t | d ƒ ƒ } | |  | ƒ S(   Ni    i   s	   iso8859-1(   t   syst   version_infot
   isinstancet   bytesR   R/   (   t   priKeyt   priDatat   realCallbackR1   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyt   _shelf_callbackç   s    "(   R   t	   associate(   R&   t   secondaryDBt   callbackR   RT   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyRU   æ   s    c         O   sK   |  j  j | | Ž  } y t j | ƒ SWn t t t j f k
 rF | SXd  S(   N(   R   t   getR   R/   t   EOFErrort	   TypeErrort   UnpicklingError(   R&   R<   t   kwR1   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyRX   ó   s
    c         C   s:   t  | |  j ƒ } |  j j | | | | ƒ } t j | ƒ S(   N(   R   R   R   RX   R   R/   (   R&   R0   R3   R8   R   R1   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyt   get_bothÿ   s    c         C   s+   t  |  j j | | ƒ ƒ } |  j | _ | S(   N(   t   DBShelfCursorR   t   cursorR   (   R&   R8   R   R   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyR_     s    c         C   s+   t  | |  j ƒ } |  j j | | | | ƒ S(   N(   R   R   R   t   put(   R&   R0   R3   R8   R   R1   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyR`     s    c         C   s
   t  ‚ d  S(   N(   t   NotImplementedError(   R&   t
   cursorListR   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyt   join  s    N(   i   i   (   R    R!   t   __doc__R6   R'   R)   R,   R.   R2   R4   R5   R7   RM   RN   R:   R   R(   RB   RC   RG   RL   RD   RU   RX   R]   R_   R`   Rc   (    (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyR   v   s0   			
								R^   c           B   s  e  Z d  Z d „  Z d „  Z d „  Z d d „ Z d d „ Z d „  Z d „  Z	 d	 „  Z
 d
 „  Z d d „ Z d d „ Z d d „ Z d d „ Z d d „ Z d d „ Z d d „ Z d d „ Z d d „ Z d d „ Z d d „ Z d d „ Z d d „ Z e Z d „  Z RS(   s   
    c         C   s   | |  _  d  S(   N(   t   dbc(   R&   R_   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyR'   !  s    c         C   s   |  j  ƒ  d  S(   N(   R(   (   R&   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyR)   $  s    c         C   s   t  |  j | ƒ S(   sH   Some methods we can just pass through to the cursor object.  (See below)(   R*   Re   (   R&   R+   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyR,   (  s    i    c         C   s(   t  |  j j | ƒ ƒ } |  j | _ | S(   N(   R^   Re   t   dupR   (   R&   R   R   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyRf   /  s    c         C   s(   t  | |  j ƒ } |  j j | | | ƒ S(   N(   R   R   Re   R`   (   R&   R0   R3   R   R1   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyR`   5  s    c         G   s-   t  | ƒ } t |  d | ƒ } | | Œ  d  S(   Ns   get_%d(   R-   R*   (   R&   R<   t   countt   method(    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyRX   :  s    c         C   s   |  j  j | ƒ } |  j | ƒ S(   N(   Re   RX   t   _extract(   R&   R   t   rec(    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyt   get_1?  s    c         C   s"   |  j  j | | ƒ } |  j | ƒ S(   N(   Re   RX   Ri   (   R&   R0   R   Rj   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyt   get_2C  s    c         C   s4   t  | |  j ƒ } |  j j | | ƒ } |  j | ƒ S(   N(   R   R   Re   RX   Ri   (   R&   R0   R3   R   R1   Rj   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyt   get_3G  s    c         C   s   |  j  | t j Bƒ S(   N(   Rk   R   t
   DB_CURRENT(   R&   R   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyt   currentM  R	   c         C   s   |  j  | t j Bƒ S(   N(   Rk   R   t   DB_FIRST(   R&   R   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyt   firstN  R	   c         C   s   |  j  | t j Bƒ S(   N(   Rk   R   t   DB_LAST(   R&   R   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyt   lastO  R	   c         C   s   |  j  | t j Bƒ S(   N(   Rk   R   t   DB_NEXT(   R&   R   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyt   nextP  R	   c         C   s   |  j  | t j Bƒ S(   N(   Rk   R   t   DB_PREV(   R&   R   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyt   prevQ  R	   c         C   s   |  j  | t j Bƒ S(   N(   Rk   R   t
   DB_CONSUME(   R&   R   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyt   consumeR  R	   c         C   s   |  j  | t j Bƒ S(   N(   Rk   R   t   DB_NEXT_DUP(   R&   R   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyt   next_dupS  R	   c         C   s   |  j  | t j Bƒ S(   N(   Rk   R   t   DB_NEXT_NODUP(   R&   R   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyt
   next_nodupT  R	   c         C   s   |  j  | t j Bƒ S(   N(   Rk   R   t   DB_PREV_NODUP(   R&   R   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyt
   prev_nodupU  R	   c         C   s4   t  | |  j ƒ } |  j j | | ƒ } |  j | ƒ S(   N(   R   R   Re   R]   Ri   (   R&   R0   R3   R   R1   Rj   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyR]   X  s    c         C   s"   |  j  j | | ƒ } |  j | ƒ S(   N(   Re   t   setRi   (   R&   R0   R   Rj   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyR€   ^  s    c         C   s"   |  j  j | | ƒ } |  j | ƒ S(   N(   Re   t	   set_rangeRi   (   R&   R0   R   Rj   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyR   b  s    c         C   s"   |  j  j | | ƒ } |  j | ƒ S(   N(   Re   t	   set_recnoRi   (   R&   t   recnoR   Rj   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyR‚   f  s    c         C   sq   | d  k r d  S| \ } } t j d d k  s> t | t ƒ rQ | t j | ƒ f S| t j t | d ƒ ƒ f Sd  S(   Ni    i   s	   iso8859-1(   R6   RM   RN   RO   RP   R   R/   (   R&   Rj   R0   R1   (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyRi   l  s    "(   R    R!   Rd   R'   R)   R,   Rf   R`   RX   Rk   Rl   Rm   Ro   Rq   Rs   Ru   Rw   Ry   R{   R}   R   R]   R€   R   R‚   t   set_bothRi   (    (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyR^     s2   							(   i   i   (   i   i   (    (   Rd   RM   RN   t   absolute_importR   R   t   warningst   catch_warningsR   t	   __enter__t   filterwarningst   DeprecationWarningt   __exit__R%   R   t   UserDictR   t   MutableMappingt   collectionsR   t   DB_HASHR6   R   R   R   R   R^   (    (    (    s$   /usr/lib/python2.7/bsddb/dbshelve.pyt   <module>   s<   
			"¨