Skip to content

Commit da480c0

Browse files
committed
Merge pull request #44 from minrk/serialize-buf
cast buffers to bytes in CannedBytes
2 parents 71b0c82 + 01af09e commit da480c0

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

ipykernel/pickleutil.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from ipython_genutils import py3compat
1818
from ipython_genutils.importstring import import_item
19-
from ipython_genutils.py3compat import string_types, iteritems, buffer_to_bytes_py2
19+
from ipython_genutils.py3compat import string_types, iteritems, buffer_to_bytes, buffer_to_bytes_py2
2020

2121
from . import codeutil # This registers a hook when it's imported
2222

@@ -290,7 +290,8 @@ def get_object(self, g=None):
290290

291291

292292
class CannedBytes(CannedObject):
293-
wrap = bytes
293+
wrap = staticmethod(buffer_to_bytes)
294+
294295
def __init__(self, obj):
295296
self.buffers = [obj]
296297

ipykernel/tests/test_pickleutil.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
import os
23
import pickle
34

45
import nose.tools as nt
@@ -59,4 +60,9 @@ def foo():
5960
bar = loads(pfoo)
6061
nt.assert_equal(foo(), bar())
6162

62-
63+
def test_uncan_bytes_buffer():
64+
data = b'data'
65+
canned = can(data)
66+
canned.buffers = [memoryview(buf) for buf in canned.buffers]
67+
out = uncan(canned)
68+
nt.assert_equal(out, data)

0 commit comments

Comments
 (0)