diff --git a/IPython/kernel/zmq/serialize.py b/IPython/kernel/zmq/serialize.py index 72729a1..18659c3 100644 --- a/IPython/kernel/zmq/serialize.py +++ b/IPython/kernel/zmq/serialize.py @@ -1,19 +1,7 @@ -"""serialization utilities for apply messages +"""serialization utilities for apply messages""" -Authors: - -* Min RK -""" -#----------------------------------------------------------------------------- -# Copyright (C) 2010-2011 The IPython Development Team -# -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#----------------------------------------------------------------------------- - -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. try: import cPickle @@ -22,13 +10,12 @@ except: cPickle = None import pickle - # IPython imports from IPython.utils import py3compat from IPython.utils.data import flatten from IPython.utils.pickleutil import ( can, uncan, can_sequence, uncan_sequence, CannedObject, - istype, sequence_types, + istype, sequence_types, PICKLE_PROTOCOL, ) if py3compat.PY3: @@ -99,7 +86,7 @@ def serialize_object(obj, buffer_threshold=MAX_BYTES, item_threshold=MAX_ITEMS): cobj = can(obj) buffers.extend(_extract_buffers(cobj, buffer_threshold)) - buffers.insert(0, pickle.dumps(cobj,-1)) + buffers.insert(0, pickle.dumps(cobj, PICKLE_PROTOCOL)) return buffers def unserialize_object(buffers, g=None): @@ -162,8 +149,8 @@ def pack_apply_message(f, args, kwargs, buffer_threshold=MAX_BYTES, item_thresho info = dict(nargs=len(args), narg_bufs=len(arg_bufs), kw_keys=kw_keys) - msg = [pickle.dumps(can(f),-1)] - msg.append(pickle.dumps(info, -1)) + msg = [pickle.dumps(can(f), PICKLE_PROTOCOL)] + msg.append(pickle.dumps(info, PICKLE_PROTOCOL)) msg.extend(arg_bufs) msg.extend(kwarg_bufs) diff --git a/IPython/kernel/zmq/session.py b/IPython/kernel/zmq/session.py index a9e1ec4..9d961d5 100644 --- a/IPython/kernel/zmq/session.py +++ b/IPython/kernel/zmq/session.py @@ -55,6 +55,7 @@ from IPython.utils.traitlets import (CBytes, Unicode, Bool, Any, Instance, Set, DottedObjectName, CUnicode, Dict, Integer, TraitError, ) +from IPython.utils.pickleutil import PICKLE_PROTOCOL from IPython.kernel.zmq.serialize import MAX_ITEMS, MAX_BYTES #----------------------------------------------------------------------------- @@ -83,7 +84,7 @@ def squash_unicode(obj): json_packer = lambda obj: jsonapi.dumps(obj, default=date_default) json_unpacker = lambda s: jsonapi.loads(s) -pickle_packer = lambda o: pickle.dumps(squash_dates(o),-1) +pickle_packer = lambda o: pickle.dumps(squash_dates(o), PICKLE_PROTOCOL) pickle_unpacker = pickle.loads default_packer = json_packer diff --git a/IPython/utils/pickleutil.py b/IPython/utils/pickleutil.py index bd69f40..68ae875 100644 --- a/IPython/utils/pickleutil.py +++ b/IPython/utils/pickleutil.py @@ -31,6 +31,11 @@ else: class_type = (type, ClassType) closure_attr = 'func_closure' +try: + PICKLE_PROTOCOL = pickle.DEFAULT_PROTOCOL +except AttributeError: + PICKLE_PROTOCOL = pickle.HIGHEST_PROTOCOL + #------------------------------------------------------------------------------- # Functions #------------------------------------------------------------------------------- @@ -197,7 +202,7 @@ class CannedArray(CannedObject): self.pickled = True if self.pickled: # just pickle it - self.buffers = [pickle.dumps(obj, -1)] + self.buffers = [pickle.dumps(obj, PICKLE_PROTOCOL)] else: # ensure contiguous obj = ascontiguousarray(obj, dtype=None)