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, |
|
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), |
|
152 | msg = [pickle.dumps(can(f), PICKLE_PROTOCOL)] | |
166 |
msg.append(pickle.dumps(info, |
|
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 |
@@ -55,6 +55,7 b' from IPython.utils.traitlets import (CBytes, Unicode, Bool, Any, Instance, Set,' | |||||
55 | DottedObjectName, CUnicode, Dict, Integer, |
|
55 | DottedObjectName, CUnicode, Dict, Integer, | |
56 | TraitError, |
|
56 | TraitError, | |
57 | ) |
|
57 | ) | |
|
58 | from IPython.utils.pickleutil import PICKLE_PROTOCOL | |||
58 | from IPython.kernel.zmq.serialize import MAX_ITEMS, MAX_BYTES |
|
59 | from IPython.kernel.zmq.serialize import MAX_ITEMS, MAX_BYTES | |
59 |
|
60 | |||
60 | #----------------------------------------------------------------------------- |
|
61 | #----------------------------------------------------------------------------- | |
@@ -83,7 +84,7 b' def squash_unicode(obj):' | |||||
83 | json_packer = lambda obj: jsonapi.dumps(obj, default=date_default) |
|
84 | json_packer = lambda obj: jsonapi.dumps(obj, default=date_default) | |
84 | json_unpacker = lambda s: jsonapi.loads(s) |
|
85 | json_unpacker = lambda s: jsonapi.loads(s) | |
85 |
|
86 | |||
86 |
pickle_packer = lambda o: pickle.dumps(squash_dates(o), |
|
87 | pickle_packer = lambda o: pickle.dumps(squash_dates(o), PICKLE_PROTOCOL) | |
87 | pickle_unpacker = pickle.loads |
|
88 | pickle_unpacker = pickle.loads | |
88 |
|
89 | |||
89 | default_packer = json_packer |
|
90 | default_packer = json_packer |
@@ -31,6 +31,11 b' else:' | |||||
31 | class_type = (type, ClassType) |
|
31 | class_type = (type, ClassType) | |
32 | closure_attr = 'func_closure' |
|
32 | closure_attr = 'func_closure' | |
33 |
|
33 | |||
|
34 | try: | |||
|
35 | PICKLE_PROTOCOL = pickle.DEFAULT_PROTOCOL | |||
|
36 | except AttributeError: | |||
|
37 | PICKLE_PROTOCOL = pickle.HIGHEST_PROTOCOL | |||
|
38 | ||||
34 | #------------------------------------------------------------------------------- |
|
39 | #------------------------------------------------------------------------------- | |
35 | # Functions |
|
40 | # Functions | |
36 | #------------------------------------------------------------------------------- |
|
41 | #------------------------------------------------------------------------------- | |
@@ -197,7 +202,7 b' class CannedArray(CannedObject):' | |||||
197 | self.pickled = True |
|
202 | self.pickled = True | |
198 | if self.pickled: |
|
203 | if self.pickled: | |
199 | # just pickle it |
|
204 | # just pickle it | |
200 |
self.buffers = [pickle.dumps(obj, |
|
205 | self.buffers = [pickle.dumps(obj, PICKLE_PROTOCOL)] | |
201 | else: |
|
206 | else: | |
202 | # ensure contiguous |
|
207 | # ensure contiguous | |
203 | obj = ascontiguousarray(obj, dtype=None) |
|
208 | obj = ascontiguousarray(obj, dtype=None) |
General Comments 0
You need to be logged in to leave comments.
Login now