##// END OF EJS Templates
disable install from master...
disable install from master while it's broken by The Big Split with informative note about `pip install -e`

File last commit:

r20957:16fd1e32
r21036:5b38bd7e
Show More
displayhook.py
73 lines | 2.4 KiB | text/x-python | PythonLexer
MinRK
pyout -> execute_result...
r16568 """Replacements for sys.displayhook that publish over ZMQ."""
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
MinRK
flush stdout/stderr on displayhook...
r4792 import sys
Brian Granger
Separating kernel into smaller pieces.
r2754
Thomas Kluyver
Move displayhook for ZMQ shell to zmq.displayhook, and rename to make the difference clearer.
r4067 from IPython.core.displayhook import DisplayHook
Min RK
bigsplit: ipython_kernel
r20955 from ipython_kernel.inprocess.socket import SocketABC
MinRK
move _encode_binary to jsonutil.encode_images...
r7737 from IPython.utils.jsonutil import encode_images
Thomas Kluyver
Fix imports of builtins module
r13351 from IPython.utils.py3compat import builtin_mod
epatters
Add abstract base class (ABC) for sockets used in kernel.
r8418 from IPython.utils.traitlets import Instance, Dict
Thomas Kluyver
Use explicit relative imports...
r13347 from .session import extract_header, Session
Brian Granger
Separating kernel into smaller pieces.
r2754
Thomas Kluyver
Move displayhook for ZMQ shell to zmq.displayhook, and rename to make the difference clearer.
r4067 class ZMQDisplayHook(object):
"""A simple displayhook that publishes the object's repr over a ZeroMQ
socket."""
MinRK
pyout -> execute_result...
r16568 topic=b'execute_result'
MinRK
propagate iopub to clients
r3602
Brian Granger
Separating kernel into smaller pieces.
r2754 def __init__(self, session, pub_socket):
self.session = session
self.pub_socket = pub_socket
self.parent_header = {}
def __call__(self, obj):
if obj is None:
return
Thomas Kluyver
Fix imports of builtins module
r13351 builtin_mod._ = obj
MinRK
flush stdout/stderr on displayhook...
r4792 sys.stdout.flush()
sys.stderr.flush()
MinRK
pyout -> execute_result...
r16568 msg = self.session.send(self.pub_socket, u'execute_result', {u'data':repr(obj)},
MinRK
propagate iopub to clients
r3602 parent=self.parent_header, ident=self.topic)
Brian Granger
Separating kernel into smaller pieces.
r2754
def set_parent(self, parent):
Thomas Kluyver
Move displayhook for ZMQ shell to zmq.displayhook, and rename to make the difference clearer.
r4067 self.parent_header = extract_header(parent)
class ZMQShellDisplayHook(DisplayHook):
"""A displayhook subclass that publishes data using ZeroMQ. This is intended
to work with an InteractiveShell instance. It sends a dict of different
representations of the object."""
MinRK
fix topic on displayhook in ZMQShell
r6814 topic=None
Thomas Kluyver
Move displayhook for ZMQ shell to zmq.displayhook, and rename to make the difference clearer.
r4067
Sylvain Corlay
allow_none=False by default for Type and Instance
r20940 session = Instance(Session, allow_none=True)
pub_socket = Instance(SocketABC, allow_none=True)
Thomas Kluyver
Move displayhook for ZMQ shell to zmq.displayhook, and rename to make the difference clearer.
r4067 parent_header = Dict({})
def set_parent(self, parent):
"""Set the parent for outbound messages."""
self.parent_header = extract_header(parent)
def start_displayhook(self):
Min RK
ensure data, metadata are set in execute_results...
r19802 self.msg = self.session.msg(u'execute_result', {
'data': {},
'metadata': {},
}, parent=self.parent_header)
Thomas Kluyver
Move displayhook for ZMQ shell to zmq.displayhook, and rename to make the difference clearer.
r4067
def write_output_prompt(self):
"""Write the output prompt."""
MinRK
prompt_count should be unconditional in pyout messages
r6693 self.msg['content']['execution_count'] = self.prompt_count
Thomas Kluyver
Move displayhook for ZMQ shell to zmq.displayhook, and rename to make the difference clearer.
r4067
MinRK
allow formatters to publish metadata...
r10443 def write_format_data(self, format_dict, md_dict=None):
MinRK
move _encode_binary to jsonutil.encode_images...
r7737 self.msg['content']['data'] = encode_images(format_dict)
MinRK
allow formatters to publish metadata...
r10443 self.msg['content']['metadata'] = md_dict
Thomas Kluyver
Move displayhook for ZMQ shell to zmq.displayhook, and rename to make the difference clearer.
r4067
def finish_displayhook(self):
"""Finish up all displayhook activities."""
MinRK
flush stdout/stderr on displayhook...
r4792 sys.stdout.flush()
sys.stderr.flush()
Min RK
don't send empty execute_result messages...
r20110 if self.msg['content']['data']:
self.session.send(self.pub_socket, self.msg, ident=self.topic)
Thomas Kluyver
Move displayhook for ZMQ shell to zmq.displayhook, and rename to make the difference clearer.
r4067 self.msg = None