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, |
|
|
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), |
|
|
166 |
msg.append(pickle.dumps(info, |
|
|
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 |
@@ -55,6 +55,7 b' from IPython.utils.traitlets import (CBytes, Unicode, Bool, Any, Instance, Set,' | |||
|
55 | 55 | DottedObjectName, CUnicode, Dict, Integer, |
|
56 | 56 | TraitError, |
|
57 | 57 | ) |
|
58 | from IPython.utils.pickleutil import PICKLE_PROTOCOL | |
|
58 | 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 | 84 | json_packer = lambda obj: jsonapi.dumps(obj, default=date_default) |
|
84 | 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 | 88 | pickle_unpacker = pickle.loads |
|
88 | 89 | |
|
89 | 90 | default_packer = json_packer |
@@ -31,6 +31,11 b' else:' | |||
|
31 | 31 | class_type = (type, ClassType) |
|
32 | 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 | 40 | # Functions |
|
36 | 41 | #------------------------------------------------------------------------------- |
@@ -197,7 +202,7 b' class CannedArray(CannedObject):' | |||
|
197 | 202 | self.pickled = True |
|
198 | 203 | if self.pickled: |
|
199 | 204 | # just pickle it |
|
200 |
self.buffers = [pickle.dumps(obj, |
|
|
205 | self.buffers = [pickle.dumps(obj, PICKLE_PROTOCOL)] | |
|
201 | 206 | else: |
|
202 | 207 | # ensure contiguous |
|
203 | 208 | obj = ascontiguousarray(obj, dtype=None) |
General Comments 0
You need to be logged in to leave comments.
Login now