summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2003-07-13 17:21:10 (GMT)
committerTim Peters <tim.peters@gmail.com>2003-07-13 17:21:10 (GMT)
commit7a6c733c3b8ee131d7860ecb0877837e412c2959 (patch)
treee8b739adbbce23fcb1112d02d5580953d6f3b0a2 /Lib
parent4a4296ec2926dd65fe4aeb4a177445606e19ffce (diff)
downloadcpython-7a6c733c3b8ee131d7860ecb0877837e412c2959.zip
cpython-7a6c733c3b8ee131d7860ecb0877837e412c2959.tar.gz
cpython-7a6c733c3b8ee131d7860ecb0877837e412c2959.tar.bz2
Make close() identical to __del__() for a dumbdbm database. Make
closing idempotent (it used to raise a nuisance exception on the 2nd close attempt). Bugfix candidate? Probably, but arguable.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/dumbdbm.py10
-rw-r--r--Lib/test/test_dumbdbm.py7
2 files changed, 12 insertions, 5 deletions
diff --git a/Lib/dumbdbm.py b/Lib/dumbdbm.py
index 1475361..7b4ddb0 100644
--- a/Lib/dumbdbm.py
+++ b/Lib/dumbdbm.py
@@ -92,6 +92,9 @@ class _Database(UserDict.DictMixin):
# CAUTION: It's vital that _commit() succeed, and _commit() can
# be called from __del__(). Therefore we must never reference a
# global in this routine.
+ if self._index is None:
+ return # nothing to do
+
try:
self._os.unlink(self._bakfile)
except self._os.error:
@@ -204,12 +207,9 @@ class _Database(UserDict.DictMixin):
def close(self):
self._commit()
- self._index = None
- self._datfile = self._dirfile = self._bakfile = None
+ self._index = self._datfile = self._dirfile = self._bakfile = None
- def __del__(self):
- if self._index is not None:
- self._commit()
+ __del__ = close
diff --git a/Lib/test/test_dumbdbm.py b/Lib/test/test_dumbdbm.py
index 08474f7..12df673 100644
--- a/Lib/test/test_dumbdbm.py
+++ b/Lib/test/test_dumbdbm.py
@@ -38,6 +38,13 @@ class DumbDBMTestCase(unittest.TestCase):
self.read_helper(f)
f.close()
+ def test_close_twice(self):
+ f = dumbdbm.open(_fname)
+ f['a'] = 'b'
+ self.assertEqual(f['a'], 'b')
+ f.close()
+ f.close()
+
def test_dumbdbm_modification(self):
self.init_db()
f = dumbdbm.open(_fname, 'w')