Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #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
Пример #7
0
    def __delitem__(self, key):
        self._checkOpen()
        self._closeCursors()

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

        _DeadlockWrap(wrapF)  # del self.db[key]
Пример #8
0
    def __setitem__(self, key, value):
        self._checkOpen()
        self._closeCursors()

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

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