Example #1
0
    def iteritems(self):
        if not self.db:
            return
        self._kill_iteration = False
        self._in_iter += 1
        try:
            try:
                cur = self._make_iter_cursor()
                kv = _DeadlockWrap(cur.first)
                key = kv[0]
                yield kv
                next = getattr(cur, 'next')
                while 1:
                    try:
                        kv = _DeadlockWrap(next)
                        key = kv[0]
                        yield kv
                    except _bsddb.DBCursorClosedError:
                        if self._kill_iteration:
                            raise RuntimeError('Database changed size during iteration.')
                        cur = self._make_iter_cursor()
                        _DeadlockWrap(cur.set, key, 0, 0, 0)
                        next = getattr(cur, 'next')

            except _bsddb.DBNotFoundError:
                pass
            except _bsddb.DBCursorClosedError:
                pass

        except:
            self._in_iter -= 1
            raise

        self._in_iter -= 1
Example #2
0
 def _checkCursor(self):
     if self.dbc is None:
         self.dbc = _DeadlockWrap(self.db.cursor)
         if self.saved_dbc_key is not None:
             _DeadlockWrap(self.dbc.set, self.saved_dbc_key)
             self.saved_dbc_key = None
     return
Example #3
0
    def iteritems(self):
        if not self.db:
            return
        self._kill_iteration = False
        self._in_iter += 1
        try:
            try:
                cur = self._make_iter_cursor()
                kv = _DeadlockWrap(cur.first)
                key = kv[0]
                yield kv
                next = getattr(cur, 'next')
                while 1:
                    try:
                        kv = _DeadlockWrap(next)
                        key = kv[0]
                        yield kv
                    except _bsddb.DBCursorClosedError:
                        if self._kill_iteration:
                            raise RuntimeError(
                                'Database changed size during iteration.')
                        cur = self._make_iter_cursor()
                        _DeadlockWrap(cur.set, key, 0, 0, 0)
                        next = getattr(cur, 'next')

            except _bsddb.DBNotFoundError:
                pass
            except _bsddb.DBCursorClosedError:
                pass

        except:
            self._in_iter -= 1
            raise

        self._in_iter -= 1
Example #4
0
 def _checkCursor(self):
     if self.dbc is None:
         self.dbc = _DeadlockWrap(self.db.cursor)
         if self.saved_dbc_key is not None:
             _DeadlockWrap(self.dbc.set, self.saved_dbc_key)
             self.saved_dbc_key = None
     return
Example #5
0
    def __iter__(self):
        self._kill_iteration = False
        self._in_iter += 1
        try:
            try:
                cur = self._make_iter_cursor()
                key = _DeadlockWrap(cur.first, 0, 0, 0)[0]
                yield key
                next = getattr(cur, "next")
                while 1:
                    try:
                        key = _DeadlockWrap(next, 0, 0, 0)[0]
                        yield key
                    except _bsddb.DBCursorClosedError:
                        if self._kill_iteration:
                            raise RuntimeError("Database changed size during iteration.")
                        cur = self._make_iter_cursor()
                        _DeadlockWrap(cur.set, key, 0, 0, 0)
                        next = getattr(cur, "next")

            except _bsddb.DBNotFoundError:
                pass
            except _bsddb.DBCursorClosedError:
                pass

        except:
            self._in_iter -= 1
            raise

        self._in_iter -= 1
Example #6
0
 def __setitem__(self, key, value):
     self._checkOpen()
     self._closeCursors()
     if self._in_iter and key not in self:
         self._kill_iteration = True
     def wrapF():
         self.db[key] = value
     _DeadlockWrap(wrapF)  # self.db[key] = value
Example #7
0
    def __delitem__(self, key):
        self._checkOpen()
        self._closeCursors()

        def wrapF():
            del self.db[key]

        _DeadlockWrap(wrapF)  # del self.db[key]
Example #8
0
    def __setitem__(self, key, value):
        self._checkOpen()
        self._closeCursors()

        def wrapF():
            self.db[key] = value

        _DeadlockWrap(wrapF)  # self.db[key] = value
Example #9
0
 def __setitem__(self, key, value):
     self._checkOpen()
     self._closeCursors()
     if self._in_iter and key not in self:
         self._kill_iteration = True
     def wrapF():
         self.db[key] = value
     _DeadlockWrap(wrapF)  # self.db[key] = value
Example #10
0
 def __delitem__(self, key):
     self._checkOpen()
     self._closeCursors()
     if self._in_iter and key in self:
         self._kill_iteration = True
     def wrapF():
         del self.db[key]
     _DeadlockWrap(wrapF)  # del self.db[key]
Example #11
0
 def __delitem__(self, key):
     self._checkOpen()
     self._closeCursors()
     if self._in_iter and key in self:
         self._kill_iteration = True
     def wrapF():
         del self.db[key]
     _DeadlockWrap(wrapF)  # del self.db[key]
Example #12
0
 def close(self):
     self._closeCursors(save=0)
     if self.dbc is not None:
         _DeadlockWrap(self.dbc.close)
     v = 0
     if self.db is not None:
         v = _DeadlockWrap(self.db.close)
     self.dbc = None
     self.db = None
     return v
Example #13
0
 def close(self):
     self._closeCursors(save=0)
     if self.dbc is not None:
         _DeadlockWrap(self.dbc.close)
     v = 0
     if self.db is not None:
         v = _DeadlockWrap(self.db.close)
     self.dbc = None
     self.db = None
     return v
Example #14
0
 def _closeCursors(self, save=1):
     if self.dbc:
         c = self.dbc
         self.dbc = None
         if save:
             try:
                 self.saved_dbc_key = _DeadlockWrap(c.current, 0, 0, 0)[0]
             except db.DBError:
                 pass
         _DeadlockWrap(c.close)
         del c
     for cref in self._cursor_refs.values():
         c = cref()
         if c is not None:
             _DeadlockWrap(c.close)
Example #15
0
 def _closeCursors(self, save=1):
     if self.dbc:
         c = self.dbc
         self.dbc = None
         if save:
             try:
                 self.saved_dbc_key = _DeadlockWrap(c.current, 0,0,0)[0]
             except db.DBError:
                 pass
         _DeadlockWrap(c.close)
         del c
     for cref in self._cursor_refs.values():
         c = cref()
         if c is not None:
             _DeadlockWrap(c.close)
Example #16
0
 def last(self):
     self._checkOpen()
     # fix 1725856: don't needlessly try to restore our cursor position
     self.saved_dbc_key = None
     self._checkCursor()
     rv = _DeadlockWrap(self.dbc.last)
     return rv
Example #17
0
 def last(self):
     self._checkOpen()
     # fix 1725856: don't needlessly try to restore our cursor position
     self.saved_dbc_key = None
     self._checkCursor()
     rv = _DeadlockWrap(self.dbc.last)
     return rv
Example #18
0
    def iteritems(self):
        if not self.db:
            return
        self._kill_iteration = False
        self._in_iter += 1
        try:
            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 = getattr(cur, "next")
                while 1:
                    try:
                        kv = _DeadlockWrap(next)
                        key = kv[0]
                        yield kv
                    except _bsddb.DBCursorClosedError:
                        if self._kill_iteration:
                            raise RuntimeError('Database changed size '
                                               'during iteration.')
                        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 = getattr(cur, "next")
            except _bsddb.DBNotFoundError:
                pass
            except _bsddb.DBCursorClosedError:
                # the database was modified during iteration.  abort.
                pass


# When Python 2.3 not supported in bsddb3, we can change this to "finally"
        except:
            self._in_iter -= 1
            raise

        self._in_iter -= 1
Example #19
0
    def iteritems(self):
        if not self.db:
            return
        self._kill_iteration = False
        self._in_iter += 1
        try:
            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 = getattr(cur, "next")
                while 1:
                    try:
                        kv = _DeadlockWrap(next)
                        key = kv[0]
                        yield kv
                    except _bsddb.DBCursorClosedError:
                        if self._kill_iteration:
                            raise RuntimeError('Database changed size '
                                               'during iteration.')
                        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 = getattr(cur, "next")
            except _bsddb.DBNotFoundError:
                pass
            except _bsddb.DBCursorClosedError:
                # the database was modified during iteration.  abort.
                pass
# When Python 2.4 not supported in bsddb3, we can change this to "finally"
        except :
            self._in_iter -= 1
            raise

        self._in_iter -= 1
Example #20
0
    def __iter__(self):
        self._kill_iteration = False
        self._in_iter += 1
        try:
            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 = getattr(cur, "next")
                while 1:
                    try:
                        key = _DeadlockWrap(next, 0, 0, 0)[0]
                        yield key
                    except _bsddb.DBCursorClosedError:
                        if self._kill_iteration:
                            raise RuntimeError('Database changed size '
                                               'during iteration.')
                        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 = getattr(cur, "next")
            except _bsddb.DBNotFoundError:
                pass
            except _bsddb.DBCursorClosedError:
                # the database was modified during iteration.  abort.
                pass
# When Python 2.3 not supported in bsddb3, we can change this to "finally"
        except:
            self._in_iter -= 1
            raise

        self._in_iter -= 1
Example #21
0
    def __iter__(self):
        self._kill_iteration = False
        self._in_iter += 1
        try:
            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 = getattr(cur, "next")
                while 1:
                    try:
                        key = _DeadlockWrap(next, 0,0,0)[0]
                        yield key
                    except _bsddb.DBCursorClosedError:
                        if self._kill_iteration:
                            raise RuntimeError('Database changed size '
                                               'during iteration.')
                        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 = getattr(cur, "next")
            except _bsddb.DBNotFoundError:
                pass
            except _bsddb.DBCursorClosedError:
                # the database was modified during iteration.  abort.
                pass
# When Python 2.4 not supported in bsddb3, we can change this to "finally"
        except :
            self._in_iter -= 1
            raise

        self._in_iter -= 1
Example #22
0
 def next(self):
     self._checkOpen()
     self._checkCursor()
     rv = _DeadlockWrap(self.dbc.next)
     return rv
Example #23
0
 def __setitem__(self, key, value):
     self._checkOpen()
     self._closeCursors()
     def wrapF():
         self.db[key] = value
     _DeadlockWrap(wrapF)  # self.db[key] = value
Example #24
0
 def __delitem__(self, key):
     self._checkOpen()
     self._closeCursors()
     def wrapF():
         del self.db[key]
     _DeadlockWrap(wrapF)  # del self.db[key]
Example #25
0
 def __getitem__(self, key):
     self._checkOpen()
     return _DeadlockWrap(lambda: self.db[key])  # self.db[key]
Example #26
0
 def __getitem__(self, key):
     self._checkOpen()
     return _DeadlockWrap(lambda: self.db[key])  # self.db[key]
Example #27
0
 def previous(self):
     self._checkOpen()
     self._checkCursor()
     rv = _DeadlockWrap(self.dbc.prev)
     return rv
Example #28
0
 def __len__(self):
     self._checkOpen()
     return _DeadlockWrap(lambda: len(self.db))  # len(self.db)
Example #29
0
 def next(self):
     self._checkOpen()
     self._checkCursor()
     rv = _DeadlockWrap(getattr(self.dbc, 'next'))
     return rv
Example #30
0
 def next(self):  # Renamed by "2to3"
     self._checkOpen()
     self._checkCursor()
     rv = _DeadlockWrap(getattr(self.dbc, "next"))
     return rv
Example #31
0
 def sync(self):
     self._checkOpen()
     return _DeadlockWrap(self.db.sync)
Example #32
0
 def previous(self):
     self._checkOpen()
     self._checkCursor()
     rv = _DeadlockWrap(self.dbc.prev)
     return rv
Example #33
0
 def set_location(self, key):
     self._checkOpen()
     self._checkCursor()
     return _DeadlockWrap(self.dbc.set_range, key)
Example #34
0
 def last(self):
     self._checkOpen()
     self.saved_dbc_key = None
     self._checkCursor()
     rv = _DeadlockWrap(self.dbc.last)
     return rv
Example #35
0
 def last(self):
     self._checkOpen()
     self.saved_dbc_key = None
     self._checkCursor()
     rv = _DeadlockWrap(self.dbc.last)
     return rv
Example #36
0
 def next(self):
     self._checkOpen()
     self._checkCursor()
     rv = _DeadlockWrap(self.dbc.next)
     return rv
Example #37
0
 def keys(self):
     self._checkOpen()
     return _DeadlockWrap(self.db.keys)
Example #38
0
 def __repr__(self) :
     if self.isOpen() :
         return repr(dict(_DeadlockWrap(self.db.items)))
     return repr(dict())
Example #39
0
 def __len__(self):
     self._checkOpen()
     return _DeadlockWrap(lambda: len(self.db))  # len(self.db)
Example #40
0
 def last(self):
     self._checkOpen()
     self._checkCursor()
     rv = _DeadlockWrap(self.dbc.last)
     return rv
Example #41
0
 def __repr__(self):
     if self.isOpen():
         return repr(dict(_DeadlockWrap(self.db.items)))
     return repr(dict())
Example #42
0
 def next(self):
     self._checkOpen()
     self._checkCursor()
     rv = _DeadlockWrap(getattr(self.dbc, 'next'))
     return rv
Example #43
0
 def sync(self):
     self._checkOpen()
     return _DeadlockWrap(self.db.sync)
Example #44
0
 def has_key(self, key):
     self._checkOpen()
     return _DeadlockWrap(self.db.has_key, key)
Example #45
0
 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
Example #46
0
 def next(self):  # Renamed by "2to3"
     self._checkOpen()
     self._checkCursor()
     rv = _DeadlockWrap(getattr(self.dbc, "next"))
     return rv
Example #47
0
 def keys(self):
     self._checkOpen()
     return _DeadlockWrap(self.db.keys)
Example #48
0
 def has_key(self, key):
     self._checkOpen()
     return _DeadlockWrap(self.db.has_key, key)
Example #49
0
 def set_location(self, key):
     self._checkOpen()
     self._checkCursor()
     return _DeadlockWrap(self.dbc.set_range, key)
Example #50
0
 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
Example #51
0
 def last(self):
     self._checkOpen()
     self._checkCursor()
     rv = _DeadlockWrap(self.dbc.last)
     return rv