Example #1
0
 def on_message(self, msg):
     if not self.channels:
         # already closed, ignore the message
         self.log.debug("Received message on closed websocket %r", msg)
         return
     if isinstance(msg, bytes):
         msg = deserialize_binary_message(msg)
     else:
         msg = json.loads(msg)
     channel = msg.pop('channel', None)
     if channel is None:
         self.log.warning("No channel specified, assuming shell: %s", msg)
         channel = 'shell'
     if channel not in self.channels:
         self.log.warning("No such channel: %r", channel)
         return
     am = self.kernel_manager.allowed_message_types
     mt = msg['header']['msg_type']
     if am and mt not in am:
         self.log.warning(
             'Received message of type "%s", which is not allowed. Ignoring.'
             % mt)
     else:
         stream = self.channels[channel]
         self.session.send(stream, msg)
Example #2
0
def test_deserialize_binary():
    s = Session()
    msg = s.msg("data_pub", content={"a": "b"})
    msg["buffers"] = [memoryview(os.urandom(2)) for i in range(3)]
    bmsg = serialize_binary_message(msg)
    msg2 = deserialize_binary_message(bmsg)
    assert msg2 == msg
def test_deserialize_binary():
    s = Session()
    msg = s.msg('data_pub', content={'a': 'b'})
    msg['buffers'] = [ memoryview(os.urandom(2)) for i in range(3) ]
    bmsg = serialize_binary_message(msg)
    msg2 = deserialize_binary_message(bmsg)
    assert msg2 == msg