Commit 2d9b3e6c authored by Albertas Agejevas's avatar Albertas Agejevas

Switch to pickle format 3 so bytes and unicodes are not smashed.

Will have to introduce a new protocol version for the new format.
parent d77eea90
...@@ -17,8 +17,21 @@ import sys ...@@ -17,8 +17,21 @@ import sys
PY3 = sys.version_info[0] >= 3 PY3 = sys.version_info[0] >= 3
# Pickle support if PY3:
from ZODB._compat import Pickler, Unpickler, dump, dumps, loads from pickle import Pickler, Unpickler as _Unpickler, dump, dumps, loads
class Unpickler(_Unpickler):
# Py3: Python 3 doesn't allow assignments to find_global,
# instead, find_class can be overridden
find_global = None
def find_class(self, modulename, name):
if self.find_global is None:
return super(Unpickler, self).find_class(modulename, name)
return self.find_global(modulename, name)
else:
# Pickle support
from cPickle import Pickler, Unpickler, dump, dumps, loads
# String and Bytes IO # String and Bytes IO
from ZODB._compat import BytesIO from ZODB._compat import BytesIO
...@@ -37,3 +50,4 @@ try: ...@@ -37,3 +50,4 @@ try:
from cStringIO import StringIO from cStringIO import StringIO
except: except:
from io import StringIO from io import StringIO
...@@ -33,7 +33,7 @@ def encode(*args): # args: (msgid, flags, name, args) ...@@ -33,7 +33,7 @@ def encode(*args): # args: (msgid, flags, name, args)
if PY3: if PY3:
# XXX: Py3: Needs optimization. # XXX: Py3: Needs optimization.
f = BytesIO() f = BytesIO()
pickler = Pickler(f, 1) pickler = Pickler(f, 3)
pickler.fast = 1 pickler.fast = 1
pickler.dump(args) pickler.dump(args)
res = f.getvalue() res = f.getvalue()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment