[pypy-svn] r53569 - pypy/dist/pypy/lib
arigo at codespeak.net
arigo at codespeak.net
Tue Apr 8 12:23:26 CEST 2008
Author: arigo
Date: Tue Apr 8 12:23:25 2008
New Revision: 53569
Added:
pypy/dist/pypy/lib/readline.py
Modified:
pypy/dist/pypy/lib/_pypy_interact.py
Log:
Move this logic into pyrepl itself.
Modified: pypy/dist/pypy/lib/_pypy_interact.py
==============================================================================
--- pypy/dist/pypy/lib/_pypy_interact.py (original)
+++ pypy/dist/pypy/lib/_pypy_interact.py Tue Apr 8 12:23:25 2008
@@ -4,18 +4,18 @@
def interactive_console(mainmodule=None):
- import code
- if mainmodule is None:
- import __main__ as mainmodule
- console = code.InteractiveConsole(mainmodule.__dict__)
try:
- from readline import multiline_input
+ from pyrepl.simple_interact import run_multiline_interactive_console
except ImportError:
- run_simple_interactive_console(console)
+ run_simple_interactive_console(mainmodule)
else:
- run_multiline_interactive_console(console)
+ run_multiline_interactive_console(mainmodule)
-def run_simple_interactive_console(console):
+def run_simple_interactive_console(mainmodule):
+ import code
+ if mainmodule is None:
+ import __main__ as mainmodule
+ console = code.InteractiveConsole(mainmodule.__dict__)
# some parts of code.py are copied here because it seems to be impossible
# to start an interactive console without printing at least one line
# of banner
@@ -38,37 +38,6 @@
console.resetbuffer()
more = 0
-def run_multiline_interactive_console(console):
- from readline import multiline_input
-
- def more_lines(unicodetext):
- # ooh, look at the hack:
- src = "#coding:utf-8\n"+unicodetext.encode('utf-8')
- try:
- code = console.compile(src, '<input>', 'single')
- except (OverflowError, SyntaxError, ValueError):
- return False
- else:
- return code is None
-
- while 1:
- try:
- ps1 = getattr(sys, 'ps1', '>>> ')
- ps2 = getattr(sys, 'ps2', '... ')
- try:
- statement = multiline_input(more_lines, ps1, ps2)
- except EOFError:
- break
- # XXX with Alt-Enter we can actually enter more than one
- # statement, and compile() ignores everything after the
- # first statement in 'single' mode... We should either
- # find some obscure workaround or tweak PyPy's compiler.
- more = console.push(statement)
- assert not more
- except KeyboardInterrupt:
- console.write("\nKeyboardInterrupt\n")
- console.resetbuffer()
-
# ____________________________________________________________
if __name__ == '__main__': # for testing
Added: pypy/dist/pypy/lib/readline.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/lib/readline.py Tue Apr 8 12:23:25 2008
@@ -0,0 +1,8 @@
+"""readline - Importing this module enables command line editing using
+the pyrepl library. The API is a subset of the GNU readline library.
+It also contains extensions for multiline input.
+
+Note that some of the functions present in the CPython module 'readline'
+are only stubs at the moment.
+"""
+from pyrepl.readline import *
More information about the pypy-svn
mailing list