Show More
@@ -41,9 +41,9 b' class EngineFactory(RegistrationFactory):' | |||
|
41 | 41 | out_stream_factory=Type('IPython.zmq.iostream.OutStream', config=True, |
|
42 | 42 | help="""The OutStream for handling stdout/err. |
|
43 | 43 | Typically 'IPython.zmq.iostream.OutStream'""") |
|
44 | display_hook_factory=Type('IPython.zmq.displayhook.DisplayHook', config=True, | |
|
44 | display_hook_factory=Type('IPython.zmq.displayhook.ZMQDisplayHook', config=True, | |
|
45 | 45 | help="""The class for handling displayhook. |
|
46 | Typically 'IPython.zmq.displayhook.DisplayHook'""") | |
|
46 | Typically 'IPython.zmq.displayhook.ZMQDisplayHook'""") | |
|
47 | 47 | location=Unicode(config=True, |
|
48 | 48 | help="""The location (an IP address) of the controller. This is |
|
49 | 49 | used for disambiguating URLs, to determine whether |
@@ -1,9 +1,13 b'' | |||
|
1 | 1 | import __builtin__ |
|
2 | from base64 import encodestring | |
|
2 | 3 | |
|
3 | from session import extract_header | |
|
4 | ||
|
5 | class DisplayHook(object): | |
|
4 | from IPython.core.displayhook import DisplayHook | |
|
5 | from IPython.utils.traitlets import Instance, Dict | |
|
6 | from session import extract_header, Session | |
|
6 | 7 | |
|
8 | class ZMQDisplayHook(object): | |
|
9 | """A simple displayhook that publishes the object's repr over a ZeroMQ | |
|
10 | socket.""" | |
|
7 | 11 | topic=None |
|
8 | 12 | |
|
9 | 13 | def __init__(self, session, pub_socket): |
@@ -20,4 +24,41 b' class DisplayHook(object):' | |||
|
20 | 24 | parent=self.parent_header, ident=self.topic) |
|
21 | 25 | |
|
22 | 26 | def set_parent(self, parent): |
|
23 | self.parent_header = extract_header(parent) No newline at end of file | |
|
27 | self.parent_header = extract_header(parent) | |
|
28 | ||
|
29 | ||
|
30 | def _encode_png(data): | |
|
31 | pngdata = data.get('image/png') | |
|
32 | if pngdata is not None: | |
|
33 | data['image/png'] = encodestring(pngdata) | |
|
34 | ||
|
35 | class ZMQShellDisplayHook(DisplayHook): | |
|
36 | """A displayhook subclass that publishes data using ZeroMQ. This is intended | |
|
37 | to work with an InteractiveShell instance. It sends a dict of different | |
|
38 | representations of the object.""" | |
|
39 | ||
|
40 | session = Instance(Session) | |
|
41 | pub_socket = Instance('zmq.Socket') | |
|
42 | parent_header = Dict({}) | |
|
43 | ||
|
44 | def set_parent(self, parent): | |
|
45 | """Set the parent for outbound messages.""" | |
|
46 | self.parent_header = extract_header(parent) | |
|
47 | ||
|
48 | def start_displayhook(self): | |
|
49 | self.msg = self.session.msg(u'pyout', {}, parent=self.parent_header) | |
|
50 | ||
|
51 | def write_output_prompt(self): | |
|
52 | """Write the output prompt.""" | |
|
53 | if self.do_full_cache: | |
|
54 | self.msg['content']['execution_count'] = self.prompt_count | |
|
55 | ||
|
56 | def write_format_data(self, format_dict): | |
|
57 | pngdata = format_dict.get('image/png') | |
|
58 | _encode_png(format_dict) | |
|
59 | self.msg['content']['data'] = format_dict | |
|
60 | ||
|
61 | def finish_displayhook(self): | |
|
62 | """Finish up all displayhook activities.""" | |
|
63 | self.session.send(self.pub_socket, self.msg) | |
|
64 | self.msg = None |
@@ -13,7 +13,6 b' import sys' | |||
|
13 | 13 | from parentpoller import ParentPollerWindows |
|
14 | 14 | |
|
15 | 15 | |
|
16 | ||
|
17 | 16 | def base_launch_kernel(code, shell_port=0, iopub_port=0, stdin_port=0, hb_port=0, |
|
18 | 17 | ip=None, stdin=None, stdout=None, stderr=None, |
|
19 | 18 | executable=None, independent=False, extra_arguments=[]): |
@@ -16,7 +16,6 b' machinery. This should thus be thought of as scaffolding.' | |||
|
16 | 16 | from __future__ import print_function |
|
17 | 17 | |
|
18 | 18 | # Stdlib |
|
19 | from base64 import encodestring | |
|
20 | 19 | import inspect |
|
21 | 20 | import os |
|
22 | 21 | |
@@ -26,7 +25,6 b' from IPython.core.interactiveshell import (' | |||
|
26 | 25 | ) |
|
27 | 26 | from IPython.core import page |
|
28 | 27 | from IPython.core.autocall import ZMQExitAutocall |
|
29 | from IPython.core.displayhook import DisplayHook | |
|
30 | 28 | from IPython.core.displaypub import DisplayPublisher |
|
31 | 29 | from IPython.core.macro import Macro |
|
32 | 30 | from IPython.core.magic import MacroToEdit |
@@ -35,6 +33,7 b' from IPython.utils import io' | |||
|
35 | 33 | from IPython.utils.path import get_py_filename |
|
36 | 34 | from IPython.utils.traitlets import Instance, Type, Dict |
|
37 | 35 | from IPython.utils.warn import warn |
|
36 | from IPython.zmq.displayhook import ZMQShellDisplayHook | |
|
38 | 37 | from IPython.zmq.session import extract_header |
|
39 | 38 | from session import Session |
|
40 | 39 | |
@@ -49,42 +48,6 b' install_payload_page()' | |||
|
49 | 48 | # Functions and classes |
|
50 | 49 | #----------------------------------------------------------------------------- |
|
51 | 50 | |
|
52 | def _encode_png(data): | |
|
53 | pngdata = data.get('image/png') | |
|
54 | if pngdata is not None: | |
|
55 | data['image/png'] = encodestring(pngdata) | |
|
56 | ||
|
57 | ||
|
58 | class ZMQDisplayHook(DisplayHook): | |
|
59 | """A displayhook subclass that publishes data using ZeroMQ.""" | |
|
60 | ||
|
61 | session = Instance(Session) | |
|
62 | pub_socket = Instance('zmq.Socket') | |
|
63 | parent_header = Dict({}) | |
|
64 | ||
|
65 | def set_parent(self, parent): | |
|
66 | """Set the parent for outbound messages.""" | |
|
67 | self.parent_header = extract_header(parent) | |
|
68 | ||
|
69 | def start_displayhook(self): | |
|
70 | self.msg = self.session.msg(u'pyout', {}, parent=self.parent_header) | |
|
71 | ||
|
72 | def write_output_prompt(self): | |
|
73 | """Write the output prompt.""" | |
|
74 | if self.do_full_cache: | |
|
75 | self.msg['content']['execution_count'] = self.prompt_count | |
|
76 | ||
|
77 | def write_format_data(self, format_dict): | |
|
78 | pngdata = format_dict.get('image/png') | |
|
79 | _encode_png(format_dict) | |
|
80 | self.msg['content']['data'] = format_dict | |
|
81 | ||
|
82 | def finish_displayhook(self): | |
|
83 | """Finish up all displayhook activities.""" | |
|
84 | self.session.send(self.pub_socket, self.msg) | |
|
85 | self.msg = None | |
|
86 | ||
|
87 | ||
|
88 | 51 | class ZMQDisplayPublisher(DisplayPublisher): |
|
89 | 52 | """A display publisher that publishes data using a ZeroMQ PUB socket.""" |
|
90 | 53 | |
@@ -114,7 +77,7 b' class ZMQDisplayPublisher(DisplayPublisher):' | |||
|
114 | 77 | class ZMQInteractiveShell(InteractiveShell): |
|
115 | 78 | """A subclass of InteractiveShell for ZMQ.""" |
|
116 | 79 | |
|
117 | displayhook_class = Type(ZMQDisplayHook) | |
|
80 | displayhook_class = Type(ZMQShellDisplayHook) | |
|
118 | 81 | display_pub_class = Type(ZMQDisplayPublisher) |
|
119 | 82 | |
|
120 | 83 | exiter = Instance(ZMQExitAutocall) |
General Comments 0
You need to be logged in to leave comments.
Login now