[Python-checkins] python/dist/src/Lib/bsddb __init__.py,1.7,1.8

greg at users.sourceforge.net greg at users.sourceforge.net
Sat Sep 20 19:51:36 EDT 2003


Update of /cvsroot/python/python/dist/src/Lib/bsddb
In directory sc8-pr-cvs1:/tmp/cvs-serv11613

Modified Files:
	__init__.py 
Log Message:
Maintain backwards compatibility with python < 2.3 by dynamically
adding the iterator interface for python >= 2.3.


Index: __init__.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/bsddb/__init__.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** __init__.py	13 Sep 2003 03:18:34 -0000	1.7
--- __init__.py	20 Sep 2003 23:51:34 -0000	1.8
***************
*** 53,59 ****
  #----------------------------------------------------------------------
  
  import UserDict
  
! class _DBWithCursor(UserDict.DictMixin):
      """
      A simple wrapper around DB that makes it look like the bsddbobject in
--- 53,88 ----
  #----------------------------------------------------------------------
  
+ 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
+ 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(_iter_mixin):
      """
      A simple wrapper around DB that makes it look like the bsddbobject in
***************
*** 146,166 ****
          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
  
  #----------------------------------------------------------------------
--- 175,178 ----





More information about the Python-checkins mailing list