summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-05-28 15:50:12 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-05-28 15:50:12 (GMT)
commit20ed56c282582060020201b2ff5962c2875e9f1e (patch)
tree10ae2f55a65284b78bbba2696f5b56009e6a4658 /Lib
parent24604d5b4ed0c3b4829cc11b3f43ff79babca4c6 (diff)
parent12c575f2f6213478c29445e7092164227e125490 (diff)
downloadcpython-20ed56c282582060020201b2ff5962c2875e9f1e.zip
cpython-20ed56c282582060020201b2ff5962c2875e9f1e.tar.gz
cpython-20ed56c282582060020201b2ff5962c2875e9f1e.tar.bz2
Restore performance of some dumb database methods (regression introduced by #19385).
Diffstat (limited to 'Lib')
-rw-r--r--Lib/dbm/dumb.py27
1 files changed, 19 insertions, 8 deletions
diff --git a/Lib/dbm/dumb.py b/Lib/dbm/dumb.py
index 15dad9c..17854ee 100644
--- a/Lib/dbm/dumb.py
+++ b/Lib/dbm/dumb.py
@@ -216,8 +216,10 @@ class _Database(collections.MutableMapping):
self._commit()
def keys(self):
- self._verify_open()
- return list(self._index.keys())
+ try:
+ return list(self._index)
+ except TypeError:
+ raise error('DBM object has already been closed') from None
def items(self):
self._verify_open()
@@ -226,17 +228,26 @@ class _Database(collections.MutableMapping):
def __contains__(self, key):
if isinstance(key, str):
key = key.encode('utf-8')
- self._verify_open()
- return key in self._index
+ try:
+ return key in self._index
+ except TypeError:
+ if self._index is None:
+ raise error('DBM object has already been closed') from None
+ else:
+ raise
def iterkeys(self):
- self._verify_open()
- return iter(self._index.keys())
+ try:
+ return iter(self._index)
+ except TypeError:
+ raise error('DBM object has already been closed') from None
__iter__ = iterkeys
def __len__(self):
- self._verify_open()
- return len(self._index)
+ try:
+ return len(self._index)
+ except TypeError:
+ raise error('DBM object has already been closed') from None
def close(self):
self._commit()