mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
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.
This commit is contained in:
parent
74c8e55f3b
commit
deadbf50e4
5 changed files with 56 additions and 16 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue