##// END OF EJS Templates
Merge pull request #6029 from minrk/dumps-protocol...
Thomas Kluyver -
r17067:4a94456c merge
parent child Browse files
Show More
@@ -1,19 +1,7 b''
1 """serialization utilities for apply messages
1 """serialization utilities for apply messages"""
2 2
3 Authors:
4
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 #-----------------------------------------------------------------------------
3 # Copyright (c) IPython Development Team.
4 # Distributed under the terms of the Modified BSD License.
17 5
18 6 try:
19 7 import cPickle
@@ -22,13 +10,12 b' except:'
22 10 cPickle = None
23 11 import pickle
24 12
25
26 13 # IPython imports
27 14 from IPython.utils import py3compat
28 15 from IPython.utils.data import flatten
29 16 from IPython.utils.pickleutil import (
30 17 can, uncan, can_sequence, uncan_sequence, CannedObject,
31 istype, sequence_types,
18 istype, sequence_types, PICKLE_PROTOCOL,
32 19 )
33 20
34 21 if py3compat.PY3:
@@ -99,7 +86,7 b' def serialize_object(obj, buffer_threshold=MAX_BYTES, item_threshold=MAX_ITEMS):'
99 86 cobj = can(obj)
100 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 90 return buffers
104 91
105 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 150 info = dict(nargs=len(args), narg_bufs=len(arg_bufs), kw_keys=kw_keys)
164 151
165 msg = [pickle.dumps(can(f),-1)]
166 msg.append(pickle.dumps(info, -1))
152 msg = [pickle.dumps(can(f), PICKLE_PROTOCOL)]
153 msg.append(pickle.dumps(info, PICKLE_PROTOCOL))
167 154 msg.extend(arg_bufs)
168 155 msg.extend(kwarg_bufs)
169 156
@@ -43,6 +43,7 b' from IPython.utils.traitlets import (CBytes, Unicode, Bool, Any, Instance, Set,'
43 43 DottedObjectName, CUnicode, Dict, Integer,
44 44 TraitError,
45 45 )
46 from IPython.utils.pickleutil import PICKLE_PROTOCOL
46 47 from IPython.kernel.adapter import adapt
47 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 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 81 pickle_unpacker = pickle.loads
81 82
82 83 default_packer = json_packer
@@ -29,6 +29,11 b' else:'
29 29 from types import ClassType
30 30 class_type = (type, ClassType)
31 31
32 try:
33 PICKLE_PROTOCOL = pickle.DEFAULT_PROTOCOL
34 except AttributeError:
35 PICKLE_PROTOCOL = pickle.HIGHEST_PROTOCOL
36
32 37 def _get_cell_type(a=None):
33 38 """the type of a closure cell doesn't seem to be importable,
34 39 so just create one
@@ -245,7 +250,7 b' class CannedArray(CannedObject):'
245 250 self.pickled = True
246 251 if self.pickled:
247 252 # just pickle it
248 self.buffers = [pickle.dumps(obj, -1)]
253 self.buffers = [pickle.dumps(obj, PICKLE_PROTOCOL)]
249 254 else:
250 255 # ensure contiguous
251 256 obj = ascontiguousarray(obj, dtype=None)
General Comments 0
You need to be logged in to leave comments. Login now