|
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 @@ 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 @@ 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) |
|
0 commit comments