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
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
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
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
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
def __delitem__(self, key): self._checkOpen() self._closeCursors() def wrapF(): del self.db[key] _DeadlockWrap(wrapF) # del self.db[key]
def __setitem__(self, key, value): self._checkOpen() self._closeCursors() def wrapF(): self.db[key] = value _DeadlockWrap(wrapF) # self.db[key] = value
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]
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
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)
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)
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
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
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
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
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
def next(self): self._checkOpen() self._checkCursor() rv = _DeadlockWrap(self.dbc.next) return rv
def __getitem__(self, key): self._checkOpen() return _DeadlockWrap(lambda: self.db[key]) # self.db[key]
def previous(self): self._checkOpen() self._checkCursor() rv = _DeadlockWrap(self.dbc.prev) return rv
def __len__(self): self._checkOpen() return _DeadlockWrap(lambda: len(self.db)) # len(self.db)
def next(self): self._checkOpen() self._checkCursor() rv = _DeadlockWrap(getattr(self.dbc, 'next')) return rv
def next(self): # Renamed by "2to3" self._checkOpen() self._checkCursor() rv = _DeadlockWrap(getattr(self.dbc, "next")) return rv
def sync(self): self._checkOpen() return _DeadlockWrap(self.db.sync)
def set_location(self, key): self._checkOpen() self._checkCursor() return _DeadlockWrap(self.dbc.set_range, key)
def last(self): self._checkOpen() self.saved_dbc_key = None self._checkCursor() rv = _DeadlockWrap(self.dbc.last) return rv
def keys(self): self._checkOpen() return _DeadlockWrap(self.db.keys)
def __repr__(self) : if self.isOpen() : return repr(dict(_DeadlockWrap(self.db.items))) return repr(dict())
def last(self): self._checkOpen() self._checkCursor() rv = _DeadlockWrap(self.dbc.last) return rv
def __repr__(self): if self.isOpen(): return repr(dict(_DeadlockWrap(self.db.items))) return repr(dict())
def has_key(self, key): self._checkOpen() return _DeadlockWrap(self.db.has_key, key)
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