From 8883255cd0dcbe160b22773f9c6333fad7864276 Mon Sep 17 00:00:00 2001 From: wuub Date: Fri, 9 Aug 2013 11:23:20 +0200 Subject: [PATCH] IPython 1.0.0 autocomplete compatibility --- config/Python/ipy_repl.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/config/Python/ipy_repl.py b/config/Python/ipy_repl.py index c6ccf9e6..872ebec5 100644 --- a/config/Python/ipy_repl.py +++ b/config/Python/ipy_repl.py @@ -34,8 +34,19 @@ cfg.InteractiveShell.colors = "NoColor" cfg.InteractiveShell.editor = os.environ.get("SUBLIMEREPL_EDITOR", editor) +try: + # IPython 1.0.0 + from IPython.terminal.console.app import ZMQTerminalIPythonApp + + def kernel_client(zmq_shell): + return zmq_shell.kernel_client +except ImportError: + # Older IPythons + from IPython.frontend.terminal.console.app import ZMQTerminalIPythonApp + + def kernel_client(zmq_shell): + return zmq_shell.kernel_manager -from IPython.frontend.terminal.console.app import ZMQTerminalIPythonApp embedded_shell = ZMQTerminalIPythonApp(config=cfg, user_ns={}) embedded_shell.initialize() @@ -71,14 +82,15 @@ def read_netstring(s): return msg -def send_netstring(s, msg): +def send_netstring(sock, msg): payload = b"".join([str(len(msg)).encode("ascii"), b':', msg.encode("utf-8"), b',']) - s.sendall(payload) + sock.sendall(payload) def complete(zmq_shell, req): - msg_id = zmq_shell.kernel_manager.shell_channel.complete(**req) - msg = zmq_shell.kernel_manager.shell_channel.get_msg(timeout=0.5) + kc = kernel_client(zmq_shell) + msg_id = kc.shell_channel.complete(**req) + msg = kc.shell_channel.get_msg(timeout=0.5) if msg['parent_header']['msg_id'] == msg_id: return msg["content"]["matches"] return []