summaryrefslogtreecommitdiffstats
path: root/Lib/bsddb
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2003-09-12 06:33:37 (GMT)
committerRaymond Hettinger <python@rcn.com>2003-09-12 06:33:37 (GMT)
commitdeadbf50e4cc3c541e706d5bf1aa73624bed36a6 (patch)
tree407b9e5f2aa93866cdda5fb5b70fee3d49d2de0e /Lib/bsddb
parent74c8e55f3b64b8819a1950be4ac1323c74931cc2 (diff)
downloadcpython-deadbf50e4cc3c541e706d5bf1aa73624bed36a6.zip
cpython-deadbf50e4cc3c541e706d5bf1aa73624bed36a6.tar.gz
cpython-deadbf50e4cc3c541e706d5bf1aa73624bed36a6.tar.bz2
SF #662923
Add support for the iterator and mapping protocols. For Py2.3, this was done for shelve, dumbdbm and other mapping objects, but not for bsddb and dbhash which were inadvertently missed.
Diffstat (limited to 'Lib/bsddb')
-rw-r--r--Lib/bsddb/__init__.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/Lib/bsddb/__init__.py b/Lib/bsddb/__init__.py
index 1ec6adc..5fc8a38 100644
--- a/Lib/bsddb/__init__.py
+++ b/Lib/bsddb/__init__.py
@@ -52,8 +52,9 @@ error = db.DBError # So bsddb.error will mean something...
#----------------------------------------------------------------------
+import UserDict
-class _DBWithCursor:
+class _DBWithCursor(UserDict.DictMixin):
"""
A simple wrapper around DB that makes it look like the bsddbobject in
the old module. It uses a cursor as needed to provide DB traversal.
@@ -144,6 +145,14 @@ class _DBWithCursor:
self._checkOpen()
return self.db.sync()
+ def __iter__(self):
+ try:
+ yield self.first()[0]
+ next = self.next
+ while 1:
+ yield next()[0]
+ except _bsddb.DBNotFoundError:
+ return
#----------------------------------------------------------------------
# Compatibility object factory functions