##// END OF EJS Templates
cast buffers to bytes on Python 2 for pickle.loads...
Min RK -
Show More
@@ -11,14 +11,14 b' except:'
11 import pickle
11 import pickle
12
12
13 # IPython imports
13 # IPython imports
14 from IPython.utils import py3compat
14 from IPython.utils.py3compat import PY3, buffer_to_bytes_py2
15 from IPython.utils.data import flatten
15 from IPython.utils.data import flatten
16 from IPython.utils.pickleutil import (
16 from IPython.utils.pickleutil import (
17 can, uncan, can_sequence, uncan_sequence, CannedObject,
17 can, uncan, can_sequence, uncan_sequence, CannedObject,
18 istype, sequence_types, PICKLE_PROTOCOL,
18 istype, sequence_types, PICKLE_PROTOCOL,
19 )
19 )
20
20
21 if py3compat.PY3:
21 if PY3:
22 buffer = memoryview
22 buffer = memoryview
23
23
24 #-----------------------------------------------------------------------------
24 #-----------------------------------------------------------------------------
@@ -105,10 +105,7 b' def deserialize_object(buffers, g=None):'
105 (newobj, bufs) : unpacked object, and the list of remaining unused buffers.
105 (newobj, bufs) : unpacked object, and the list of remaining unused buffers.
106 """
106 """
107 bufs = list(buffers)
107 bufs = list(buffers)
108 pobj = bufs.pop(0)
108 pobj = buffer_to_bytes_py2(bufs.pop(0))
109 if not isinstance(pobj, bytes):
110 # a zmq message
111 pobj = bytes(pobj)
112 canned = pickle.loads(pobj)
109 canned = pickle.loads(pobj)
113 if istype(canned, sequence_types) and len(canned) < MAX_ITEMS:
110 if istype(canned, sequence_types) and len(canned) < MAX_ITEMS:
114 for c in canned:
111 for c in canned:
@@ -161,11 +158,10 b' def unpack_apply_message(bufs, g=None, copy=True):'
161 Returns: original f,args,kwargs"""
158 Returns: original f,args,kwargs"""
162 bufs = list(bufs) # allow us to pop
159 bufs = list(bufs) # allow us to pop
163 assert len(bufs) >= 2, "not enough buffers!"
160 assert len(bufs) >= 2, "not enough buffers!"
164 if not copy:
161 pf = buffer_to_bytes_py2(bufs.pop(0))
165 for i in range(2):
162 f = uncan(pickle.loads(pf), g)
166 bufs[i] = bufs[i].bytes
163 pinfo = buffer_to_bytes_py2(bufs.pop(0))
167 f = uncan(pickle.loads(bufs.pop(0)), g)
164 info = pickle.loads(pinfo)
168 info = pickle.loads(bufs.pop(0))
169 arg_bufs, kwarg_bufs = bufs[:info['narg_bufs']], bufs[info['narg_bufs']:]
165 arg_bufs, kwarg_bufs = bufs[:info['narg_bufs']], bufs[info['narg_bufs']:]
170
166
171 args = []
167 args = []
@@ -17,7 +17,7 b' except ImportError:'
17 from . import codeutil # This registers a hook when it's imported
17 from . import codeutil # This registers a hook when it's imported
18 from . import py3compat
18 from . import py3compat
19 from .importstring import import_item
19 from .importstring import import_item
20 from .py3compat import string_types, iteritems
20 from .py3compat import string_types, iteritems, buffer_to_bytes_py2
21
21
22 from IPython.config import Application
22 from IPython.config import Application
23 from IPython.utils.log import get_logger
23 from IPython.utils.log import get_logger
@@ -260,8 +260,8 b' class CannedArray(CannedObject):'
260 from numpy import frombuffer
260 from numpy import frombuffer
261 data = self.buffers[0]
261 data = self.buffers[0]
262 if self.pickled:
262 if self.pickled:
263 # no shape, we just pickled it
263 # we just pickled it
264 return pickle.loads(data)
264 return pickle.loads(buffer_to_bytes_py2(data))
265 else:
265 else:
266 return frombuffer(data, dtype=self.dtype).reshape(self.shape)
266 return frombuffer(data, dtype=self.dtype).reshape(self.shape)
267
267
General Comments 0
You need to be logged in to leave comments. Login now