Python3 UnicodeDecodeError in python3 on unpickling data saved in python2

svn: r21777
This commit is contained in:
Benny Malengier 2013-03-28 10:47:48 +00:00
parent f59b8fb7d8
commit c64f64657f
3 changed files with 20 additions and 2 deletions

View File

@ -111,7 +111,11 @@ class BsddbBaseCursor(object):
_flags | flags | (db.DB_RMW if self._update else 0),
**kwargs)
return (data[0], loads(data[1])) if data else None
try:
return (data[0], loads(data[1])) if data else None
except UnicodeDecodeError:
#we need to assume we opened data in python3 saved in python2
return (data[0], loads(data[1], encoding='utf-8')) if data else None
return get

View File

@ -1536,6 +1536,10 @@ class DbBsddbRead(DbReadBase, Callback):
handle = handle.encode('utf-8')
try:
return table.get(handle, txn=self.txn)
except UnicodeDecodeError:
#we need to assume we opened data in python3 saved in python2
raw = table.db.get(handle, txn=self.txn)
return pickle.loads(raw, encoding='utf-8')
except DBERRS as msg:
self.__log_error()
raise DbError(msg)

View File

@ -648,7 +648,13 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
pass
# bookmarks
meta = lambda meta: self.metadata.get(meta, default=[])
def meta(key):
try:
return self.metadata.get(key, default=[])
except UnicodeDecodeError:
#we need to assume we opened data in python3 saved in python2
raw = self.metadata.db.get(key, default=[])
return pickle.loads(raw, encoding='utf-8') if raw else raw
self.bookmarks.set(meta(b'bookmarks'))
self.family_bookmarks.set(meta(b'family_bookmarks'))
@ -1800,6 +1806,10 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
handle = handle.encode('utf-8')
try:
data = data_map.get(handle, txn=self.txn)
except UnicodeDecodeError:
#we need to assume we opened data in python3 saved in python2
raw = data_map.db.get(handle, txn=self.txn)
data = pickle.loads(raw, encoding='utf-8')
except:
data = None
# under certain circumstances during a database reload,