From 046aebacca2386334f402099dc169a82875264c5 2011-05-18 19:45:55 From: Brian Granger Date: 2011-05-18 19:45:55 Subject: [PATCH] Fixing small bug in display logic. * png data was not being encoded (base64) whenn the display function was used. --- diff --git a/IPython/zmq/session.py b/IPython/zmq/session.py index 0fcb194..afb9907 100644 --- a/IPython/zmq/session.py +++ b/IPython/zmq/session.py @@ -123,7 +123,7 @@ class Session(object): socket.send(ident, zmq.SNDMORE) socket.send_json(msg) return msg - + def recv(self, socket, mode=zmq.NOBLOCK): """recv a message on a socket. diff --git a/IPython/zmq/zmqshell.py b/IPython/zmq/zmqshell.py index 8dea867..6e5732c 100644 --- a/IPython/zmq/zmqshell.py +++ b/IPython/zmq/zmqshell.py @@ -48,6 +48,12 @@ install_payload_page() # Functions and classes #----------------------------------------------------------------------------- +def _encode_png(data): + pngdata = data.get('image/png') + if pngdata is not None: + data['image/png'] = encodestring(pngdata) + + class ZMQDisplayHook(DisplayHook): """A displayhook subclass that publishes data using ZeroMQ.""" @@ -69,8 +75,7 @@ class ZMQDisplayHook(DisplayHook): def write_format_data(self, format_dict): pngdata = format_dict.get('image/png') - if pngdata is not None: - format_dict['image/png'] = encodestring(pngdata) + _encode_png(format_dict) self.msg['content']['data'] = format_dict def finish_displayhook(self): @@ -96,6 +101,7 @@ class ZMQDisplayPublisher(DisplayPublisher): self._validate_data(source, data, metadata) content = {} content['source'] = source + _encode_png(data) content['data'] = data content['metadata'] = metadata self.session.send(