From 181027dda58ea2de51d8947bfceda50807334c1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Wed, 26 Jun 2019 00:00:18 +0200 Subject: [PATCH] IPython: Simplify stream code --- gajim/dev/ipython_view.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/gajim/dev/ipython_view.py b/gajim/dev/ipython_view.py index 86348cc2b..fad1c873a 100644 --- a/gajim/dev/ipython_view.py +++ b/gajim/dev/ipython_view.py @@ -141,12 +141,6 @@ def __init__(self, argv=None, user_ns=None, user_global_ns=None, cin=None, else: IPython.frontend.terminal.interactiveshell.raw_input_original = \ input_func - if cin: - io.stdin = io.IOStream(cin) - if cout: - io.stdout = io.IOStream(cout) - if cerr: - io.stderr = io.IOStream(cerr) # This is to get rid of the blockage that accurs during # IPython.Shell.InteractiveShell.user_setup() @@ -163,10 +157,10 @@ def __init__(self, argv=None, user_ns=None, user_global_ns=None, cin=None, cfg = Config() cfg.InteractiveShell.colors = "Linux" - # InteractiveShell's __init__ overwrites io.stdout,io.stderr with - # sys.stdout, sys.stderr, this makes sure they are right + # InteractiveShell's __init__ gets a reference of stdout and stderr + # so we save the standard here to revert it after init old_stdout, old_stderr = sys.stdout, sys.stderr - sys.stdout, sys.stderr = io.stdout.stream, io.stderr.stream + sys.stdout, sys.stderr = cout, cerr # InteractiveShell inherits from SingletonConfigurable so use instance() if parse_version(IPython.release.version) >= parse_version("1.2.1"): @@ -177,6 +171,7 @@ def __init__(self, argv=None, user_ns=None, user_global_ns=None, cin=None, IPython.frontend.terminal.embed.InteractiveShellEmbed.instance( config=cfg, user_ns=user_ns) + # Set back stdout and stderr to what it was before sys.stdout, sys.stderr = old_stdout, old_stderr self.IP.system = lambda cmd: self.shell(self.IP.var_expand(cmd), -- GitLab