Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
cec1b3f6
Commit
cec1b3f6
authored
Sep 20, 2003
by
Gregory P. Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Maintain backwards compatibility with python < 2.3 by dynamically
adding the iterator interface for python >= 2.3.
parent
0aab0020
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
18 deletions
+30
-18
Lib/bsddb/__init__.py
Lib/bsddb/__init__.py
+30
-18
No files found.
Lib/bsddb/__init__.py
View file @
cec1b3f6
...
@@ -52,9 +52,38 @@ error = db.DBError # So bsddb.error will mean something...
...
@@ -52,9 +52,38 @@ error = db.DBError # So bsddb.error will mean something...
#----------------------------------------------------------------------
#----------------------------------------------------------------------
import
sys
# for backwards compatibility with python versions older than 2.3, the
# iterator interface is dynamically defined and added using a mixin
# class. old python can't tokenize it due to the yield keyword.
if
sys
.
version
>=
'2.3'
:
exec
"""
import UserDict
import UserDict
class _iter_mixin(UserDict.DictMixin):
def __iter__(self):
try:
yield self.first()[0]
next = self.next
while 1:
yield next()[0]
except _bsddb.DBNotFoundError:
return
def iteritems(self):
try:
yield self.first()
next = self.next
while 1:
yield next()
except _bsddb.DBNotFoundError:
return
"""
else
:
class
_iter_mixin
:
pass
class
_DBWithCursor
(
UserDict
.
DictMixin
):
class
_DBWithCursor
(
_iter_mixin
):
"""
"""
A simple wrapper around DB that makes it look like the bsddbobject in
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.
the old module. It uses a cursor as needed to provide DB traversal.
...
@@ -145,23 +174,6 @@ class _DBWithCursor(UserDict.DictMixin):
...
@@ -145,23 +174,6 @@ class _DBWithCursor(UserDict.DictMixin):
self
.
_checkOpen
()
self
.
_checkOpen
()
return
self
.
db
.
sync
()
return
self
.
db
.
sync
()
def
__iter__
(
self
):
try
:
yield
self
.
first
()[
0
]
next
=
self
.
next
while
1
:
yield
next
()[
0
]
except
_bsddb
.
DBNotFoundError
:
return
def
iteritems
(
self
):
try
:
yield
self
.
first
()
next
=
self
.
next
while
1
:
yield
next
()
except
_bsddb
.
DBNotFoundError
:
return
#----------------------------------------------------------------------
#----------------------------------------------------------------------
# Compatibility object factory functions
# Compatibility object factory functions
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment