summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/bsddb/__init__.py11
-rwxr-xr-xLib/test/test_bsddb.py24
2 files changed, 28 insertions, 7 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
diff --git a/Lib/test/test_bsddb.py b/Lib/test/test_bsddb.py
index aa58ef8..87145fb 100755
--- a/Lib/test/test_bsddb.py
+++ b/Lib/test/test_bsddb.py
@@ -20,12 +20,24 @@ def test(openmethod, what, ondisk=1):
verify(f.keys() == [])
if verbose:
print 'creation...'
- f['0'] = ''
- f['a'] = 'Guido'
- f['b'] = 'van'
- f['c'] = 'Rossum'
- f['d'] = 'invented'
- f['f'] = 'Python'
+ keys = ['0', 'a', 'b', 'c', 'd', 'e', 'f']
+ values = ['', 'Guido', 'van', 'Rossum', 'invented', 'Python']
+ items = zip(keys, values)
+ for k, v in items:
+ f[k] = v
+
+ # test mapping iteration methods
+ from sets import Set
+ def verifyset(s1, s2):
+ verify(Set(s1) == Set(s2))
+ verify(keys, f.keys())
+ verify(values, f.values())
+ verify(items, f.items())
+ verify(keys, f)
+ verify(keys, f.iterkeys())
+ verify(values, f.itervalues())
+ verify(items, f.iteritems())
+
if verbose:
print '%s %s %s' % (f['a'], f['b'], f['c'])