summaryrefslogtreecommitdiff
path: root/Lib/bsddb/dbshelve.py
diff options
context:
space:
mode:
authorJesus Cea <jcea@jcea.es>2008-07-23 11:38:42 +0000
committerJesus Cea <jcea@jcea.es>2008-07-23 11:38:42 +0000
commitc5a11fabdb03d032f278f86e600bcdaafdb5d783 (patch)
treee7db234112c7ac06aebe9c1e7833b0dd4168c664 /Lib/bsddb/dbshelve.py
parent30e208d525cd472446feb91b774cf472e7122918 (diff)
downloadcpython-git-c5a11fabdb03d032f278f86e600bcdaafdb5d783.tar.gz
bsddb module updated to version 4.7.2devel9.
This patch publishes the work done until now for Python 3.0 compatibility. Still a lot to be done. When possible, we use 3.0 features in Python 2.6, easing development and testing, and exposing internal changes to a wider audience, for better test coverage. Some mode details: http://www.jcea.es/programacion/pybsddb.htm#bsddb3-4.7.2
Diffstat (limited to 'Lib/bsddb/dbshelve.py')
-rw-r--r--Lib/bsddb/dbshelve.py33
1 files changed, 26 insertions, 7 deletions
diff --git a/Lib/bsddb/dbshelve.py b/Lib/bsddb/dbshelve.py
index 6d7414ed9c..f5f6f8e258 100644
--- a/Lib/bsddb/dbshelve.py
+++ b/Lib/bsddb/dbshelve.py
@@ -30,11 +30,17 @@ storage.
#------------------------------------------------------------------------
import cPickle
-import db
import sys
-#At version 2.3 cPickle switched to using protocol instead of bin and
-#DictMixin was added
+import sys
+absolute_import = (sys.version_info[0] >= 3)
+if absolute_import :
+ # Because this syntaxis is not valid before Python 2.5
+ exec("from . import db")
+else :
+ import db
+
+#At version 2.3 cPickle switched to using protocol instead of bin
if sys.version_info[:3] >= (2, 3, 0):
HIGHEST_PROTOCOL = cPickle.HIGHEST_PROTOCOL
# In python 2.3.*, "cPickle.dumps" accepts no
@@ -47,13 +53,22 @@ if sys.version_info[:3] >= (2, 3, 0):
def _dumps(object, protocol):
return cPickle.dumps(object, protocol=protocol)
- from UserDict import DictMixin
-
else:
HIGHEST_PROTOCOL = None
def _dumps(object, protocol):
return cPickle.dumps(object, bin=protocol)
- class DictMixin: pass
+
+
+if sys.version_info[0:2] <= (2, 5) :
+ try:
+ from UserDict import DictMixin
+ except ImportError:
+ # DictMixin is new in Python 2.3
+ class DictMixin: pass
+ MutableMapping = DictMixin
+else :
+ import collections
+ MutableMapping = collections.MutableMapping
#------------------------------------------------------------------------
@@ -96,7 +111,7 @@ def open(filename, flags=db.DB_CREATE, mode=0660, filetype=db.DB_HASH,
class DBShelveError(db.DBError): pass
-class DBShelf(DictMixin):
+class DBShelf(MutableMapping):
"""A shelf to hold pickled objects, built upon a bsddb DB object. It
automatically pickles/unpickles data objects going to/from the DB.
"""
@@ -147,6 +162,10 @@ class DBShelf(DictMixin):
else:
return self.db.keys()
+ if sys.version_info[0:2] >= (2, 6) :
+ def __iter__(self) :
+ return self.db.__iter__()
+
def open(self, *args, **kwargs):
self.db.open(*args, **kwargs)