summaryrefslogtreecommitdiff
path: root/Lib/idlelib/run.py
diff options
context:
space:
mode:
authorKurt B. Kaiser <kbk@shore.net>2004-07-04 01:25:56 +0000
committerKurt B. Kaiser <kbk@shore.net>2004-07-04 01:25:56 +0000
commit49a5fe107fceb0239d87119842b20a7421043b5a (patch)
tree1d265bc88514c8069ea096650870b87c06698c86 /Lib/idlelib/run.py
parent9ec3e3b6eb4b36870bd28682e6c7a6c36911e5e0 (diff)
downloadcpython-git-49a5fe107fceb0239d87119842b20a7421043b5a.tar.gz
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/run.py')
-rw-r--r--Lib/idlelib/run.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py
index 96da4593b4..98b8c13030 100644
--- a/Lib/idlelib/run.py
+++ b/Lib/idlelib/run.py
@@ -1,5 +1,6 @@
import sys
import os
+import linecache
import time
import socket
import traceback
@@ -17,6 +18,22 @@ import __main__
LOCALHOST = '127.0.0.1'
+try:
+ import warnings
+except ImportError:
+ pass
+else:
+ def idle_formatwarning_subproc(message, category, filename, lineno):
+ """Format warnings the IDLE way"""
+ s = "\nWarning (from warnings module):\n"
+ s += ' File \"%s\", line %s\n' % (filename, lineno)
+ line = linecache.getline(filename, lineno).strip()
+ if line:
+ s += " %s\n" % line
+ s += "%s: %s\n" % (category.__name__, message)
+ return s
+ warnings.formatwarning = idle_formatwarning_subproc
+
# Thread shared globals: Establish a queue between a subthread (which handles
# the socket) and the main thread (which runs user code), plus global
# completion and exit flags: