summaryrefslogtreecommitdiffstats
path: root/Lib/bsddb
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2007-10-13 23:23:58 (GMT)
committerGregory P. Smith <greg@mad-scientist.com>2007-10-13 23:23:58 (GMT)
commit659e7f44e2f0bc92db8b4e33fb6bae429dcbd205 (patch)
tree2f5e174ede49c82ee0e068b521fcc5c8b6871947 /Lib/bsddb
parentddacf968682818a34a90ec6702fbb44098914a9d (diff)
downloadcpython-659e7f44e2f0bc92db8b4e33fb6bae429dcbd205.zip
cpython-659e7f44e2f0bc92db8b4e33fb6bae429dcbd205.tar.gz
cpython-659e7f44e2f0bc92db8b4e33fb6bae429dcbd205.tar.bz2
Merge 58450: fix uncollectable reference caused by bsddb.db.DBShelf.append
Adds a DBShelf __repr__ method to not raise an exception when the DB is closed.
Diffstat (limited to 'Lib/bsddb')
-rw-r--r--Lib/bsddb/dbshelve.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/Lib/bsddb/dbshelve.py b/Lib/bsddb/dbshelve.py
index c687ab5..87be3d1 100644
--- a/Lib/bsddb/dbshelve.py
+++ b/Lib/bsddb/dbshelve.py
@@ -86,6 +86,7 @@ class DBShelf(DictMixin):
"""
def __init__(self, dbenv=None):
self.db = db.DB(dbenv)
+ self._closed = True
self.binary = 1
@@ -128,6 +129,23 @@ class DBShelf(DictMixin):
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):
if txn != None:
items = self.db.items(txn)
@@ -156,8 +174,7 @@ class DBShelf(DictMixin):
def append(self, value, txn=None):
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")