All Samples(952) | Call(937) | Derive(0) | Import(15)
Format the exception part of a traceback. The arguments are the exception type and value such as given by sys.last_type and sys.last_value. The return value is a list of strings, each ending in a newline. Normally, the list contains a single string; however, for SyntaxError exceptions, it contains several lines that (when printed) display detailed information about where the syntax error occurred. The message indicating which exception occurred is always the last string in the list.
def format_exception_only(etype, value):
"""Format the exception part of a traceback.
The arguments are the exception type and value such as given by
sys.last_type and sys.last_value. The return value is a list of
strings, each ending in a newline.
Normally, the list contains a single string; however, for
SyntaxError exceptions, it contains several lines that (when
printed) display detailed information about where the syntax
error occurred.
The message indicating which exception occurred is always the last
string in the list.
"""
# An instance should not have a meaningful value parameter, but
# sometimes does, particularly for string exceptions, such as
# >>> raise string1, string2 # deprecated
#
# Clear these out first because issubtype(string1, SyntaxError)
# would throw another exception and mask the original problem.
if (isinstance(etype, BaseException) or
isinstance(etype, types.InstanceType) or
etype is None or type(etype) is str):
return [_format_final_exc_line(etype, value)]
stype = etype.__name__
if not issubclass(etype, SyntaxError):
return [_format_final_exc_line(stype, value)]
# It was a syntax error; show exactly where the problem was found.
lines = []
try:
msg, (filename, lineno, offset, badline) = value.args
except Exception:
pass
else:
filename = filename or ""
lines.append(' File "%s", line %d\n' % (filename, lineno))
if badline is not None:
lines.append(' %s\n' % badline.strip())
if offset is not None:
caretspace = badline.rstrip('\n')[:offset].lstrip()
# non-space whitespace (likes tabs) must be kept for alignment
caretspace = ((c.isspace() and c or ' ') for c in caretspace)
# only three spaces to account for offset1 == pos 0
lines.append(' %s^\n' % ''.join(caretspace))
value = msg
lines.append(_format_final_exc_line(stype, value))
return lines
if tb:
file.write('Traceback (most recent call last):\n')
_print_tb(tb, limit, file)
lines = traceback.format_exception_only(etype, value)
for line in lines[:-1]:
file.write(line+' ')
file.write(lines[-1])
def _format_exception_only():
try:
# Assume exception can be formatted as a list of with single element, with a trailing \n.
return traceback.format_exception_only(sys.exc_info()[0], sys.exc_info()[1])[0][:-1]
except IndexError:
return str(sys.exc_info()[0]) + ": " + str(sys.exc_info()[1])
src/l/e/LEPL-4.3.2/src/lepl/_example/support.py LEPL(Download)
from logging import getLogger from unittest import TestCase from traceback import format_exception_only, format_exc from lepl._test.base import assert_str
result = str(example())
except Exception as e:
getLogger('lepl._example.support.Example').debug(format_exc())
result = ''.join(format_exception_only(type(e), e))
assert_str(target, result)
src/p/y/pyobjc-framework-Cocoa-2.3/Examples/AppKit/PythonBrowser/PythonBrowserModel.py pyobjc-framework-Cocoa(Download)
def __repr__(self):
from traceback import format_exception_only
lines = format_exception_only(*self.exc_info[:2])
assert len(lines) == 1
error = lines[0].strip()
return "*** error *** %s" %error
src/i/r/ironruby-HEAD/External.LCA_RESTRICTED/Languages/IronPython/27/Lib/site-packages/isapi/threaded_extension.py ironruby(Download)
print >> ecb
print >> ecb, "<H3>Traceback (most recent call last):</H3>"
list = traceback.format_tb(exc_tb, limit) + \
traceback.format_exception_only(exc_typ, exc_val)
print >> ecb, "<PRE>%s<B>%s</B></PRE>" % (
cgi.escape("".join(list[:-1])), cgi.escape(list[-1]),)
except ExtensionError:
src/j/y/jython-HEAD/sandbox/tobias/jython/CPythonLib/idlelib/run.py jython(Download)
"RemoteDebugger.py", "bdb.py")
cleanup_traceback(tbe, exclude)
traceback.print_list(tbe, file=efile)
lines = traceback.format_exception_only(typ, val)
for line in lines:
print>>efile, line,
src/i/r/ironruby-HEAD/External.LCA_RESTRICTED/Languages/IronPython/27/Lib/idlelib/run.py ironruby(Download)
"RemoteDebugger.py", "bdb.py")
cleanup_traceback(tbe, exclude)
traceback.print_list(tbe, file=efile)
lines = traceback.format_exception_only(typ, val)
for line in lines:
print>>efile, line,
src/i/r/ironruby-HEAD/External.LCA_RESTRICTED/Languages/CPython/27/Lib/idlelib/run.py ironruby(Download)
"RemoteDebugger.py", "bdb.py")
cleanup_traceback(tbe, exclude)
traceback.print_list(tbe, file=efile)
lines = traceback.format_exception_only(typ, val)
for line in lines:
print>>efile, line,
src/j/y/jython-HEAD/jython/CPythonLib/idlelib/run.py jython(Download)
"RemoteDebugger.py", "bdb.py")
cleanup_traceback(tbe, exclude)
traceback.print_list(tbe, file=efile)
lines = traceback.format_exception_only(typ, val)
for line in lines:
print>>efile, line,
src/j/y/jython-HEAD/sandbox/tobias/jython/CPythonLib/code.py jython(Download)
# 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)
def showtraceback(self):
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)
finally:
tblist = tb = None
map(self.write, list)
src/i/r/ironruby-HEAD/External.LCA_RESTRICTED/Languages/IronPython/27/Lib/code.py ironruby(Download)
# 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)
def showtraceback(self):
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)
finally:
tblist = tb = None
map(self.write, list)
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Next