Commit fc732cfa authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Fix remaining issues with pickling in Python 3

parent b2ed6f34
...@@ -70,7 +70,6 @@ string lexical_cast<string,python::object>(const python::object & o) ...@@ -70,7 +70,6 @@ string lexical_cast<string,python::object>(const python::object & o)
stringstream s; stringstream s;
object_pickler(OStream(s), o); object_pickler(OStream(s), o);
return s.str(); return s.str();
return "";
} }
template <> template <>
...@@ -96,7 +95,7 @@ public: ...@@ -96,7 +95,7 @@ public:
std::streamsize read(char* s, std::streamsize n) std::streamsize read(char* s, std::streamsize n)
{ {
python::object pbuf = _file.attr("read")(n); python::object pbuf = _file.attr("read")(n);
string buf = python::extract<string>(pbuf); string buf = python::extract<string>(pbuf.attr("decode")("utf-8"));
for (size_t i = 0; i < buf.size(); ++i) for (size_t i = 0; i < buf.size(); ++i)
s[i] = buf[i]; s[i] = buf[i];
return buf.size(); return buf.size();
...@@ -106,7 +105,7 @@ public: ...@@ -106,7 +105,7 @@ public:
{ {
string buf(s, s+n); string buf(s, s+n);
python::object pbuf(buf); python::object pbuf(buf);
_file.attr("write")(pbuf); _file.attr("write")(pbuf.attr("encode")("utf-8"));
return n; return n;
} }
......
...@@ -1771,7 +1771,7 @@ class Graph(object): ...@@ -1771,7 +1771,7 @@ class Graph(object):
def __getstate__(self): def __getstate__(self):
state = dict() state = dict()
sio = BytesIO() sio = BytesIO()
stream = gzip.GzipFile(fileobj=sio, mode="w") stream = gzip.GzipFile(fileobj=sio, mode="wb")
self.save(stream, "xml") self.save(stream, "xml")
stream.close() stream.close()
state["blob"] = sio.getvalue() state["blob"] = sio.getvalue()
...@@ -1782,7 +1782,7 @@ class Graph(object): ...@@ -1782,7 +1782,7 @@ class Graph(object):
blob = state["blob"] blob = state["blob"]
if blob != "": if blob != "":
sio = BytesIO(blob) sio = BytesIO(blob)
stream = gzip.GzipFile(fileobj=sio, mode="r") stream = gzip.GzipFile(fileobj=sio, mode="rb")
self.load(stream, "xml") self.load(stream, "xml")
......
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