From 3a7e4325dd3061af9b20f5c09ac709cb7bd92b2a Mon Sep 17 00:00:00 2001 From: MinRK Date: Thu, 26 Jul 2012 13:31:51 -0700 Subject: [PATCH] add data_pub messages for publishing raw data, rather than reprs (zmq-only) --- IPython/core/interactiveshell.py | 9 +++++++++ IPython/zmq/ipkernel.py | 4 ++++ IPython/zmq/zmqshell.py | 2 ++ 3 files changed, 15 insertions(+) diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 4a24fe3421b..d0d479638c8 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -270,6 +270,7 @@ class InteractiveShell(SingletonConfigurable): display_formatter = Instance(DisplayFormatter) displayhook_class = Type(DisplayHook) display_pub_class = Type(DisplayPublisher) + data_pub_class = None exit_now = CBool(False) exiter = Instance(ExitAutocall) @@ -483,6 +484,7 @@ def __init__(self, config=None, ipython_dir=None, profile_dir=None, self.init_prompts() self.init_display_formatter() self.init_display_pub() + self.init_data_pub() self.init_displayhook() self.init_reload_doctest() self.init_latextool() @@ -659,6 +661,13 @@ def init_display_pub(self): self.display_pub = self.display_pub_class(config=self.config) self.configurables.append(self.display_pub) + def init_data_pub(self): + if not self.data_pub_class: + self.data_pub = None + return + self.data_pub = self.data_pub_class(config=self.config) + self.configurables.append(self.data_pub) + def init_displayhook(self): # Initialize displayhook, set in/out prompts and printing system self.displayhook = self.displayhook_class( diff --git a/IPython/zmq/ipkernel.py b/IPython/zmq/ipkernel.py index 2f756ffb7b3..9b7309e254e 100755 --- a/IPython/zmq/ipkernel.py +++ b/IPython/zmq/ipkernel.py @@ -147,6 +147,8 @@ def __init__(self, **kwargs): self.shell.displayhook.topic = self._topic('pyout') self.shell.display_pub.session = self.session self.shell.display_pub.pub_socket = self.iopub_socket + self.shell.data_pub.session = self.session + self.shell.data_pub.pub_socket = self.iopub_socket # TMP - hack while developing self.shell._reply_content = None @@ -353,6 +355,7 @@ def execute_request(self, stream, ident, parent): # Set the parent message of the display hook and out streams. shell.displayhook.set_parent(parent) shell.display_pub.set_parent(parent) + shell.data_pub.set_parent(parent) sys.stdout.set_parent(parent) sys.stderr.set_parent(parent) @@ -538,6 +541,7 @@ def apply_request(self, stream, ident, parent): shell = self.shell shell.displayhook.set_parent(parent) shell.display_pub.set_parent(parent) + shell.data_pub.set_parent(parent) sys.stdout.set_parent(parent) sys.stderr.set_parent(parent) diff --git a/IPython/zmq/zmqshell.py b/IPython/zmq/zmqshell.py index 0691ef65de1..48675b86b86 100644 --- a/IPython/zmq/zmqshell.py +++ b/IPython/zmq/zmqshell.py @@ -44,6 +44,7 @@ from IPython.utils.traitlets import Instance, Type, Dict, CBool, CBytes from IPython.utils.warn import warn, error from IPython.zmq.displayhook import ZMQShellDisplayHook +from IPython.zmq.datapub import ZMQDataPublisher from IPython.zmq.session import extract_header from session import Session @@ -464,6 +465,7 @@ class ZMQInteractiveShell(InteractiveShell): displayhook_class = Type(ZMQShellDisplayHook) display_pub_class = Type(ZMQDisplayPublisher) + data_pub_class = Type(ZMQDataPublisher) # Override the traitlet in the parent class, because there's no point using # readline for the kernel. Can be removed when the readline code is moved