##// 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:
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
@@ -29,6 +29,11 b' else:'
29 from types import ClassType
29 from types import ClassType
30 class_type = (type, ClassType)
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 def _get_cell_type(a=None):
37 def _get_cell_type(a=None):
33 """the type of a closure cell doesn't seem to be importable,
38 """the type of a closure cell doesn't seem to be importable,
34 so just create one
39 so just create one
@@ -245,7 +250,7 b' class CannedArray(CannedObject):'
245 self.pickled = True
250 self.pickled = True
246 if self.pickled:
251 if self.pickled:
247 # just pickle it
252 # just pickle it
248 self.buffers = [pickle.dumps(obj, -1)]
253 self.buffers = [pickle.dumps(obj, PICKLE_PROTOCOL)]
249 else:
254 else:
250 # ensure contiguous
255 # ensure contiguous
251 obj = ascontiguousarray(obj, dtype=None)
256 obj = ascontiguousarray(obj, dtype=None)
General Comments 0
You need to be logged in to leave comments. Login now