##// END OF EJS Templates
use istype instead of isinstance for canning tuples/lists...
MinRK -
Show More
@@ -34,7 +34,8 b' except:'
34 34 from IPython.utils import py3compat
35 35 from IPython.utils.data import flatten
36 36 from IPython.utils.pickleutil import (
37 can, uncan, can_sequence, uncan_sequence, CannedObject
37 can, uncan, can_sequence, uncan_sequence, CannedObject,
38 istype, sequence_types,
38 39 )
39 40
40 41 if py3compat.PY3:
@@ -91,11 +92,11 b' def serialize_object(obj, buffer_threshold=MAX_BYTES, item_threshold=MAX_ITEMS):'
91 92 [bufs] : list of buffers representing the serialized object.
92 93 """
93 94 buffers = []
94 if isinstance(obj, (list, tuple)) and len(obj) < item_threshold:
95 if istype(obj, sequence_types) and len(obj) < item_threshold:
95 96 cobj = can_sequence(obj)
96 97 for c in cobj:
97 98 buffers.extend(_extract_buffers(c, buffer_threshold))
98 elif isinstance(obj, dict) and len(obj) < item_threshold:
99 elif istype(obj, dict) and len(obj) < item_threshold:
99 100 cobj = {}
100 101 for k in sorted(obj.iterkeys()):
101 102 c = can(obj[k])
@@ -129,7 +130,7 b' def unserialize_object(buffers, g=None):'
129 130 # a zmq message
130 131 pobj = bytes(pobj)
131 132 canned = pickle.loads(pobj)
132 if isinstance(canned, (list, tuple)) and len(canned) < MAX_ITEMS:
133 if istype(canned, sequence_types) and len(canned) < MAX_ITEMS:
133 134 for c in canned:
134 135 _restore_buffers(c, bufs)
135 136 newobj = uncan_sequence(canned, g)
@@ -18,6 +18,7 b' __docformat__ = "restructuredtext en"'
18 18 import copy
19 19 import logging
20 20 import sys
21 from collections import namedtuple
21 22 from types import FunctionType
22 23
23 24 try:
@@ -249,7 +250,7 b' def can_class(obj):'
249 250
250 251 def can_dict(obj):
251 252 """can the *values* of a dict"""
252 if isinstance(obj, dict):
253 if istype(obj, dict):
253 254 newobj = {}
254 255 for k, v in obj.iteritems():
255 256 newobj[k] = can(v)
@@ -257,9 +258,11 b' def can_dict(obj):'
257 258 else:
258 259 return obj
259 260
261 sequence_types = (list, tuple, set)
262
260 263 def can_sequence(obj):
261 264 """can the elements of a sequence"""
262 if isinstance(obj, (list, tuple)):
265 if istype(obj, sequence_types):
263 266 t = type(obj)
264 267 return t([can(i) for i in obj])
265 268 else:
@@ -285,7 +288,7 b' def uncan(obj, g=None):'
285 288 return obj
286 289
287 290 def uncan_dict(obj, g=None):
288 if isinstance(obj, dict):
291 if istype(obj, dict):
289 292 newobj = {}
290 293 for k, v in obj.iteritems():
291 294 newobj[k] = uncan(v,g)
@@ -294,7 +297,7 b' def uncan_dict(obj, g=None):'
294 297 return obj
295 298
296 299 def uncan_sequence(obj, g=None):
297 if isinstance(obj, (list, tuple)):
300 if istype(obj, sequence_types):
298 301 t = type(obj)
299 302 return t([uncan(i,g) for i in obj])
300 303 else:
General Comments 0
You need to be logged in to leave comments. Login now