##// END OF EJS Templates
Merge pull request #3756 from minrk/wiredoc...
Merge pull request #3756 from minrk/wiredoc document the wire protocol in the messaging doc also update the digest scheme to use sha256 and make this configurable, since md5 is the previous default and has been shown to be bad. More messaging docs to update here: - [x] remove get/setattr on kernel - [x] remove crash messages - [x] completion requests do not behave as documented - [x] object_info is misdocumented (`name` is actually `oname` in object_info_request)

File last commit:

r9375:4d245182
r11721:42034aaf merge
Show More
datapub.py
70 lines | 2.3 KiB | text/x-python | PythonLexer
MinRK
add IPython.zmq.datapub
r8107 """Publishing
"""
#-----------------------------------------------------------------------------
# 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
MinRK
move IPython.inprocess to IPython.kernel.inprocess
r9375 from IPython.kernel.inprocess.socket import SocketABC
MinRK
add IPython.zmq.datapub
r8107 from IPython.utils.jsonutil import json_clean
epatters
Add abstract base class (ABC) for sockets used in kernel.
r8418 from IPython.utils.traitlets import Instance, Dict, CBytes
MinRK
mv IPython.zmq to IPython.kernel.zmq
r9372 from IPython.kernel.zmq.serialize import serialize_object
from IPython.kernel.zmq.session import Session, extract_header
MinRK
add IPython.zmq.datapub
r8107
#-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------
class ZMQDataPublisher(Configurable):
topic = topic = CBytes(b'datapub')
session = Instance(Session)
epatters
Add abstract base class (ABC) for sockets used in kernel.
r8418 pub_socket = Instance(SocketABC)
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)
def publish_data(self, data):
"""publish a data_message on the IOPub channel
Parameters
----------
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
Parameters
----------
data : dict
The data to be published. Think of it as a namespace.
"""
MinRK
mv IPython.zmq to IPython.kernel.zmq
r9372 from IPython.kernel.zmq.zmqshell import ZMQInteractiveShell
MinRK
add IPython.zmq.datapub
r8107 ZMQInteractiveShell.instance().data_pub.publish_data(data)