mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-06 11:35:24 +08:00
Merge pull request #7798 from jasongrout/buffer-memoryview
Extract session buffers as memoryviews
This commit is contained in:
commit
0fa751b894
@ -8,6 +8,7 @@ import os
|
||||
import json
|
||||
import struct
|
||||
import warnings
|
||||
import sys
|
||||
|
||||
try:
|
||||
from urllib.parse import urlparse # Py 3
|
||||
@ -43,6 +44,8 @@ def serialize_binary_message(msg):
|
||||
# don't modify msg or buffer list in-place
|
||||
msg = msg.copy()
|
||||
buffers = list(msg.pop('buffers'))
|
||||
if sys.version_info < (3, 4):
|
||||
buffers = [x.tobytes() for x in buffers]
|
||||
bmsg = json.dumps(msg, default=date_default).encode('utf8')
|
||||
buffers.insert(0, bmsg)
|
||||
nbufs = len(buffers)
|
||||
|
@ -13,14 +13,14 @@ from ..base.zmqhandlers import (
|
||||
def test_serialize_binary():
|
||||
s = Session()
|
||||
msg = s.msg('data_pub', content={'a': 'b'})
|
||||
msg['buffers'] = [ os.urandom(3) for i in range(3) ]
|
||||
msg['buffers'] = [ memoryview(os.urandom(3)) for i in range(3) ]
|
||||
bmsg = serialize_binary_message(msg)
|
||||
nt.assert_is_instance(bmsg, bytes)
|
||||
|
||||
def test_deserialize_binary():
|
||||
s = Session()
|
||||
msg = s.msg('data_pub', content={'a': 'b'})
|
||||
msg['buffers'] = [ os.urandom(2) for i in range(3) ]
|
||||
msg['buffers'] = [ memoryview(os.urandom(2)) for i in range(3) ]
|
||||
bmsg = serialize_binary_message(msg)
|
||||
msg2 = deserialize_binary_message(bmsg)
|
||||
nt.assert_equal(msg2, msg)
|
||||
|
Loading…
Reference in New Issue
Block a user