From: Guido van Rossum Date: Fri, 14 Jun 2002 13:48:25 +0000 (+0000) Subject: Don't poorly emulate the interactive interpreter, use X-Git-Tag: v2.3c1~5311 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2aabac8276751c6a1a9758a410b8b837354967b8;p=python Don't poorly emulate the interactive interpreter, use code.InteractiveConsole to do a much better job. --- diff --git a/Lib/rexec.py b/Lib/rexec.py index 623cc97665..b45fc69917 100644 --- a/Lib/rexec.py +++ b/Lib/rexec.py @@ -552,25 +552,15 @@ def test(): print "%s: can't open file %s" % (sys.argv[0], `args[0]`) return 1 if fp.isatty(): - print "*** RESTRICTED *** Python", sys.version - print 'Type "help", "copyright", "credits" or "license" ' \ - 'for more information.' - - while 1: - try: - try: - s = raw_input('>>> ') - except EOFError: - print - break - if s and s[0] != '#': - s = s + '\n' - c = compile(s, '', 'single') - r.s_exec(c) - except SystemExit, n: - return n - except: - traceback.print_exc() + import code + interp = code.InteractiveConsole(r.modules['__main__'].__dict__) + try: + interp.interact( + "*** RESTRICTED *** Python %s on %s\n" + 'Type "help", "copyright", "credits" or "license" ' + "for more information." % (sys.version, sys.platform)) + except SystemExit, n: + return n else: text = fp.read() fp.close()