From d8f3d170be002b23d41a8887197cffe5977c4af8 2011-08-22 20:56:01 From: Thomas Kluyver Date: 2011-08-22 20:56:01 Subject: [PATCH] Defer saving raw_input to shell initialisation, so that we pick up the modified version needed for PyPy's readline to work. --- diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 5218375..f61b348 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -86,10 +86,6 @@ dedent_re = re.compile(r'^\s+raise|^\s+return|^\s+pass') # Utilities #----------------------------------------------------------------------------- -# store the builtin raw_input globally, and use this always, in case user code -# overwrites it (like wx.py.PyShell does) -raw_input_original = raw_input - def softspace(file, newvalue): """Copied from code.py, to remove the dependency""" @@ -411,6 +407,10 @@ class InteractiveShell(SingletonConfigurable, Magic): # init_readline() must come before init_io(), because init_io uses # readline related things. self.init_readline() + # We save this here in case user code replaces raw_input, but it needs + # to be after init_readline(), because PyPy's readline works by replacing + # raw_input. + self.raw_input_original = raw_input # init_completer must come after init_readline, because it needs to # know whether readline is present or not system-wide to configure the # completers, since the completion machinery can now operate diff --git a/IPython/core/magic.py b/IPython/core/magic.py index e58bd4e..4193bbb 100644 --- a/IPython/core/magic.py +++ b/IPython/core/magic.py @@ -3175,7 +3175,7 @@ Defaulting color scheme to 'NoColor'""" from IPython.core import interactiveshell print "Pasting code; enter '%s' alone on the line to stop." % sentinel while True: - l = interactiveshell.raw_input_original(':') + l = self.shell.raw_input_original(':') if l == sentinel: return else: diff --git a/IPython/frontend/terminal/interactiveshell.py b/IPython/frontend/terminal/interactiveshell.py index e78f89e..253f3e4 100644 --- a/IPython/frontend/terminal/interactiveshell.py +++ b/IPython/frontend/terminal/interactiveshell.py @@ -47,11 +47,6 @@ def get_default_editor(): ed = 'notepad' # same in Windows! return ed - -# store the builtin raw_input globally, and use this always, in case user code -# overwrites it (like wx.py.PyShell does) -raw_input_original = raw_input - #----------------------------------------------------------------------------- # Main class #----------------------------------------------------------------------------- @@ -337,7 +332,7 @@ class TerminalInteractiveShell(InteractiveShell): self.set_readline_completer() try: - line = raw_input_original(prompt).decode(self.stdin_encoding) + line = self.raw_input_original(prompt).decode(self.stdin_encoding) except ValueError: warn("\n********\nYou or a %run:ed script called sys.stdin.close()" " or sys.stdout.close()!\nExiting IPython!")