##// END OF EJS Templates
remove use of utils.flatten...
remove use of utils.flatten use `list(chain.from_iterable))` which is equivalent

File last commit:

r21073:ff373955
r21171:40f50cd7
Show More
datapub.py
70 lines | 2.3 KiB | text/x-python | PythonLexer
Thomas Kluyver
Standardise some module docstring first lines
r13888 """Publishing native (typically pickled) objects.
MinRK
add IPython.zmq.datapub
r8107 """
#-----------------------------------------------------------------------------
# Copyright (C) 2012 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
from IPython.config import Configurable
Min RK
bigsplit: ipython_kernel
r20955 from ipython_kernel.inprocess.socket import SocketABC
Min RK
import jsonutil from jupyter_client
r21073 from jupyter_client.jsonutil import json_clean
epatters
Add abstract base class (ABC) for sockets used in kernel.
r8418 from IPython.utils.traitlets import Instance, Dict, CBytes
Min RK
remove ipython_kernel.zmq sub-pkg
r20957 from ipython_kernel.serialize import serialize_object
from ipython_kernel.session import Session, extract_header
MinRK
add IPython.zmq.datapub
r8107
#-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------
class ZMQDataPublisher(Configurable):
topic = topic = CBytes(b'datapub')
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)
MinRK
add IPython.zmq.datapub
r8107 parent_header = Dict({})
def set_parent(self, parent):
"""Set the parent for outbound messages."""
self.parent_header = extract_header(parent)
Min RK
bigsplit: ipython_kernel
r20955
MinRK
add IPython.zmq.datapub
r8107 def publish_data(self, data):
"""publish a data_message on the IOPub channel
Min RK
bigsplit: ipython_kernel
r20955
MinRK
add IPython.zmq.datapub
r8107 Parameters
----------
Min RK
bigsplit: ipython_kernel
r20955
MinRK
add IPython.zmq.datapub
r8107 data : dict
The data to be published. Think of it as a namespace.
"""
session = self.session
buffers = serialize_object(data,
buffer_threshold=session.buffer_threshold,
item_threshold=session.item_threshold,
)
content = json_clean(dict(keys=data.keys()))
session.send(self.pub_socket, 'data_message', content=content,
parent=self.parent_header,
buffers=buffers,
ident=self.topic,
)
def publish_data(data):
"""publish a data_message on the IOPub channel
Min RK
bigsplit: ipython_kernel
r20955
MinRK
add IPython.zmq.datapub
r8107 Parameters
----------
Min RK
bigsplit: ipython_kernel
r20955
MinRK
add IPython.zmq.datapub
r8107 data : dict
The data to be published. Think of it as a namespace.
"""
Min RK
remove ipython_kernel.zmq sub-pkg
r20957 from ipython_kernel.zmqshell import ZMQInteractiveShell
MinRK
add IPython.zmq.datapub
r8107 ZMQInteractiveShell.instance().data_pub.publish_data(data)