mò
­fIc           @   s¶  d  Z  y- e d j o d k Z e Z n
 d k Z Wn) e j
 o d k Z e i e =‚  n Xe Z Z e i	 Z	 e i
 Z d k Z d k Z e i d j o" d k Z d k l Z d d Un d f  d „  ƒ  YZ d e f d	 „  ƒ  YZ d
 d d d d d d d d „ Z d
 d d d d d d d d „ Z d
 d d d d d d d d d d „
 Z d „  Z d „  Z y0 d k Z [ e i ƒ  d j  o d e _ n Wn e j
 o d e _ n Xd S(   s(   Support for BerkeleyDB 3.2 through 4.2.
t   bsddb3Ns   2.3(   s   refsç	  
class _iter_mixin(UserDict.DictMixin):
    def _make_iter_cursor(self):
        cur = self.db.cursor()
        key = id(cur)
        self._cursor_refs[key] = ref(cur, self._gen_cref_cleaner(key))
        return cur

    def _gen_cref_cleaner(self, key):
        # use generate the function for the weakref callback here
        # to ensure that we do not hold a strict reference to cur
        # in the callback.
        return lambda ref: self._cursor_refs.pop(key, None)

    def __iter__(self):
        try:
            cur = self._make_iter_cursor()

            # FIXME-20031102-greg: race condition.  cursor could
            # be closed by another thread before this call.

            # since we're only returning keys, we call the cursor
            # methods with flags=0, dlen=0, dofs=0
            key = cur.first(0,0,0)[0]
            yield key

            next = cur.next
            while 1:
                try:
                    key = next(0,0,0)[0]
                    yield key
                except _bsddb.DBCursorClosedError:
                    cur = self._make_iter_cursor()
                    # FIXME-20031101-greg: race condition.  cursor could
                    # be closed by another thread before this call.
                    cur.set(key,0,0,0)
                    next = cur.next
        except _bsddb.DBNotFoundError:
            return
        except _bsddb.DBCursorClosedError:
            # the database was modified during iteration.  abort.
            return

    def iteritems(self):
        try:
            try:
                cur = self._make_iter_cursor()
            except AttributeError:
                return

            # FIXME-20031102-greg: race condition.  cursor could
            # be closed by another thread before this call.

            kv = cur.first()
            key = kv[0]
            yield kv

            next = cur.next
            while 1:
                try:
                    kv = next()
                    key = kv[0]
                    yield kv
                except _bsddb.DBCursorClosedError:
                    cur = self._make_iter_cursor()
                    # FIXME-20031101-greg: race condition.  cursor could
                    # be closed by another thread before this call.
                    cur.set(key,0,0,0)
                    next = cur.next
        except _bsddb.DBNotFoundError:
            return
        except _bsddb.DBCursorClosedError:
            # the database was modified during iteration.  abort.
            return
t   _iter_mixinc           B   s   t  Z RS(   N(   t   __name__t
   __module__(    (    (    t+   /mit/python/lib/python2.4/bsddb/__init__.pyR   ’   s    t   _DBWithCursorc           B   s¼   t  Z d  Z d „  Z d „  Z d „  Z d d „ Z d „  Z d „  Z d „  Z	 d	 „  Z
 d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s˜   
    A simple wrapper around DB that makes it look like the bsddbobject in
    the old module.  It uses a cursor as needed to provide DB traversal.
    c         C   s8   | |  _  |  i  i d ƒ d  |  _ d  |  _ h  |  _ d  S(   Ni    (   t   dbt   selft   set_get_returns_nonet   Nonet   dbct   saved_dbc_keyt   _cursor_refs(   R   R   (    (    R   t   __init__š   s
    			c         C   s   |  i ƒ  d  S(   N(   R   t   close(   R   (    (    R   t   __del__°   s    c         C   sZ   |  i d  j oF |  i i ƒ  |  _ |  i d  j	 o  |  i i |  i ƒ d  |  _ qV n d  S(   N(   R   R
   R	   R   t   cursorR   t   set(   R   (    (    R   t   _checkCursor³   s
    i   c         C   s³   |  i og |  i } d  |  _ | o= y  | i d d d ƒ d |  _ Wq` t i j
 o q` Xn | i	 ƒ  ~ n x; |  i
 i ƒ  D]* } | ƒ  } | d  j	 o | i	 ƒ  q q Wd  S(   Ni    (   R   R
   t   cR	   t   savet   currentR   R   t   DBErrorR   R   t   valuest   cref(   R   R   R   R   (    (    R   t   _closeCursors¾   s    
		 	
 	c         C   s!   |  i d  j o t d ‚ n d  S(   Ns$   BSDDB object has already been closed(   R   R   R	   t   error(   R   (    (    R   t
   _checkOpenÎ   s    c         C   s   |  i d  j	 S(   N(   R   R   R	   (   R   (    (    R   t   isOpenÒ   s    c         C   s   |  i ƒ  t |  i ƒ S(   N(   R   R   t   lenR   (   R   (    (    R   t   __len__Õ   s    
c         C   s   |  i ƒ  |  i | S(   N(   R   R   R   t   key(   R   R   (    (    R   t   __getitem__Ù   s    
c         C   s%   |  i ƒ  |  i ƒ  | |  i | <d  S(   N(   R   R   R   t   valueR   R   (   R   R   R!   (    (    R   t   __setitem__Ý   s    

c         C   s"   |  i ƒ  |  i ƒ  |  i | =d  S(   N(   R   R   R   R   R   (   R   R   (    (    R   t   __delitem__â   s    

c         C   sp   |  i d d ƒ |  i d  j	 o |  i i ƒ  n d } |  i d  j	 o |  i i ƒ  } n d  |  _ d  |  _ | S(   NR   i    (   R   R   R
   R	   R   t   vR   (   R   R$   (    (    R   R   ç   s    		c         C   s   |  i ƒ  |  i i ƒ  S(   N(   R   R   R   t   keys(   R   (    (    R   R%   ò   s    
c         C   s   |  i ƒ  |  i i | ƒ S(   N(   R   R   R   t   has_keyR   (   R   R   (    (    R   R&   ö   s    
c         C   s$   |  i ƒ  |  i ƒ  |  i i | ƒ S(   N(   R   R   R   R
   t	   set_rangeR   (   R   R   (    (    R   t   set_locationú   s    

c         C   s'   |  i ƒ  |  i ƒ  |  i i ƒ  } | S(   N(   R   R   R   R
   t   nextt   rv(   R   R*   (    (    R   R)   ÿ   s    

c         C   s'   |  i ƒ  |  i ƒ  |  i i ƒ  } | S(   N(   R   R   R   R
   t   prevR*   (   R   R*   (    (    R   t   previous  s    

c         C   s'   |  i ƒ  |  i ƒ  |  i i ƒ  } | S(   N(   R   R   R   R
   t   firstR*   (   R   R*   (    (    R   R-     s    

c         C   s'   |  i ƒ  |  i ƒ  |  i i ƒ  } | S(   N(   R   R   R   R
   t   lastR*   (   R   R*   (    (    R   R.     s    

c         C   s   |  i ƒ  |  i i ƒ  S(   N(   R   R   R   t   sync(   R   (    (    R   R/     s    
(   R   R   t   __doc__R   R   R   R   R   R   R   R    R"   R#   R   R%   R&   R(   R)   R,   R-   R.   R/   (    (    (    R   R   •   s(    																	R   i¶  i    c	         C   sÒ   t  | |  ƒ } t | ƒ }	 t i |	 ƒ }
 |
 i
 | ƒ | d  j	 o |
 i | ƒ n | d  j	 o |
 i | ƒ n | d  j	 o |
 i | ƒ n | d  j	 o |
 i | ƒ n |
 i |  t i | | ƒ t |
 ƒ S(   N(   t
   _checkflagt   flagt   filet   flagst
   _openDBEnvt	   cachesizet   eR   t   DBt   dt	   set_flagst   hflagst   pgsizeR	   t   set_pagesizet   lordert
   set_lordert   ffactort   set_h_ffactort   nelemt   set_h_nelemt   opent   DB_HASHt   modeR   (   R3   R2   RF   R<   R@   RB   R6   R>   R;   R7   R9   R4   (    (    R   t   hashopen  s        c	         C   sÒ   t  | |  ƒ } t | ƒ }	 t i |	 ƒ }
 | d  j	 o |
 i | ƒ n | d  j	 o |
 i | ƒ n |
 i | ƒ | d  j	 o |
 i | ƒ n | d  j	 o |
 i | ƒ n |
 i |  t i | | ƒ t |
 ƒ S(   N(   R1   R2   R3   R4   R5   R6   R7   R   R8   R9   R<   R	   R=   R>   R?   R:   t   btflagst
   minkeypaget   set_bt_minkeyt
   maxkeypaget   set_bt_maxkeyRD   t   DB_BTREERF   R   (   R3   R2   RF   RH   R6   RK   RI   R<   R>   R7   R9   R4   (    (    R   t   btopen/  s        c         C   s  t  | |  ƒ } t | ƒ } t i | ƒ } | d  j	 o | i | ƒ n | d  j	 o | i | ƒ n | i | ƒ | d  j	 o | i | ƒ n | d  j	 o | i | ƒ n |	 d  j	 o | i |	 ƒ n |
 d  j	 o | i |
 ƒ n | i |  t i | | ƒ t | ƒ S(   N(   R1   R2   R3   R4   R5   R6   R7   R   R8   R9   R<   R	   R=   R>   R?   R:   t   rnflagst   delimt   set_re_delimt   rlent
   set_re_lent   sourcet   set_re_sourcet   padt
   set_re_padRD   t   DB_RECNORF   R   (   R3   R2   RF   RO   R6   R<   R>   RR   RP   RT   RV   R7   R9   R4   (    (    R   t   rnopenA  s$          c         C   sz   t  i ƒ  } |  d  j	 o. |  d j o | i d |  ƒ qG t d ‚ n | i d t  i t  i	 Bt  i
 Bt  i Bt  i Bƒ | S(   Ni P  i    s   cachesize must be >= 20480t   .(   R   t   DBEnvR7   R6   R	   t   set_cachesizeR   RD   t
   DB_PRIVATEt	   DB_CREATEt	   DB_THREADt   DB_INIT_LOCKt   DB_INIT_MPOOL(   R6   R7   (    (    R   R5   T  s    /c         C   s·   |  d j o t i } n“ |  d j o
 d } n| |  d j o t i } nb |  d j o t i } nH |  d j o1 t i } t i i | ƒ o t i	 | ƒ q¬ n
 t
 d ‚ | t i BS(   Nt   rt   rwi    t   wR   t   ns+   flags should be one of 'r', 'w', 'c' or 'n'(   R2   R   t	   DB_RDONLYR4   R^   t   ost   patht   isfileR3   t   unlinkR   R_   (   R2   R3   R4   (    (    R   R1   ^  s    
		i   (   i   i   i    (   R0   R   t   _pybsddbt   _bsddbt   ImportErrort   syst   modulesR   t   _dbt   __version__R   R   Rg   t   versiont   UserDictt   weakreft   refR   R   R	   RG   RN   RY   R5   R1   t   threadR_   (   RG   Rq   R5   RY   Ru   R1   Rs   Rp   R   Rl   Rn   R   Rv   RN   R   R   Rk   Rg   (    (    R   t   ?%   s>   	
	

			LŠ!!'	
		