##// END OF EJS Templates
add pickleutil.PICKLE_PROTOCOL...
MinRK -
Show More
@@ -1,19 +1,7 b''
1 """serialization utilities for apply messages
1 """serialization utilities for apply messages"""
2
2
3 Authors:
3 # Copyright (c) IPython Development Team.
4
4 # Distributed under the terms of the Modified BSD License.
5 * Min RK
6 """
7 #-----------------------------------------------------------------------------
8 # Copyright (C) 2010-2011 The IPython Development Team
9 #
10 # Distributed under the terms of the BSD License. The full license is in
11 # the file COPYING, distributed as part of this software.
12 #-----------------------------------------------------------------------------
13
14 #-----------------------------------------------------------------------------
15 # Imports
16 #-----------------------------------------------------------------------------
17
5
18 try:
6 try:
19 import cPickle
7 import cPickle
@@ -22,13 +10,12 b' except:'
22 cPickle = None
10 cPickle = None
23 import pickle
11 import pickle
24
12
25
26 # IPython imports
13 # IPython imports
27 from IPython.utils import py3compat
14 from IPython.utils import py3compat
28 from IPython.utils.data import flatten
15 from IPython.utils.data import flatten
29 from IPython.utils.pickleutil import (
16 from IPython.utils.pickleutil import (
30 can, uncan, can_sequence, uncan_sequence, CannedObject,
17 can, uncan, can_sequence, uncan_sequence, CannedObject,
31 istype, sequence_types,
18 istype, sequence_types, PICKLE_PROTOCOL,
32 )
19 )
33
20
34 if py3compat.PY3:
21 if py3compat.PY3:
@@ -99,7 +86,7 b' def serialize_object(obj, buffer_threshold=MAX_BYTES, item_threshold=MAX_ITEMS):'
99 cobj = can(obj)
86 cobj = can(obj)
100 buffers.extend(_extract_buffers(cobj, buffer_threshold))
87 buffers.extend(_extract_buffers(cobj, buffer_threshold))
101
88
102 buffers.insert(0, pickle.dumps(cobj,-1))
89 buffers.insert(0, pickle.dumps(cobj, PICKLE_PROTOCOL))
103 return buffers
90 return buffers
104
91
105 def unserialize_object(buffers, g=None):
92 def unserialize_object(buffers, g=None):
@@ -162,8 +149,8 b' def pack_apply_message(f, args, kwargs, buffer_threshold=MAX_BYTES, item_thresho'
162
149
163 info = dict(nargs=len(args), narg_bufs=len(arg_bufs), kw_keys=kw_keys)
150 info = dict(nargs=len(args), narg_bufs=len(arg_bufs), kw_keys=kw_keys)
164
151
165 msg = [pickle.dumps(can(f),-1)]
152 msg = [pickle.dumps(can(f), PICKLE_PROTOCOL)]
166 msg.append(pickle.dumps(info, -1))
153 msg.append(pickle.dumps(info, PICKLE_PROTOCOL))
167 msg.extend(arg_bufs)
154 msg.extend(arg_bufs)
168 msg.extend(kwarg_bufs)
155 msg.extend(kwarg_bufs)
169
156
@@ -43,6 +43,7 b' from IPython.utils.traitlets import (CBytes, Unicode, Bool, Any, Instance, Set,'
43 DottedObjectName, CUnicode, Dict, Integer,
43 DottedObjectName, CUnicode, Dict, Integer,
44 TraitError,
44 TraitError,
45 )
45 )
46 from IPython.utils.pickleutil import PICKLE_PROTOCOL
46 from IPython.kernel.adapter import adapt
47 from IPython.kernel.adapter import adapt
47 from IPython.kernel.zmq.serialize import MAX_ITEMS, MAX_BYTES
48 from IPython.kernel.zmq.serialize import MAX_ITEMS, MAX_BYTES
48
49
@@ -76,7 +77,7 b' json_packer = lambda obj: jsonapi.dumps(obj, default=date_default,'
76 )
77 )
77 json_unpacker = lambda s: jsonapi.loads(s)
78 json_unpacker = lambda s: jsonapi.loads(s)
78
79
79 pickle_packer = lambda o: pickle.dumps(squash_dates(o),-1)
80 pickle_packer = lambda o: pickle.dumps(squash_dates(o), PICKLE_PROTOCOL)
80 pickle_unpacker = pickle.loads
81 pickle_unpacker = pickle.loads
81
82
82 default_packer = json_packer
83 default_packer = json_packer
@@ -28,6 +28,11 b' else:'
28 from types import ClassType
28 from types import ClassType
29 class_type = (type, ClassType)
29 class_type = (type, ClassType)
30
30
31 try:
32 PICKLE_PROTOCOL = pickle.DEFAULT_PROTOCOL
33 except AttributeError:
34 PICKLE_PROTOCOL = pickle.HIGHEST_PROTOCOL
35
31 def _get_cell_type(a=None):
36 def _get_cell_type(a=None):
32 """the type of a closure cell doesn't seem to be importable,
37 """the type of a closure cell doesn't seem to be importable,
33 so just create one
38 so just create one
@@ -244,7 +249,7 b' class CannedArray(CannedObject):'
244 self.pickled = True
249 self.pickled = True
245 if self.pickled:
250 if self.pickled:
246 # just pickle it
251 # just pickle it
247 self.buffers = [pickle.dumps(obj, -1)]
252 self.buffers = [pickle.dumps(obj, PICKLE_PROTOCOL)]
248 else:
253 else:
249 # ensure contiguous
254 # ensure contiguous
250 obj = ascontiguousarray(obj, dtype=None)
255 obj = ascontiguousarray(obj, dtype=None)
General Comments 0
You need to be logged in to leave comments. Login now