##// END OF EJS Templates
Merge pull request #3162 from ivanov/output-stream-kwarg...
Merge pull request #3162 from ivanov/output-stream-kwarg adding stream kwarg to current.new_output This was missing, and made unnecessarily clunky to create output cells of stream type using the nbformat API. Before this commit, you had to do something like from IPython.nbformat import current as c output = c.new_output('stream', the_text) output['stream'] = 'stdout' after this commit from IPython.nbformat import current as c output = c.new_output('stream', the_text, stream='stdout') and actually, that stream= argument defaults to 'stdout' if it isn't given. I modified a test that will break if this functionality is ever removed.

File last commit:

r9375:4d245182
r10190:c3b429bd merge
Show More
socket.py
63 lines | 2.1 KiB | text/x-python | PythonLexer
epatters
Implement EmbeddedKernel.
r8411 """ Defines a dummy socket implementing (part of) the zmq.Socket interface. """
#-----------------------------------------------------------------------------
# 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
#-----------------------------------------------------------------------------
# Standard library imports.
epatters
Add abstract base class (ABC) for sockets used in kernel.
r8418 import abc
epatters
Implement EmbeddedKernel.
r8411 import Queue
# System library imports.
import zmq
# Local imports.
from IPython.utils.traitlets import HasTraits, Instance, Int
#-----------------------------------------------------------------------------
epatters
Add abstract base class (ABC) for sockets used in kernel.
r8418 # Generic socket interface
#-----------------------------------------------------------------------------
class SocketABC(object):
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def recv_multipart(self, flags=0, copy=True, track=False):
raise NotImplementedError
@abc.abstractmethod
def send_multipart(self, msg_parts, flags=0, copy=True, track=False):
raise NotImplementedError
SocketABC.register(zmq.Socket)
#-----------------------------------------------------------------------------
epatters
Implement EmbeddedKernel.
r8411 # Dummy socket class
#-----------------------------------------------------------------------------
class DummySocket(HasTraits):
""" A dummy socket implementing (part of) the zmq.Socket interface. """
queue = Instance(Queue.Queue, ())
message_sent = Int(0) # Should be an Event
#-------------------------------------------------------------------------
epatters
Add abstract base class (ABC) for sockets used in kernel.
r8418 # Socket interface
epatters
Implement EmbeddedKernel.
r8411 #-------------------------------------------------------------------------
def recv_multipart(self, flags=0, copy=True, track=False):
return self.queue.get_nowait()
def send_multipart(self, msg_parts, flags=0, copy=True, track=False):
msg_parts = map(zmq.Message, msg_parts)
self.queue.put_nowait(msg_parts)
self.message_sent += 1
epatters
Add abstract base class (ABC) for sockets used in kernel.
r8418
SocketABC.register(DummySocket)