Open
Description
For instance, in simple_interact.py
there is _strip_final_indent
, which is not present here.
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
import __main__
mainmodule = mainmodule or __main__
console = code.InteractiveConsole(mainmodule.__dict__, filename='<stdin>')
if future_flags:
console.compile.compiler.flags |= future_flags
def more_lines(unicodetext):
# ooh, look at the hack:
if sys.version_info < (3,):
src = "#coding:utf-8\n"+_strip_final_indent(unicodetext).encode('utf-8')
else:
src = _strip_final_indent(unicodetext)
try:
code = console.compile(src, '<stdin>', 'single')
except (OverflowError, SyntaxError, ValueError):
return False
else:
return code is None
...
Activity