Permalink
Browse files

Date is properly removed from JSON reply before WebSocket forward.

* Both the header and parent_header have a date field that cannot
  be json serialized. This field is just removed for now, but
  in the future, we will covert the date to a ISO8601 field.
* Better error handling around this code has also been added
  to prevent the server from crashing due to malformed messages.
  • Loading branch information...
1 parent baf6e69 commit b796f247229f321ccb36ea62e802782cd357d712 @ellisonbg ellisonbg committed Aug 15, 2011
Showing with 16 additions and 9 deletions.
  1. +16 −9 IPython/frontend/html/notebook/handlers.py
@@ -101,10 +101,25 @@ def _reserialize_reply(self, msg_list):
"""
idents, msg_list = self.session.feed_identities(msg_list)
msg = self.session.unserialize(msg_list)
- msg['header'].pop('date')
+ try:
+ msg['header'].pop('date')
+ except KeyError:
+ pass
+ try:
+ msg['parent_header'].pop('date')
+ except KeyError:
+ pass
msg.pop('buffers')
return jsonapi.dumps(msg)
+ def _on_zmq_reply(self, msg_list):
+ try:
+ msg = self._reserialize_reply(msg_list)
+ except:
+ self.application.kernel_manager.log.critical("Malformed message: %r" % msg_list)
+ else:
+ self.write_message(msg)
+
class IOPubHandler(ZMQStreamHandler):
@@ -122,10 +137,6 @@ def open(self, kernel_id):
self.iopub_stream.on_recv(self._on_zmq_reply)
self.start_hb(self.kernel_died)
- def _on_zmq_reply(self, msg_list):
- msg = self._reserialize_reply(msg_list)
- self.write_message(msg)
-
def on_close(self):
self.stop_hb()
self.iopub_stream.close()
@@ -186,10 +197,6 @@ def open(self, kernel_id):
self.shell_stream = self.application.kernel_manager.create_shell_stream(kernel_id)
self.shell_stream.on_recv(self._on_zmq_reply)
- def _on_zmq_reply(self, msg_list):
- msg = self._reserialize_reply(msg_list)
- self.write_message(msg)
-
def on_message(self, msg):
if len(msg) < self.max_msg_size:
msg = jsonapi.loads(msg)

0 comments on commit b796f24

Please sign in to comment.