³ò
œ›\Kc           @   sî  d  Z  yS e d j o& d d k Z e Z d d k l Z n d d k Z d d k l Z Wn, e j
 o  d d k	 Z	 e	 i
 e =‚  n Xe Z Z e i Z e i Z d d k	 Z	 d d k Z e	 i d j o( d d k Z d d k l Z d d Un d d 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 y3 d 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.3 through 4.4 with a simple interface.

For the full featured object oriented interface use the bsddb.db module
instead.  It mirrors the Sleepycat BerkeleyDB C API.
t   bsddb3iÿÿÿÿN(   t   DeadlockWraps   2.3(   t   refs&
  
class _iter_mixin(UserDict.DictMixin):
    def _make_iter_cursor(self):
        cur = _DeadlockWrap(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 = _DeadlockWrap(cur.first, 0,0,0)[0]
            yield key

            next = cur.next
            while 1:
                try:
                    key = _DeadlockWrap(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.
                    _DeadlockWrap(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):
        if not self.db:
            return
        try:
            cur = self._make_iter_cursor()

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

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

            next = cur.next
            while 1:
                try:
                    kv = _DeadlockWrap(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.
                    _DeadlockWrap(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   e  Z RS(    (   t   __name__t
   __module__(    (    (    s$   /usr/lib/python2.5/bsddb/__init__.pyR   –   s    t   _DBWithCursorc           B   s¼   e  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   set_get_returns_nonet   Nonet   dbct   saved_dbc_keyt   _cursor_refs(   t   selfR   (    (    s$   /usr/lib/python2.5/bsddb/__init__.pyt   __init__ž   s
    			c         C   s   |  i  ƒ  d  S(   N(   t   close(   R   (    (    s$   /usr/lib/python2.5/bsddb/__init__.pyt   __del__´   s    c         C   s`   |  i  d  j oL t |  i i ƒ |  _  |  i d  j	 o# t |  i  i |  i ƒ d  |  _ q\ n d  S(   N(   R
   R	   t   _DeadlockWrapR   t   cursorR   t   set(   R   (    (    s$   /usr/lib/python2.5/bsddb/__init__.pyt   _checkCursor·   s
    i   c         C   s¼   |  i  om |  i  } d  |  _  | o@ y# t | i d d d ƒ d |  _ Wqc t i j
 o qc Xn t | i ƒ ~ n x> |  i i	 ƒ  D]- } | ƒ  } | d  j	 o t | i ƒ q‡ q‡ Wd  S(   Ni    (
   R
   R	   R   t   currentR   R   t   DBErrorR   R   t   values(   R   t   savet   ct   cref(    (    s$   /usr/lib/python2.5/bsddb/__init__.pyt   _closeCursorsÂ   s    
		#	 	c         C   s!   |  i  d  j o t d ‚ n d  S(   Ns$   BSDDB object has already been closed(   R   R	   t   error(   R   (    (    s$   /usr/lib/python2.5/bsddb/__init__.pyt
   _checkOpenÒ   s    c         C   s   |  i  d  j	 S(   N(   R   R	   (   R   (    (    s$   /usr/lib/python2.5/bsddb/__init__.pyt   isOpenÖ   s    c            s   ˆ  i  ƒ  t ‡  f d †  ƒ S(   Nc              s   t  ˆ  i ƒ S(    (   t   lenR   (    (   R   (    s$   /usr/lib/python2.5/bsddb/__init__.pyt   <lambda>Û   s    (   R   R   (   R   (    (   R   s$   /usr/lib/python2.5/bsddb/__init__.pyt   __len__Ù   s    
c            s    ˆ  i  ƒ  t ‡  ‡ f d †  ƒ S(   Nc              s   ˆ  i  ˆ S(    (   R   (    (   R   t   key(    s$   /usr/lib/python2.5/bsddb/__init__.pyR    ß   s    (   R   R   (   R   R"   (    (   R   R"   s$   /usr/lib/python2.5/bsddb/__init__.pyt   __getitem__Ý   s    
c            s7   ˆ  i  ƒ  ˆ  i ƒ  ‡  ‡ ‡ f d †  } t | ƒ d  S(   Nc              s   ˆ ˆ  i  ˆ <d  S(   N(   R   (    (   R   t   valueR"   (    s$   /usr/lib/python2.5/bsddb/__init__.pyt   wrapFä   s    (   R   R   R   (   R   R"   R$   R%   (    (   R   R$   R"   s$   /usr/lib/python2.5/bsddb/__init__.pyt   __setitem__á   s    

c            s4   ˆ  i  ƒ  ˆ  i ƒ  ‡  ‡ f d †  } t | ƒ d  S(   Nc              s   ˆ  i  ˆ =d  S(   N(   R   (    (   R   R"   (    s$   /usr/lib/python2.5/bsddb/__init__.pyR%   ë   s    (   R   R   R   (   R   R"   R%   (    (   R   R"   s$   /usr/lib/python2.5/bsddb/__init__.pyt   __delitem__è   s    

c         C   sv   |  i  d d ƒ |  i d  j	 o t |  i i ƒ n d } |  i d  j	 o t |  i i ƒ } n d  |  _ d  |  _ | S(   NR   i    (   R   R
   R	   R   R   R   (   R   t   v(    (    s$   /usr/lib/python2.5/bsddb/__init__.pyR   ï   s    		c         C   s   |  i  ƒ  t |  i i ƒ S(   N(   R   R   R   t   keys(   R   (    (    s$   /usr/lib/python2.5/bsddb/__init__.pyR)   ú   s    
c         C   s   |  i  ƒ  t |  i i | ƒ S(   N(   R   R   R   t   has_key(   R   R"   (    (    s$   /usr/lib/python2.5/bsddb/__init__.pyR*   þ   s    
c         C   s'   |  i  ƒ  |  i ƒ  t |  i i | ƒ S(   N(   R   R   R   R
   t	   set_range(   R   R"   (    (    s$   /usr/lib/python2.5/bsddb/__init__.pyt   set_location  s    

c         C   s*   |  i  ƒ  |  i ƒ  t |  i i ƒ } | S(   N(   R   R   R   R
   t   next(   R   t   rv(    (    s$   /usr/lib/python2.5/bsddb/__init__.pyR-     s    

c         C   s*   |  i  ƒ  |  i ƒ  t |  i i ƒ } | S(   N(   R   R   R   R
   t   prev(   R   R.   (    (    s$   /usr/lib/python2.5/bsddb/__init__.pyt   previous  s    

c         C   s3   |  i  ƒ  d  |  _ |  i ƒ  t |  i i ƒ } | S(   N(   R   R	   R   R   R   R
   t   first(   R   R.   (    (    s$   /usr/lib/python2.5/bsddb/__init__.pyR1     s
    
	
c         C   s3   |  i  ƒ  d  |  _ |  i ƒ  t |  i i ƒ } | S(   N(   R   R	   R   R   R   R
   t   last(   R   R.   (    (    s$   /usr/lib/python2.5/bsddb/__init__.pyR2     s
    
	
c         C   s   |  i  ƒ  t |  i i ƒ S(   N(   R   R   R   t   sync(   R   (    (    s$   /usr/lib/python2.5/bsddb/__init__.pyR3   #  s    
(   R   R   t   __doc__R   R   R   R   R   R   R!   R#   R&   R'   R   R)   R*   R,   R-   R0   R1   R2   R3   (    (    (    s$   /usr/lib/python2.5/bsddb/__init__.pyR   ™   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
   _openDBEnvR   t   DBt	   set_flagsR	   t   set_pagesizet
   set_lordert   set_h_ffactort   set_h_nelemt   opent   DB_HASHR   (   t   filet   flagt   modet   pgsizet   ffactort   nelemt	   cachesizet   lordert   hflagst   flagst   et   d(    (    s$   /usr/lib/python2.5/bsddb/__init__.pyt   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(   R5   R6   R   R7   R	   R9   R:   R8   t   set_bt_minkeyt   set_bt_maxkeyR=   t   DB_BTREER   (   R?   R@   RA   t   btflagsRE   t
   maxkeypaget
   minkeypageRB   RF   RH   RI   RJ   (    (    s$   /usr/lib/python2.5/bsddb/__init__.pyt   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(   R5   R6   R   R7   R	   R9   R:   R8   t   set_re_delimt
   set_re_lent   set_re_sourcet
   set_re_padR=   t   DB_RECNOR   (   R?   R@   RA   t   rnflagsRE   RB   RF   t   rlent   delimt   sourcet   padRH   RI   RJ   (    (    s$   /usr/lib/python2.5/bsddb/__init__.pyt   rnopenM  s$          c         C   sŠ   t  i ƒ  } |  d  j	 o. |  d j o | i d |  ƒ qG t d ‚ n | i t  i ƒ | i d t  i t  i	 Bt  i
 Bt  i Bt  i Bƒ | S(   Ni P  i    s   cachesize must be >= 20480t   .(   R   t   DBEnvR	   t   set_cachesizeR   t   set_lk_detectt   DB_LOCK_DEFAULTR=   t
   DB_PRIVATEt	   DB_CREATEt	   DB_THREADt   DB_INIT_LOCKt   DB_INIT_MPOOL(   RE   RI   (    (    s$   /usr/lib/python2.5/bsddb/__init__.pyR6   `  s    /c         C   sÄ   |  d j o t  i } n  |  d j o
 d } n‰ |  d j o t  i } no |  d j o t  i } nU |  d j o> t  i } | d  j	 o$ 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'(
   R   t	   DB_RDONLYRd   R	   t   ost   patht   isfilet   unlinkR   Re   (   R@   R?   RH   (    (    s$   /usr/lib/python2.5/bsddb/__init__.pyR5   k  s    
	 	i   (    (   i   i   i    (   R4   R   t   _pybsddbt   _bsddbt   bsddb3.dbutilsR   R   t   bsddb.dbutilst   ImportErrort   syst   modulesR   t   _dbt   __version__R   R   Rm   t   versiont   UserDictt   weakrefR   R   R   R	   RK   RR   R]   R6   R5   t   threadRe   (    (    (    s$   /usr/lib/python2.5/bsddb/__init__.pys   <module>(   sL   

		J’		