summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/ScriptBinding.py
diff options
context:
space:
mode:
authorKurt B. Kaiser <kbk@shore.net>2004-07-04 01:25:56 (GMT)
committerKurt B. Kaiser <kbk@shore.net>2004-07-04 01:25:56 (GMT)
commit49a5fe107fceb0239d87119842b20a7421043b5a (patch)
tree1d265bc88514c8069ea096650870b87c06698c86 /Lib/idlelib/ScriptBinding.py
parent9ec3e3b6eb4b36870bd28682e6c7a6c36911e5e0 (diff)
downloadcpython-49a5fe107fceb0239d87119842b20a7421043b5a.zip
cpython-49a5fe107fceb0239d87119842b20a7421043b5a.tar.gz
cpython-49a5fe107fceb0239d87119842b20a7421043b5a.tar.bz2
Redirect the warning stream to the shell during the ScriptBinding check of user code
and format the warning similarly to an exception for both that check and for warnings raised in the subprocess. M NEWS.txt M Pyshell.py M ScriptBinding.py M run.py
Diffstat (limited to 'Lib/idlelib/ScriptBinding.py')
-rw-r--r--Lib/idlelib/ScriptBinding.py40
1 files changed, 23 insertions, 17 deletions
diff --git a/Lib/idlelib/ScriptBinding.py b/Lib/idlelib/ScriptBinding.py
index a1d937b..8ad02a4 100644
--- a/Lib/idlelib/ScriptBinding.py
+++ b/Lib/idlelib/ScriptBinding.py
@@ -82,6 +82,9 @@ class ScriptBinding:
return True
def checksyntax(self, filename):
+ self.shell = shell = self.flist.open_shell()
+ saved_stream = shell.get_warning_stream()
+ shell.set_warning_stream(shell.stderr)
f = open(filename, 'r')
source = f.read()
f.close()
@@ -92,20 +95,23 @@ class ScriptBinding:
text = self.editwin.text
text.tag_remove("ERROR", "1.0", "end")
try:
- # If successful, return the compiled code
- return compile(source, filename, "exec")
- except (SyntaxError, OverflowError), err:
try:
- msg, (errorfilename, lineno, offset, line) = err
- if not errorfilename:
- err.args = msg, (filename, lineno, offset, line)
- err.filename = filename
- self.colorize_syntax_error(msg, lineno, offset)
- except:
- msg = "*** " + str(err)
- self.errorbox("Syntax error",
- "There's an error in your program:\n" + msg)
- return False
+ # If successful, return the compiled code
+ return compile(source, filename, "exec")
+ except (SyntaxError, OverflowError), err:
+ try:
+ msg, (errorfilename, lineno, offset, line) = err
+ if not errorfilename:
+ err.args = msg, (filename, lineno, offset, line)
+ err.filename = filename
+ self.colorize_syntax_error(msg, lineno, offset)
+ except:
+ msg = "*** " + str(err)
+ self.errorbox("Syntax error",
+ "There's an error in your program:\n" + msg)
+ return False
+ finally:
+ shell.set_warning_stream(saved_stream)
def colorize_syntax_error(self, msg, lineno, offset):
text = self.editwin.text
@@ -135,10 +141,7 @@ class ScriptBinding:
code = self.checksyntax(filename)
if not code:
return
- flist = self.editwin.flist
- shell = flist.open_shell()
- if not shell:
- return # couldn't open the shell
+ shell = self.shell
interp = shell.interp
if PyShell.use_subprocess:
shell.restart_shell()
@@ -156,6 +159,9 @@ class ScriptBinding:
del _filename, _sys, _basename, _os
\n""" % (filename, dirname))
interp.prepend_syspath(filename)
+ # XXX KBK 03Jul04 When run w/o subprocess, runtime warnings still
+ # go to __stderr__. With subprocess, they go to the shell.
+ # Need to change streams in PyShell.ModifiedInterpreter.
interp.runcode(code)
def getfilename(self):