mirror of https://github.com/python/cpython
Fix an uncollectable reference leak in bsddb.db.DBShelf.append
This commit is contained in:
parent
5fbf663703
commit
5d743fd187
|
@ -93,6 +93,7 @@ class DBShelf(DictMixin):
|
||||||
"""
|
"""
|
||||||
def __init__(self, dbenv=None):
|
def __init__(self, dbenv=None):
|
||||||
self.db = db.DB(dbenv)
|
self.db = db.DB(dbenv)
|
||||||
|
self._closed = True
|
||||||
if HIGHEST_PROTOCOL:
|
if HIGHEST_PROTOCOL:
|
||||||
self.protocol = HIGHEST_PROTOCOL
|
self.protocol = HIGHEST_PROTOCOL
|
||||||
else:
|
else:
|
||||||
|
@ -138,6 +139,23 @@ class DBShelf(DictMixin):
|
||||||
return self.db.keys()
|
return self.db.keys()
|
||||||
|
|
||||||
|
|
||||||
|
def open(self, *args, **kwargs):
|
||||||
|
self.db.open(*args, **kwargs)
|
||||||
|
self._closed = False
|
||||||
|
|
||||||
|
|
||||||
|
def close(self, *args, **kwargs):
|
||||||
|
self.db.close(*args, **kwargs)
|
||||||
|
self._closed = True
|
||||||
|
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
if self._closed:
|
||||||
|
return '<DBShelf @ 0x%x - closed>' % (id(self))
|
||||||
|
else:
|
||||||
|
return repr(dict(self.iteritems()))
|
||||||
|
|
||||||
|
|
||||||
def items(self, txn=None):
|
def items(self, txn=None):
|
||||||
if txn != None:
|
if txn != None:
|
||||||
items = self.db.items(txn)
|
items = self.db.items(txn)
|
||||||
|
@ -166,8 +184,7 @@ class DBShelf(DictMixin):
|
||||||
|
|
||||||
def append(self, value, txn=None):
|
def append(self, value, txn=None):
|
||||||
if self.get_type() == db.DB_RECNO:
|
if self.get_type() == db.DB_RECNO:
|
||||||
self.append = self.__append
|
return self.__append(value, txn=txn)
|
||||||
return self.append(value, txn=txn)
|
|
||||||
raise DBShelveError, "append() only supported when dbshelve opened with filetype=dbshelve.db.DB_RECNO"
|
raise DBShelveError, "append() only supported when dbshelve opened with filetype=dbshelve.db.DB_RECNO"
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue