Commit 3424a562 authored by Tiago Peixoto's avatar Tiago Peixoto

Fix issue with pickling and python3

parent aa341e2e
......@@ -52,7 +52,10 @@ def IStream_readline(self, n=None):
def OStream_write(self, s):
self.Write(s, len(s))
data = s
if not isinstance(data, str) and isinstance(data, bytes):
data = data.decode('utf-8')
self.Write(data, len(s))
libgraph_tool_core.IStream.read = IStream_read
libgraph_tool_core.IStream.readline = IStream_readline
......@@ -63,11 +66,11 @@ libgraph_tool_core.OStream.write = OStream_write
def pickler(stream, obj):
sstream = BytesIO()
pickle.dump(obj, sstream, -1)
stream.write(base64.b64encode(sstream.getvalue().encode('ascii')))
stream.write(base64.b64encode(sstream.getvalue()))
def unpickler(stream):
sstream = BytesIO(base64.b64decode(stream.read().encode('ascii')))
data = stream.read().encode('utf-8')
sstream = BytesIO(base64.b64decode(data))
return pickle.load(sstream)
libgraph_tool_core.set_pickler(pickler)
......
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