From 702b527246987a7efc3d7e939d02c8b8111eccb1 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Wed, 5 Jul 2017 12:31:03 +0300 Subject: [PATCH] Fix(lib/python/init.py): Fix stdout for readline Restore stdout during raw_input(). Necessary because readline works only with bare stdout. This fixes code.interact(), django-admin shell and all that. --- lib/python/init.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/python/init.py b/lib/python/init.py index 19f0234..a38cea3 100644 --- a/lib/python/init.py +++ b/lib/python/init.py @@ -107,6 +107,22 @@ def init(): sys.stdout = ColoredFile(sys.stdout, '\033[1;3%sm' % stdout_color) sys.stderr = ColoredFile(sys.stderr, '\033[31m') # red + def myinput(prompt=None): + save_stdout = sys.stdout + sys.stdout = sys.__stdout__ + result = builtin_input(prompt) + sys.stdout = save_stdout + return result + + try: + builtins.raw_input + except AttributeError: # PY3 + builtin_input = builtins.input + builtins.input = myinput + else: + builtin_input = builtins.raw_input + builtins.raw_input = myinput + break try: -- 2.39.5