##// END OF EJS Templates
Generate "All magics..." menu live...
Generate "All magics..." menu live this use 'user_expression' request to ask for the value of 'get_ipython().lsmagic()' and populate the menu with the result. As is, the action need to be triggerd by hand, once the console have appear. Otherwith there is no prompt The logic can certainly also be shortend by using msg.id instead of uuid We should also keep a list of magic that shouldn't be executed without argument (eg: %gui) and don't put them in the menu. or appending '?' at the end

File last commit:

r4783:6392cebc
r5392:5881216f
Show More
iostream.py
91 lines | 2.9 KiB | text/x-python | PythonLexer
Brian Granger
Separating kernel into smaller pieces.
r2754 import sys
import time
Thomas Kluyver
Handle unicode properly in IPython.zmq.iostream
r4070 from io import StringIO
Brian Granger
Separating kernel into smaller pieces.
r2754
from session import extract_header, Message
MinRK
add text.getdefaultencoding() for central default encoding guess...
r4783 from IPython.utils import io, text
Fernando Perez
Add missing flush of output streams on execute
r2938
Brian Granger
Separating kernel into smaller pieces.
r2754 #-----------------------------------------------------------------------------
Fernando Perez
Merge branch 'kernel-logging' of https://github.com/omazapa/ipython into omazapa-kernel-logging...
r3322 # Globals
Brian Granger
Separating kernel into smaller pieces.
r2754 #-----------------------------------------------------------------------------
Fernando Perez
Merge branch 'kernel-logging' of https://github.com/omazapa/ipython into omazapa-kernel-logging...
r3322
#-----------------------------------------------------------------------------
Brian Granger
Separating kernel into smaller pieces.
r2754 # Stream classes
#-----------------------------------------------------------------------------
class OutStream(object):
"""A file like object that publishes the stream to a 0MQ PUB socket."""
# The time interval between automatic flushes, in seconds.
flush_interval = 0.05
MinRK
propagate iopub to clients
r3602 topic=None
Brian Granger
Separating kernel into smaller pieces.
r2754 def __init__(self, session, pub_socket, name):
self.session = session
self.pub_socket = pub_socket
self.name = name
self.parent_header = {}
self._new_buffer()
def set_parent(self, parent):
self.parent_header = extract_header(parent)
def close(self):
self.pub_socket = None
def flush(self):
Fernando Perez
Add missing flush of output streams on execute
r2938 #io.rprint('>>>flushing output buffer: %s<<<' % self.name) # dbg
Brian Granger
Separating kernel into smaller pieces.
r2754 if self.pub_socket is None:
raise ValueError(u'I/O operation on closed file')
else:
data = self._buffer.getvalue()
if data:
content = {u'name':self.name, u'data':data}
MinRK
propagate iopub to clients
r3602 msg = self.session.send(self.pub_socket, u'stream', content=content,
parent=self.parent_header, ident=self.topic)
MinRK
flush pub_socket in OutStream.flush...
r4476 if hasattr(self.pub_socket, 'flush'):
# socket itself has flush (presumably ZMQStream)
self.pub_socket.flush()
Brian Granger
Separating kernel into smaller pieces.
r2754 self._buffer.close()
self._new_buffer()
def isatty(self):
return False
def next(self):
raise IOError('Read not supported on a write only stream.')
def read(self, size=-1):
raise IOError('Read not supported on a write only stream.')
def readline(self, size=-1):
raise IOError('Read not supported on a write only stream.')
def write(self, string):
if self.pub_socket is None:
raise ValueError('I/O operation on closed file')
else:
Thomas Kluyver
Handle unicode properly in IPython.zmq.iostream
r4070 # Make sure that we're handling unicode
if not isinstance(string, unicode):
MinRK
add text.getdefaultencoding() for central default encoding guess...
r4783 enc = text.getdefaultencoding()
Thomas Kluyver
Handle unicode properly in IPython.zmq.iostream
r4070 string = string.decode(enc, 'replace')
Brian Granger
Separating kernel into smaller pieces.
r2754 self._buffer.write(string)
current_time = time.time()
if self._start <= 0:
self._start = current_time
elif current_time - self._start > self.flush_interval:
self.flush()
def writelines(self, sequence):
if self.pub_socket is None:
raise ValueError('I/O operation on closed file')
else:
for string in sequence:
self.write(string)
def _new_buffer(self):
self._buffer = StringIO()
Fernando Perez
Add missing flush of output streams on execute
r2938 self._start = -1