Permalink
Browse files

Implement payloads in embedded kernel.

  • Loading branch information...
1 parent 8e22797 commit 50592c30c12cf79ab493722a2467cc3a8a2b05bd @epatters committed Sep 6, 2012
Showing with 42 additions and 2 deletions.
  1. +40 −0 IPython/embedded/ipkernel.py
  2. +1 −0 IPython/embedded/kernelmagics.py
  3. +1 −1 IPython/embedded/kernelmanager.py
  4. +0 −1 IPython/zmq/zmqshell.py
@@ -26,6 +26,7 @@
from IPython.core.displayhook import DisplayHook
from IPython.core.error import StdinNotImplementedError
from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC
+from IPython.core.payloadpage import install_payload_page
from IPython.utils.jsonutil import encode_images, json_clean
from IPython.utils import py3compat
from IPython.utils.text import safe_unicode
@@ -336,6 +337,9 @@ def __init__(self, kernel, *args, **kwds):
# InteractiveShell interface
#---------------------------------------------------------------------------
+ def init_environment(self):
+ install_payload_page()
+
def init_magics(self):
super(EmbeddedInteractiveShell, self).init_magics()
self.register_magics(KernelMagics)
@@ -346,6 +350,42 @@ def init_sys_modules(self):
pass
#---------------------------------------------------------------------------
+ # ZMQInteractiveShell payloads
+ #---------------------------------------------------------------------------
+
+ # FIXME: We are basically a ZMQInteractiveShell look-a-like, but do we still
+ # want to use its payload IDs? This is a bit smelly.
+
+ def ask_exit(self):
+ """ Engage the exit actions.
+ """
+ self.exit_now = True
+ payload = dict(
+ source = 'IPython.zmq.zmqshell.ZMQInteractiveShell.ask_exit',
+ exit = True,
+ keepkernel = False)
+ self.payload_manager.write_payload(payload)
+
+ def auto_rewrite_input(self, cmd):
+ """ Called to show the auto-rewritten input for autocall and friends.
+ """
+ new = self.prompt_manager.render('rewrite') + cmd
+ payload = dict(
+ source = 'IPython.zmq.zmqshell.ZMQInteractiveShell.'
+ 'auto_rewrite_input',
+ transformed_input = new)
+ self.payload_manager.write_payload(payload)
+
+ def set_next_input(self, text):
+ """ Send the specified text to the frontend to be presented at the next
+ input cell.
+ """
+ payload = dict(
+ source = 'IPython.zmq.zmqshell.ZMQInteractiveShell.set_next_input',
+ text = text)
+ self.payload_manager.write_payload(payload)
+
+ #---------------------------------------------------------------------------
# Protected interface
#---------------------------------------------------------------------------
@@ -16,6 +16,7 @@
# Local imports
from IPython.core.magic import magics_class, line_magic, Magics
from IPython.core.magics import MacroToEdit, CodeMagics
+from IPython.core import page
from IPython.testing.skipdoctest import skip_doctest
from IPython.utils import openpy
@@ -381,7 +381,7 @@ def has_kernel(self):
def kill_kernel(self):
""" Kill the running kernel.
"""
- self.kernel.frontends.pop(self)
+ self.kernel.frontends.remove(self)
self.kernel = None
def interrupt_kernel(self):
View
@@ -25,7 +25,6 @@
# Our own
from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC
-from IPython.core import page
from IPython.core.autocall import ZMQExitAutocall
from IPython.core.displaypub import DisplayPublisher
from IPython.core.error import UsageError

0 comments on commit 50592c3

Please sign in to comment.