mò
­fIc           @   s   d  Z  d k Z y d k l Z Wn& e j
 o d f  d „  ƒ  YZ n Xd k Z e i d e i d d d „ Z	 d e f d „  ƒ  YZ
 d	 f  d
 „  ƒ  YZ d S(   sN   Manage shelves of pickled objects using bsddb database files for the
storage.
N(   s	   DictMixint	   DictMixinc           B   s   t  Z RS(   N(   t   __name__t
   __module__(    (    (    t+   /mit/python/lib/python2.4/bsddb/dbshelve.pyR    %   s    i°  c         C   sÞ   t  | ƒ t  d ƒ j oœ | } | d j o t i } qµ | d j o
 d } qµ | d j o t i } qµ | d j o t i } qµ | d j o t i t i B} qµ t i d ‚ n t | ƒ } | 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()
    t    t   rt   rwi    t   wt   ct   nsJ   flags should be one of 'r', 'w', 'c' or 'n' or use the bsddb.db.DB_* flagsN(   t   typet   flagst   sflagt   dbt	   DB_RDONLYt	   DB_CREATEt   DB_TRUNCATEt   DBErrort   DBShelft   dbenvt   dt   opent   filenamet   dbnamet   filetypet   mode(   R   R   R   R   R   R   R   R   (    (    R   R   +   s"     
R   c           B   sÚ   t  Z d  Z e d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 e d „ Z e d	 „ Z e d
 „ Z e d „ Z e d „ Z d d „ Z d „  Z e d d „ Z e d d „ Z e 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  i | ƒ |  _  d |  _ d  S(   Ni   (   R   t   DBR   t   selft   binary(   R   R   (    (    R   t   __init__R   s    c         C   s   |  i ƒ  d  S(   N(   R   t   close(   R   (    (    R   t   __del__W   s    c         C   s   t  |  i | ƒ S(   sT   Many methods we can just pass through to the DB object.
        (See below)
        N(   t   getattrR   R   t   name(   R   R!   (    (    R   t   __getattr__[   s     c         C   s   t  |  i ƒ S(   N(   t   lenR   R   (   R   (    (    R   t   __len__e   s    c         C   s   |  i | } t i | ƒ S(   N(   R   R   t   keyt   datat   cPicklet   loads(   R   R%   R&   (    (    R   t   __getitem__i   s    c         C   s&   t  i | |  i ƒ } | |  i | <d  S(   N(   R'   t   dumpst   valueR   R   R&   R   R%   (   R   R%   R+   R&   (    (    R   t   __setitem__n   s    c         C   s   |  i | =d  S(   N(   R   R   R%   (   R   R%   (    (    R   t   __delitem__s   s    c         C   s2   | d  j o |  i i | ƒ Sn |  i i ƒ  Sd  S(   N(   t   txnt   NoneR   R   t   keys(   R   R.   (    (    R   R0   w   s    c         C   so   | d  j o |  i i | ƒ } n |  i i ƒ  } g  } x0 | D]( \ } } | i | t	 i
 | ƒ f ƒ q? W| S(   N(   R.   R/   R   R   t   itemst   newitemst   kt   vt   appendR'   R(   (   R   R.   R2   R1   R4   R3   (    (    R   R1   ~   s      c         C   sB   | d  j o |  i i | ƒ } n |  i i ƒ  } t t i | ƒ S(   N(   R.   R/   R   R   t   valuest   mapR'   R(   (   R   R.   R6   (    (    R   R6   ‰   s    c         C   s(   t  i | |  i ƒ } |  i i | | ƒ S(   N(	   R'   R*   R+   R   R   R&   R   R5   R.   (   R   R+   R.   R&   (    (    R   t   __append”   s    c         C   sI   |  i ƒ  t i j o# |  i |  _ |  i | d | ƒSn t i d ‚ d  S(   NR.   sO   append() only supported when dbshelve opened with filetype=dbshelve.db.DB_RECNO(	   R   t   get_typeR   t   DB_RECNOt   _DBShelf__appendR5   R+   R.   R   (   R   R+   R.   (    (    R   R5   ˜   s    i    c         C   s"   | d „ } |  i i | | | ƒ S(   Nc         C   s   t  i | ƒ } | |  | ƒ S(   N(   R'   R(   t   priDataR&   t   realCallbackt   priKey(   R>   R<   R=   R&   (    (    R   t   _shelf_callback    s    (   t   callbackR?   R   R   t	   associatet   secondaryDBR   (   R   RB   R@   R   R?   (    (    R   RA   Ÿ   s    c         O   sP   t  |  i i | | ƒ } y t i | ƒ SWn  t	 t i
 f j
 o | Sn Xd  S(   N(   t   applyR   R   t   gett   argst   kwR&   R'   R(   t	   TypeErrort   UnpicklingError(   R   RE   RF   R&   (    (    R   RD   §   s
    c         C   s=   t  i | |  i ƒ } |  i i | | | | ƒ } t  i | ƒ S(   N(   R'   R*   R+   R   R   R&   R   RD   R%   R.   R   R(   (   R   R%   R+   R.   R   R&   (    (    R   t   get_both³   s    c         C   s+   t  |  i i | | ƒ ƒ } |  i | _ | S(   N(   t   DBShelfCursorR   R   t   cursorR.   R   R   R   (   R   R.   R   R   (    (    R   RK   ¹   s    c         C   s.   t  i | |  i ƒ } |  i i | | | | ƒ S(   N(   R'   R*   R+   R   R   R&   R   t   putR%   R.   R   (   R   R%   R+   R.   R   R&   (    (    R   RL   ¿   s    c         C   s
   t  ‚ d  S(   N(   t   NotImplementedError(   R   t
   cursorListR   (    (    R   t   joinÄ   s    (   R   R   t   __doc__R/   R   R   R"   R$   R)   R,   R-   R0   R1   R6   R;   R5   RA   RD   RI   RK   RL   RO   (    (    (    R   R   N   s&    		
					RJ   c           B   s  t  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(   RK   R   t   dbc(   R   RK   (    (    R   R   Õ   s    c         C   s   |  i ƒ  d  S(   N(   R   R   (   R   (    (    R   R   Ø   s    c         C   s   t  |  i | ƒ S(   sH   Some methods we can just pass through to the cursor object.  (See below)N(   R    R   RQ   R!   (   R   R!   (    (    R   R"   Ü   s     i    c         C   s   t  |  i i | ƒ ƒ S(   N(   RJ   R   RQ   t   dupR   (   R   R   (    (    R   RR   ã   s    c         C   s+   t  i | |  i ƒ } |  i i | | | ƒ S(   N(
   R'   R*   R+   R   R   R&   RQ   RL   R%   R   (   R   R%   R+   R   R&   (    (    R   RL   ç   s    c         G   s0   t  | ƒ } t |  d | ƒ } t | | ƒ d  S(   Ns   get_%d(   R#   RE   t   countR    R   t   methodRC   (   R   RE   RS   RT   (    (    R   RD   ì   s    c         C   s   |  i i | ƒ } |  i | ƒ S(   N(   R   RQ   RD   R   t   rect   _extract(   R   R   RU   (    (    R   t   get_1ñ   s    c         C   s"   |  i i | | ƒ } |  i | ƒ S(   N(   R   RQ   RD   R%   R   RU   RV   (   R   R%   R   RU   (    (    R   t   get_2õ   s    c         C   s7   t  i | |  i ƒ } |  i i | | ƒ } |  i | ƒ S(   N(   R'   R*   R+   R   R   R&   RQ   RD   R%   R   RU   RV   (   R   R%   R+   R   RU   R&   (    (    R   t   get_3ù   s    c         C   s   |  i | t i Bƒ S(   N(   R   RW   R   R   t
   DB_CURRENT(   R   R   (    (    R   t   currentÿ   s    c         C   s   |  i | t i Bƒ S(   N(   R   RW   R   R   t   DB_FIRST(   R   R   (    (    R   t   first   s    c         C   s   |  i | t i Bƒ S(   N(   R   RW   R   R   t   DB_LAST(   R   R   (    (    R   t   last  s    c         C   s   |  i | t i Bƒ S(   N(   R   RW   R   R   t   DB_NEXT(   R   R   (    (    R   t   next  s    c         C   s   |  i | t i Bƒ S(   N(   R   RW   R   R   t   DB_PREV(   R   R   (    (    R   t   prev  s    c         C   s   |  i | t i Bƒ S(   N(   R   RW   R   R   t
   DB_CONSUME(   R   R   (    (    R   t   consume  s    c         C   s   |  i | t i Bƒ S(   N(   R   RW   R   R   t   DB_NEXT_DUP(   R   R   (    (    R   t   next_dup  s    c         C   s   |  i | t i Bƒ S(   N(   R   RW   R   R   t   DB_NEXT_NODUP(   R   R   (    (    R   t
   next_nodup  s    c         C   s   |  i | t i Bƒ S(   N(   R   RW   R   R   t   DB_PREV_NODUP(   R   R   (    (    R   t
   prev_nodup  s    c         C   s7   t  i | |  i ƒ } |  i i | | ƒ } |  i | ƒ S(   N(   R'   R*   R+   R   R   R&   RQ   RI   R%   R   RU   RV   (   R   R%   R+   R   RU   R&   (    (    R   RI   
  s    c         C   s"   |  i i | | ƒ } |  i | ƒ S(   N(   R   RQ   t   setR%   R   RU   RV   (   R   R%   R   RU   (    (    R   Rl     s    c         C   s"   |  i i | | ƒ } |  i | ƒ S(   N(   R   RQ   t	   set_rangeR%   R   RU   RV   (   R   R%   R   RU   (    (    R   Rm     s    c         C   s"   |  i i | | ƒ } |  i | ƒ S(   N(   R   RQ   t	   set_recnot   recnoR   RU   RV   (   R   Ro   R   RU   (    (    R   Rn     s    c         C   s8   | d  j o d  Sn  | \ } } | t i | ƒ f Sd  S(   N(   RU   R/   R%   R&   R'   R(   (   R   RU   R%   R&   (    (    R   RV     s    (   R   R   RP   R   R   R"   RR   RL   RD   RW   RX   RY   R[   R]   R_   Ra   Rc   Re   Rg   Ri   Rk   RI   Rl   Rm   Rn   t   set_bothRV   (    (    (    R   RJ   Ò   s2    							(   RP   R'   t   UserDictR    t   ImportErrorR   R   t   DB_HASHR/   R   R   RJ   (   R'   R    R   RJ   R   R   (    (    R   t   ?   s   		#„