aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2021-04-01 23:25:08 +0300
committerMatti Picus <matti.picus@gmail.com>2021-04-01 23:25:08 +0300
commit3e67d2b5ec103696e7ffe7332dad63cf8d95a7e3 (patch)
treefddf039929a8a0400d6e05ff75d160ae5072f68e
parentmention HPy in release note; tweak documentation (diff)
downloadpypy-3e67d2b5ec103696e7ffe7332dad63cf8d95a7e3.tar.gz
pypy-3e67d2b5ec103696e7ffe7332dad63cf8d95a7e3.tar.bz2
pypy-3e67d2b5ec103696e7ffe7332dad63cf8d95a7e3.zip
restore code that got lost in the shuffle (thanks obfusk)
-rw-r--r--lib_pypy/pyrepl/simple_interact.py23
1 files changed, 19 insertions, 4 deletions
diff --git a/lib_pypy/pyrepl/simple_interact.py b/lib_pypy/pyrepl/simple_interact.py
index 3b84a156b2..ca0364615d 100644
--- a/lib_pypy/pyrepl/simple_interact.py
+++ b/lib_pypy/pyrepl/simple_interact.py
@@ -26,7 +26,6 @@ allowing multiline input and multiline history entries.
import sys
from pyrepl.readline import multiline_input, _error, _get_reader
-
def check(): # returns False if there is a problem initializing the state
try:
_get_reader()
@@ -34,6 +33,15 @@ def check(): # returns False if there is a problem initializing the state
return False
return True
+def _strip_final_indent(text):
+ # kill spaces and tabs at the end, but only if they follow '\n'.
+ # meant to remove the auto-indentation only (although it would of
+ # course also remove explicitly-added indentation).
+ short = text.rstrip(' \t')
+ n = len(short)
+ if n > 0 and text[n-1] == '\n':
+ return short
+ return text
def run_multiline_interactive_console(mainmodule=None, future_flags=0):
import code
@@ -46,9 +54,9 @@ def run_multiline_interactive_console(mainmodule=None, future_flags=0):
def more_lines(unicodetext):
if sys.version_info < (3, ):
# ooh, look at the hack:
- src = "#coding:utf-8\n"+unicodetext.encode('utf-8')
+ src = "#coding:utf-8\n" + _strip_final_indent(unicodetext).encode('utf-8')
else:
- src = unicodetext
+ src = _strip_final_indent(unicodetext)
try:
code = console.compile(src, '<stdin>', 'single')
except (OverflowError, SyntaxError, ValueError):
@@ -58,6 +66,10 @@ def run_multiline_interactive_console(mainmodule=None, future_flags=0):
while 1:
try:
+ try:
+ sys.stdout.flush()
+ except:
+ pass
ps1 = getattr(sys, 'ps1', '>>> ')
ps2 = getattr(sys, 'ps2', '... ')
try:
@@ -65,8 +77,11 @@ def run_multiline_interactive_console(mainmodule=None, future_flags=0):
returns_unicode=True)
except EOFError:
break
- more = console.push(statement)
+ more = console.push(_strip_final_indent(statement))
assert not more
except KeyboardInterrupt:
console.write("\nKeyboardInterrupt\n")
console.resetbuffer()
+ except MemoryError:
+ console.write("\nMemoryError\n")
+ console.resetbuffer()