[accerciser] Fix for bug #671179 - Unexpected behaviours in ipython_view
- From: Javier HernÃndez AntÃnez <jhernandez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [accerciser] Fix for bug #671179 - Unexpected behaviours in ipython_view
- Date: Sat, 26 May 2012 20:25:08 +0000 (UTC)
commit 3835bdb79deccdc5dab94a8dcb3df0952e599a9c
Author: Brian Parma <execrable gmail com>
Date: Sat May 26 22:22:34 2012 +0200
Fix for bug #671179 - Unexpected behaviours in ipython_view
plugins/ipython_view.py | 35 +++++++++++++++++++++++++----------
1 files changed, 25 insertions(+), 10 deletions(-)
---
diff --git a/plugins/ipython_view.py b/plugins/ipython_view.py
index 95deed3..df8df60 100755
--- a/plugins/ipython_view.py
+++ b/plugins/ipython_view.py
@@ -67,21 +67,21 @@ class IterableIPShell:
@param input_func: Replacement for builtin raw_input()
@type input_func: function
'''
+ io = IPython.utils.io
if input_func:
IPython.frontend.terminal.interactiveshell.raw_input_original = input_func
if cin:
- IPython.utils.io.stdin = IPython.utils.io.IOStream(cin)
+ io.stdin = io.IOStream(cin)
if cout:
- IPython.utils.io.stdout = IPython.utils.io.IOStream(cout)
+ io.stdout = io.IOStream(cout)
if cerr:
- IPython.utils.io.stderr = IPython.utils.io.IOStream(cerr)
+ io.stderr = io.IOStream(cerr)
# This is to get rid of the blockage that accurs during
# IPython.Shell.InteractiveShell.user_setup()
- IPython.utils.io.raw_input = lambda x: None
+ io.raw_input = lambda x: None
- self.term = IPython.utils.io.IOTerm(stdin=cin, stdout=cout, stderr=cerr)
os.environ['TERM'] = 'dumb'
excepthook = sys.excepthook
@@ -89,10 +89,22 @@ class IterableIPShell:
cfg = Config()
cfg.InteractiveShell.colors = "Linux"
- self.IP = IPython.frontend.terminal.embed.InteractiveShellEmbed(config=cfg, user_ns=user_ns)
+ # InteractiveShell's __init__ overwrites io.stdout,io.stderr with
+ # sys.stdout, sys.stderr, this makes sure they are right
+ #
+ old_stdout, old_stderr = sys.stdout, sys.stderr
+ sys.stdout, sys.stderr = io.stdout.stream, io.stderr.stream
+
+ # InteractiveShell inherits from SingletonConfigurable, so use instance()
+ #
+ self.IP = IPython.frontend.terminal.embed.InteractiveShellEmbed.instance(\
+ config=cfg, user_ns=user_ns)
+
+ sys.stdout, sys.stderr = old_stdout, old_stderr
+
self.IP.system = lambda cmd: self.shell(self.IP.var_expand(cmd),
- header='IPython system call: ',
- local_ns=user_ns)
+ header='IPython system call: ')
+# local_ns=user_ns)
#global_ns=user_global_ns)
#verbose=self.IP.rc.system_verbose)
@@ -122,8 +134,11 @@ class IterableIPShell:
'''
self.history_level = 0
+ # this is needed because some functions in IPython use 'print' to print
+ # output (like 'who')
+ #
orig_stdout = sys.stdout
- sys.stdout = self.term.stdout
+ sys.stdout = IPython.utils.io.stdout
orig_stdin = sys.stdin
sys.stdin = IPython.utils.io.stdin;
@@ -514,11 +529,11 @@ class IPythonView(ConsoleView, IterableIPShell):
IterableIPShell.__init__(self, cout=self.cout,cerr=self.cout,
input_func=self.raw_input)
# self.connect('key_press_event', self.keyPress)
+ self.interrupt = False
self.execute()
self.prompt = self.generatePrompt(False)
self.cout.truncate(0)
self.showPrompt(self.prompt)
- self.interrupt = False
def raw_input(self, prompt=''):
'''
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]