diff options
author | Jesus Cea <jcea@jcea.es> | 2008-08-31 14:00:51 +0000 |
---|---|---|
committer | Jesus Cea <jcea@jcea.es> | 2008-08-31 14:00:51 +0000 |
commit | 4907d27c1fcc7bd990715d3023932433076e152f (patch) | |
tree | f7e79e00d3e95785b6ff3d2d0b809e6d6e5e5779 /Lib/bsddb/dbshelve.py | |
parent | 82358691f77e33301df2916746474873b35ccafa (diff) | |
download | cpython-git-4907d27c1fcc7bd990715d3023932433076e152f.tar.gz |
Update bsddb code to version 4.7.3pre2. This code should
be compatible with Python 3.0, also.
http://www.jcea.es/programacion/pybsddb.htm#bsddb3-4.7.3
Diffstat (limited to 'Lib/bsddb/dbshelve.py')
-rw-r--r-- | Lib/bsddb/dbshelve.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/Lib/bsddb/dbshelve.py b/Lib/bsddb/dbshelve.py index f5f6f8e258..e2912597d5 100644 --- a/Lib/bsddb/dbshelve.py +++ b/Lib/bsddb/dbshelve.py @@ -218,8 +218,13 @@ class DBShelf(MutableMapping): def associate(self, secondaryDB, callback, flags=0): def _shelf_callback(priKey, priData, realCallback=callback): - data = cPickle.loads(priData) + # Safe in Python 2.x because expresion short circuit + if sys.version_info[0] < 3 or isinstance(priData, bytes) : + data = cPickle.loads(priData) + else : + data = cPickle.loads(bytes(priData, "iso8859-1")) # 8 bits return realCallback(priKey, data) + return self.db.associate(secondaryDB, _shelf_callback, flags) @@ -232,7 +237,7 @@ class DBShelf(MutableMapping): data = apply(self.db.get, args, kw) try: return cPickle.loads(data) - except (TypeError, cPickle.UnpicklingError): + except (EOFError, TypeError, cPickle.UnpicklingError): return data # we may be getting the default value, or None, # so it doesn't need unpickled. @@ -350,7 +355,11 @@ class DBShelfCursor: return None else: key, data = rec - return key, cPickle.loads(data) + # Safe in Python 2.x because expresion short circuit + if sys.version_info[0] < 3 or isinstance(data, bytes) : + return key, cPickle.loads(data) + else : + return key, cPickle.loads(bytes(data, "iso8859-1")) # 8 bits #---------------------------------------------- # Methods allowed to pass-through to self.dbc |