use new showwarnings signature for idle #3391

This commit is contained in:
Benjamin Peterson 2008-10-16 19:40:14 +00:00
parent 5c4e006367
commit b76444b2fa
2 changed files with 11 additions and 6 deletions

View File

@ -55,18 +55,22 @@ try:
except ImportError:
pass
else:
def idle_showwarning(message, category, filename, lineno):
def idle_showwarning(message, category, filename, lineno,
file=None, line=None):
file = warning_stream
try:
file.write(warnings.formatwarning(message, category, filename, lineno))
file.write(warnings.formatwarning(message, category, filename,\
lineno, file=file, line=line))
except IOError:
pass ## file (probably __stderr__) is invalid, warning dropped.
warnings.showwarning = idle_showwarning
def idle_formatwarning(message, category, filename, lineno):
def idle_formatwarning(message, category, filename, lineno,
file=None, line=None):
"""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()
line = linecache.getline(filename, lineno).strip() \
if line is None else line
if line:
s += " %s\n" % line
s += "%s: %s\n>>> " % (category.__name__, message)

View File

@ -25,11 +25,12 @@ except ImportError:
pass
else:
def idle_formatwarning_subproc(message, category, filename, lineno,
line=None):
file=None, line=None):
"""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()
line = linecache.getline(filename, lineno).strip() \
if line is None else line
if line:
s += " %s\n" % line
s += "%s: %s\n" % (category.__name__, message)