aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/code.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/code.py')
-rw-r--r--Lib/code.py47
1 files changed, 14 insertions, 33 deletions
diff --git a/Lib/code.py b/Lib/code.py
index 3b39d1b346f..605aede5ef1 100644
--- a/Lib/code.py
+++ b/Lib/code.py
@@ -12,19 +12,6 @@ from codeop import CommandCompiler, compile_command
__all__ = ["InteractiveInterpreter", "InteractiveConsole", "interact",
"compile_command"]
-def softspace(file, newvalue):
- oldvalue = 0
- try:
- oldvalue = file.softspace
- except AttributeError:
- pass
- try:
- file.softspace = newvalue
- except (AttributeError, TypeError):
- # "attribute-less object" or "read-only attributes"
- pass
- return oldvalue
-
class InteractiveInterpreter:
"""Base class for InteractiveConsole.
@@ -100,14 +87,11 @@ class InteractiveInterpreter:
"""
try:
- exec code in self.locals
+ exec(code, self.locals)
except SystemExit:
raise
except:
self.showtraceback()
- else:
- if softspace(sys.stdout, 0):
- print
def showsyntaxerror(self, filename=None):
"""Display the syntax error that just occurred.
@@ -127,16 +111,16 @@ class InteractiveInterpreter:
if filename and type is SyntaxError:
# Work hard to stuff the correct filename in the exception
try:
- msg, (dummy_filename, lineno, offset, line) = value
- except:
+ msg, (dummy_filename, lineno, offset, line) = value.args
+ except ValueError:
# Not the format we expect; leave it alone
pass
else:
# Stuff in the right filename
value = SyntaxError(msg, (filename, lineno, offset, line))
sys.last_value = value
- list = traceback.format_exception_only(type, value)
- map(self.write, list)
+ lines = traceback.format_exception_only(type, value)
+ self.write(''.join(lines))
def showtraceback(self):
"""Display the exception that just occurred.
@@ -153,13 +137,13 @@ class InteractiveInterpreter:
sys.last_traceback = tb
tblist = traceback.extract_tb(tb)
del tblist[:1]
- list = traceback.format_list(tblist)
- if list:
- list.insert(0, "Traceback (most recent call last):\n")
- list[len(list):] = traceback.format_exception_only(type, value)
+ lines = traceback.format_list(tblist)
+ if lines:
+ lines.insert(0, "Traceback (most recent call last):\n")
+ lines.extend(traceback.format_exception_only(type, value))
finally:
tblist = tb = None
- map(self.write, list)
+ self.write(''.join(lines))
def write(self, data):
"""Write a string.
@@ -200,7 +184,7 @@ class InteractiveConsole(InteractiveInterpreter):
def interact(self, banner=None):
"""Closely emulate the interactive Python console.
- The optional banner argument specify the banner to print
+ The optional banner argument specifies the banner to print
before the first interaction; by default it prints a banner
similar to the one printed by the real Python interpreter,
followed by the current class name in parentheses (so as not
@@ -232,10 +216,6 @@ class InteractiveConsole(InteractiveInterpreter):
prompt = sys.ps1
try:
line = self.raw_input(prompt)
- # Can be None if sys.stdin was redefined
- encoding = getattr(sys.stdin, "encoding", None)
- if encoding and not isinstance(line, unicode):
- line = line.decode(encoding)
except EOFError:
self.write("\n")
break
@@ -274,11 +254,12 @@ class InteractiveConsole(InteractiveInterpreter):
When the user enters the EOF key sequence, EOFError is raised.
The base implementation uses the built-in function
- raw_input(); a subclass may replace this with a different
+ input(); a subclass may replace this with a different
implementation.
"""
- return raw_input(prompt)
+ return input(prompt)
+
def interact(banner=None, readfunc=None, local=None):