Permalink
Browse files

Defer saving raw_input to shell initialisation, so that we pick up th…

…e modified version needed for PyPy's readline to work.
  • Loading branch information...
takluyver committed Aug 22, 2011
1 parent 4d5d46f commit d8f3d170be002b23d41a8887197cffe5977c4af8
Showing with 6 additions and 11 deletions.
  1. +4 −4 IPython/core/interactiveshell.py
  2. +1 −1 IPython/core/magic.py
  3. +1 −6 IPython/frontend/terminal/interactiveshell.py
@@ -86,10 +86,6 @@
# 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 @@ def __init__(self, config=None, ipython_dir=None, profile_dir=None,
# 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
View
@@ -3175,7 +3175,7 @@ def _get_pasted_lines(self, sentinel):
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:
@@ -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 @@ def raw_input(self, prompt=''):
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!")

0 comments on commit d8f3d17

Please sign in to comment.