Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib64/python3....
File: traceback.py
"""Extract, format and print information about Python stack traces."""
[0] Fix | Delete
[1] Fix | Delete
import collections
[2] Fix | Delete
import itertools
[3] Fix | Delete
import linecache
[4] Fix | Delete
import sys
[5] Fix | Delete
[6] Fix | Delete
__all__ = ['extract_stack', 'extract_tb', 'format_exception',
[7] Fix | Delete
'format_exception_only', 'format_list', 'format_stack',
[8] Fix | Delete
'format_tb', 'print_exc', 'format_exc', 'print_exception',
[9] Fix | Delete
'print_last', 'print_stack', 'print_tb', 'clear_frames',
[10] Fix | Delete
'FrameSummary', 'StackSummary', 'TracebackException',
[11] Fix | Delete
'walk_stack', 'walk_tb']
[12] Fix | Delete
[13] Fix | Delete
#
[14] Fix | Delete
# Formatting and printing lists of traceback lines.
[15] Fix | Delete
#
[16] Fix | Delete
[17] Fix | Delete
def print_list(extracted_list, file=None):
[18] Fix | Delete
"""Print the list of tuples as returned by extract_tb() or
[19] Fix | Delete
extract_stack() as a formatted stack trace to the given file."""
[20] Fix | Delete
if file is None:
[21] Fix | Delete
file = sys.stderr
[22] Fix | Delete
for item in StackSummary.from_list(extracted_list).format():
[23] Fix | Delete
print(item, file=file, end="")
[24] Fix | Delete
[25] Fix | Delete
def format_list(extracted_list):
[26] Fix | Delete
"""Format a list of tuples or FrameSummary objects for printing.
[27] Fix | Delete
[28] Fix | Delete
Given a list of tuples or FrameSummary objects as returned by
[29] Fix | Delete
extract_tb() or extract_stack(), return a list of strings ready
[30] Fix | Delete
for printing.
[31] Fix | Delete
[32] Fix | Delete
Each string in the resulting list corresponds to the item with the
[33] Fix | Delete
same index in the argument list. Each string ends in a newline;
[34] Fix | Delete
the strings may contain internal newlines as well, for those items
[35] Fix | Delete
whose source text line is not None.
[36] Fix | Delete
"""
[37] Fix | Delete
return StackSummary.from_list(extracted_list).format()
[38] Fix | Delete
[39] Fix | Delete
#
[40] Fix | Delete
# Printing and Extracting Tracebacks.
[41] Fix | Delete
#
[42] Fix | Delete
[43] Fix | Delete
def print_tb(tb, limit=None, file=None):
[44] Fix | Delete
"""Print up to 'limit' stack trace entries from the traceback 'tb'.
[45] Fix | Delete
[46] Fix | Delete
If 'limit' is omitted or None, all entries are printed. If 'file'
[47] Fix | Delete
is omitted or None, the output goes to sys.stderr; otherwise
[48] Fix | Delete
'file' should be an open file or file-like object with a write()
[49] Fix | Delete
method.
[50] Fix | Delete
"""
[51] Fix | Delete
print_list(extract_tb(tb, limit=limit), file=file)
[52] Fix | Delete
[53] Fix | Delete
def format_tb(tb, limit=None):
[54] Fix | Delete
"""A shorthand for 'format_list(extract_tb(tb, limit))'."""
[55] Fix | Delete
return extract_tb(tb, limit=limit).format()
[56] Fix | Delete
[57] Fix | Delete
def extract_tb(tb, limit=None):
[58] Fix | Delete
"""
[59] Fix | Delete
Return a StackSummary object representing a list of
[60] Fix | Delete
pre-processed entries from traceback.
[61] Fix | Delete
[62] Fix | Delete
This is useful for alternate formatting of stack traces. If
[63] Fix | Delete
'limit' is omitted or None, all entries are extracted. A
[64] Fix | Delete
pre-processed stack trace entry is a FrameSummary object
[65] Fix | Delete
containing attributes filename, lineno, name, and line
[66] Fix | Delete
representing the information that is usually printed for a stack
[67] Fix | Delete
trace. The line is a string with leading and trailing
[68] Fix | Delete
whitespace stripped; if the source is not available it is None.
[69] Fix | Delete
"""
[70] Fix | Delete
return StackSummary.extract(walk_tb(tb), limit=limit)
[71] Fix | Delete
[72] Fix | Delete
#
[73] Fix | Delete
# Exception formatting and output.
[74] Fix | Delete
#
[75] Fix | Delete
[76] Fix | Delete
_cause_message = (
[77] Fix | Delete
"\nThe above exception was the direct cause "
[78] Fix | Delete
"of the following exception:\n\n")
[79] Fix | Delete
[80] Fix | Delete
_context_message = (
[81] Fix | Delete
"\nDuring handling of the above exception, "
[82] Fix | Delete
"another exception occurred:\n\n")
[83] Fix | Delete
[84] Fix | Delete
[85] Fix | Delete
def print_exception(etype, value, tb, limit=None, file=None, chain=True):
[86] Fix | Delete
"""Print exception up to 'limit' stack trace entries from 'tb' to 'file'.
[87] Fix | Delete
[88] Fix | Delete
This differs from print_tb() in the following ways: (1) if
[89] Fix | Delete
traceback is not None, it prints a header "Traceback (most recent
[90] Fix | Delete
call last):"; (2) it prints the exception type and value after the
[91] Fix | Delete
stack trace; (3) if type is SyntaxError and value has the
[92] Fix | Delete
appropriate format, it prints the line where the syntax error
[93] Fix | Delete
occurred with a caret on the next line indicating the approximate
[94] Fix | Delete
position of the error.
[95] Fix | Delete
"""
[96] Fix | Delete
# format_exception has ignored etype for some time, and code such as cgitb
[97] Fix | Delete
# passes in bogus values as a result. For compatibility with such code we
[98] Fix | Delete
# ignore it here (rather than in the new TracebackException API).
[99] Fix | Delete
if file is None:
[100] Fix | Delete
file = sys.stderr
[101] Fix | Delete
for line in TracebackException(
[102] Fix | Delete
type(value), value, tb, limit=limit).format(chain=chain):
[103] Fix | Delete
print(line, file=file, end="")
[104] Fix | Delete
[105] Fix | Delete
[106] Fix | Delete
def format_exception(etype, value, tb, limit=None, chain=True):
[107] Fix | Delete
"""Format a stack trace and the exception information.
[108] Fix | Delete
[109] Fix | Delete
The arguments have the same meaning as the corresponding arguments
[110] Fix | Delete
to print_exception(). The return value is a list of strings, each
[111] Fix | Delete
ending in a newline and some containing internal newlines. When
[112] Fix | Delete
these lines are concatenated and printed, exactly the same text is
[113] Fix | Delete
printed as does print_exception().
[114] Fix | Delete
"""
[115] Fix | Delete
# format_exception has ignored etype for some time, and code such as cgitb
[116] Fix | Delete
# passes in bogus values as a result. For compatibility with such code we
[117] Fix | Delete
# ignore it here (rather than in the new TracebackException API).
[118] Fix | Delete
return list(TracebackException(
[119] Fix | Delete
type(value), value, tb, limit=limit).format(chain=chain))
[120] Fix | Delete
[121] Fix | Delete
[122] Fix | Delete
def format_exception_only(etype, value):
[123] Fix | Delete
"""Format the exception part of a traceback.
[124] Fix | Delete
[125] Fix | Delete
The arguments are the exception type and value such as given by
[126] Fix | Delete
sys.last_type and sys.last_value. The return value is a list of
[127] Fix | Delete
strings, each ending in a newline.
[128] Fix | Delete
[129] Fix | Delete
Normally, the list contains a single string; however, for
[130] Fix | Delete
SyntaxError exceptions, it contains several lines that (when
[131] Fix | Delete
printed) display detailed information about where the syntax
[132] Fix | Delete
error occurred.
[133] Fix | Delete
[134] Fix | Delete
The message indicating which exception occurred is always the last
[135] Fix | Delete
string in the list.
[136] Fix | Delete
[137] Fix | Delete
"""
[138] Fix | Delete
return list(TracebackException(etype, value, None).format_exception_only())
[139] Fix | Delete
[140] Fix | Delete
[141] Fix | Delete
# -- not official API but folk probably use these two functions.
[142] Fix | Delete
[143] Fix | Delete
def _format_final_exc_line(etype, value):
[144] Fix | Delete
valuestr = _some_str(value)
[145] Fix | Delete
if value is None or not valuestr:
[146] Fix | Delete
line = "%s\n" % etype
[147] Fix | Delete
else:
[148] Fix | Delete
line = "%s: %s\n" % (etype, valuestr)
[149] Fix | Delete
return line
[150] Fix | Delete
[151] Fix | Delete
def _some_str(value):
[152] Fix | Delete
try:
[153] Fix | Delete
return str(value)
[154] Fix | Delete
except:
[155] Fix | Delete
return '<unprintable %s object>' % type(value).__name__
[156] Fix | Delete
[157] Fix | Delete
# --
[158] Fix | Delete
[159] Fix | Delete
def print_exc(limit=None, file=None, chain=True):
[160] Fix | Delete
"""Shorthand for 'print_exception(*sys.exc_info(), limit, file)'."""
[161] Fix | Delete
print_exception(*sys.exc_info(), limit=limit, file=file, chain=chain)
[162] Fix | Delete
[163] Fix | Delete
def format_exc(limit=None, chain=True):
[164] Fix | Delete
"""Like print_exc() but return a string."""
[165] Fix | Delete
return "".join(format_exception(*sys.exc_info(), limit=limit, chain=chain))
[166] Fix | Delete
[167] Fix | Delete
def print_last(limit=None, file=None, chain=True):
[168] Fix | Delete
"""This is a shorthand for 'print_exception(sys.last_type,
[169] Fix | Delete
sys.last_value, sys.last_traceback, limit, file)'."""
[170] Fix | Delete
if not hasattr(sys, "last_type"):
[171] Fix | Delete
raise ValueError("no last exception")
[172] Fix | Delete
print_exception(sys.last_type, sys.last_value, sys.last_traceback,
[173] Fix | Delete
limit, file, chain)
[174] Fix | Delete
[175] Fix | Delete
#
[176] Fix | Delete
# Printing and Extracting Stacks.
[177] Fix | Delete
#
[178] Fix | Delete
[179] Fix | Delete
def print_stack(f=None, limit=None, file=None):
[180] Fix | Delete
"""Print a stack trace from its invocation point.
[181] Fix | Delete
[182] Fix | Delete
The optional 'f' argument can be used to specify an alternate
[183] Fix | Delete
stack frame at which to start. The optional 'limit' and 'file'
[184] Fix | Delete
arguments have the same meaning as for print_exception().
[185] Fix | Delete
"""
[186] Fix | Delete
if f is None:
[187] Fix | Delete
f = sys._getframe().f_back
[188] Fix | Delete
print_list(extract_stack(f, limit=limit), file=file)
[189] Fix | Delete
[190] Fix | Delete
[191] Fix | Delete
def format_stack(f=None, limit=None):
[192] Fix | Delete
"""Shorthand for 'format_list(extract_stack(f, limit))'."""
[193] Fix | Delete
if f is None:
[194] Fix | Delete
f = sys._getframe().f_back
[195] Fix | Delete
return format_list(extract_stack(f, limit=limit))
[196] Fix | Delete
[197] Fix | Delete
[198] Fix | Delete
def extract_stack(f=None, limit=None):
[199] Fix | Delete
"""Extract the raw traceback from the current stack frame.
[200] Fix | Delete
[201] Fix | Delete
The return value has the same format as for extract_tb(). The
[202] Fix | Delete
optional 'f' and 'limit' arguments have the same meaning as for
[203] Fix | Delete
print_stack(). Each item in the list is a quadruple (filename,
[204] Fix | Delete
line number, function name, text), and the entries are in order
[205] Fix | Delete
from oldest to newest stack frame.
[206] Fix | Delete
"""
[207] Fix | Delete
if f is None:
[208] Fix | Delete
f = sys._getframe().f_back
[209] Fix | Delete
stack = StackSummary.extract(walk_stack(f), limit=limit)
[210] Fix | Delete
stack.reverse()
[211] Fix | Delete
return stack
[212] Fix | Delete
[213] Fix | Delete
[214] Fix | Delete
def clear_frames(tb):
[215] Fix | Delete
"Clear all references to local variables in the frames of a traceback."
[216] Fix | Delete
while tb is not None:
[217] Fix | Delete
try:
[218] Fix | Delete
tb.tb_frame.clear()
[219] Fix | Delete
except RuntimeError:
[220] Fix | Delete
# Ignore the exception raised if the frame is still executing.
[221] Fix | Delete
pass
[222] Fix | Delete
tb = tb.tb_next
[223] Fix | Delete
[224] Fix | Delete
[225] Fix | Delete
class FrameSummary:
[226] Fix | Delete
"""A single frame from a traceback.
[227] Fix | Delete
[228] Fix | Delete
- :attr:`filename` The filename for the frame.
[229] Fix | Delete
- :attr:`lineno` The line within filename for the frame that was
[230] Fix | Delete
active when the frame was captured.
[231] Fix | Delete
- :attr:`name` The name of the function or method that was executing
[232] Fix | Delete
when the frame was captured.
[233] Fix | Delete
- :attr:`line` The text from the linecache module for the
[234] Fix | Delete
of code that was running when the frame was captured.
[235] Fix | Delete
- :attr:`locals` Either None if locals were not supplied, or a dict
[236] Fix | Delete
mapping the name to the repr() of the variable.
[237] Fix | Delete
"""
[238] Fix | Delete
[239] Fix | Delete
__slots__ = ('filename', 'lineno', 'name', '_line', 'locals')
[240] Fix | Delete
[241] Fix | Delete
def __init__(self, filename, lineno, name, *, lookup_line=True,
[242] Fix | Delete
locals=None, line=None):
[243] Fix | Delete
"""Construct a FrameSummary.
[244] Fix | Delete
[245] Fix | Delete
:param lookup_line: If True, `linecache` is consulted for the source
[246] Fix | Delete
code line. Otherwise, the line will be looked up when first needed.
[247] Fix | Delete
:param locals: If supplied the frame locals, which will be captured as
[248] Fix | Delete
object representations.
[249] Fix | Delete
:param line: If provided, use this instead of looking up the line in
[250] Fix | Delete
the linecache.
[251] Fix | Delete
"""
[252] Fix | Delete
self.filename = filename
[253] Fix | Delete
self.lineno = lineno
[254] Fix | Delete
self.name = name
[255] Fix | Delete
self._line = line
[256] Fix | Delete
if lookup_line:
[257] Fix | Delete
self.line
[258] Fix | Delete
self.locals = {k: repr(v) for k, v in locals.items()} if locals else None
[259] Fix | Delete
[260] Fix | Delete
def __eq__(self, other):
[261] Fix | Delete
if isinstance(other, FrameSummary):
[262] Fix | Delete
return (self.filename == other.filename and
[263] Fix | Delete
self.lineno == other.lineno and
[264] Fix | Delete
self.name == other.name and
[265] Fix | Delete
self.locals == other.locals)
[266] Fix | Delete
if isinstance(other, tuple):
[267] Fix | Delete
return (self.filename, self.lineno, self.name, self.line) == other
[268] Fix | Delete
return NotImplemented
[269] Fix | Delete
[270] Fix | Delete
def __getitem__(self, pos):
[271] Fix | Delete
return (self.filename, self.lineno, self.name, self.line)[pos]
[272] Fix | Delete
[273] Fix | Delete
def __iter__(self):
[274] Fix | Delete
return iter([self.filename, self.lineno, self.name, self.line])
[275] Fix | Delete
[276] Fix | Delete
def __repr__(self):
[277] Fix | Delete
return "<FrameSummary file {filename}, line {lineno} in {name}>".format(
[278] Fix | Delete
filename=self.filename, lineno=self.lineno, name=self.name)
[279] Fix | Delete
[280] Fix | Delete
def __len__(self):
[281] Fix | Delete
return 4
[282] Fix | Delete
[283] Fix | Delete
@property
[284] Fix | Delete
def line(self):
[285] Fix | Delete
if self._line is None:
[286] Fix | Delete
self._line = linecache.getline(self.filename, self.lineno).strip()
[287] Fix | Delete
return self._line
[288] Fix | Delete
[289] Fix | Delete
[290] Fix | Delete
def walk_stack(f):
[291] Fix | Delete
"""Walk a stack yielding the frame and line number for each frame.
[292] Fix | Delete
[293] Fix | Delete
This will follow f.f_back from the given frame. If no frame is given, the
[294] Fix | Delete
current stack is used. Usually used with StackSummary.extract.
[295] Fix | Delete
"""
[296] Fix | Delete
if f is None:
[297] Fix | Delete
f = sys._getframe().f_back.f_back
[298] Fix | Delete
while f is not None:
[299] Fix | Delete
yield f, f.f_lineno
[300] Fix | Delete
f = f.f_back
[301] Fix | Delete
[302] Fix | Delete
[303] Fix | Delete
def walk_tb(tb):
[304] Fix | Delete
"""Walk a traceback yielding the frame and line number for each frame.
[305] Fix | Delete
[306] Fix | Delete
This will follow tb.tb_next (and thus is in the opposite order to
[307] Fix | Delete
walk_stack). Usually used with StackSummary.extract.
[308] Fix | Delete
"""
[309] Fix | Delete
while tb is not None:
[310] Fix | Delete
yield tb.tb_frame, tb.tb_lineno
[311] Fix | Delete
tb = tb.tb_next
[312] Fix | Delete
[313] Fix | Delete
[314] Fix | Delete
_RECURSIVE_CUTOFF = 3 # Also hardcoded in traceback.c.
[315] Fix | Delete
[316] Fix | Delete
class StackSummary(list):
[317] Fix | Delete
"""A stack of frames."""
[318] Fix | Delete
[319] Fix | Delete
@classmethod
[320] Fix | Delete
def extract(klass, frame_gen, *, limit=None, lookup_lines=True,
[321] Fix | Delete
capture_locals=False):
[322] Fix | Delete
"""Create a StackSummary from a traceback or stack object.
[323] Fix | Delete
[324] Fix | Delete
:param frame_gen: A generator that yields (frame, lineno) tuples to
[325] Fix | Delete
include in the stack.
[326] Fix | Delete
:param limit: None to include all frames or the number of frames to
[327] Fix | Delete
include.
[328] Fix | Delete
:param lookup_lines: If True, lookup lines for each frame immediately,
[329] Fix | Delete
otherwise lookup is deferred until the frame is rendered.
[330] Fix | Delete
:param capture_locals: If True, the local variables from each frame will
[331] Fix | Delete
be captured as object representations into the FrameSummary.
[332] Fix | Delete
"""
[333] Fix | Delete
if limit is None:
[334] Fix | Delete
limit = getattr(sys, 'tracebacklimit', None)
[335] Fix | Delete
if limit is not None and limit < 0:
[336] Fix | Delete
limit = 0
[337] Fix | Delete
if limit is not None:
[338] Fix | Delete
if limit >= 0:
[339] Fix | Delete
frame_gen = itertools.islice(frame_gen, limit)
[340] Fix | Delete
else:
[341] Fix | Delete
frame_gen = collections.deque(frame_gen, maxlen=-limit)
[342] Fix | Delete
[343] Fix | Delete
result = klass()
[344] Fix | Delete
fnames = set()
[345] Fix | Delete
for f, lineno in frame_gen:
[346] Fix | Delete
co = f.f_code
[347] Fix | Delete
filename = co.co_filename
[348] Fix | Delete
name = co.co_name
[349] Fix | Delete
[350] Fix | Delete
fnames.add(filename)
[351] Fix | Delete
linecache.lazycache(filename, f.f_globals)
[352] Fix | Delete
# Must defer line lookups until we have called checkcache.
[353] Fix | Delete
if capture_locals:
[354] Fix | Delete
f_locals = f.f_locals
[355] Fix | Delete
else:
[356] Fix | Delete
f_locals = None
[357] Fix | Delete
result.append(FrameSummary(
[358] Fix | Delete
filename, lineno, name, lookup_line=False, locals=f_locals))
[359] Fix | Delete
for filename in fnames:
[360] Fix | Delete
linecache.checkcache(filename)
[361] Fix | Delete
# If immediate lookup was desired, trigger lookups now.
[362] Fix | Delete
if lookup_lines:
[363] Fix | Delete
for f in result:
[364] Fix | Delete
f.line
[365] Fix | Delete
return result
[366] Fix | Delete
[367] Fix | Delete
@classmethod
[368] Fix | Delete
def from_list(klass, a_list):
[369] Fix | Delete
"""
[370] Fix | Delete
Create a StackSummary object from a supplied list of
[371] Fix | Delete
FrameSummary objects or old-style list of tuples.
[372] Fix | Delete
"""
[373] Fix | Delete
# While doing a fast-path check for isinstance(a_list, StackSummary) is
[374] Fix | Delete
# appealing, idlelib.run.cleanup_traceback and other similar code may
[375] Fix | Delete
# break this by making arbitrary frames plain tuples, so we need to
[376] Fix | Delete
# check on a frame by frame basis.
[377] Fix | Delete
result = StackSummary()
[378] Fix | Delete
for frame in a_list:
[379] Fix | Delete
if isinstance(frame, FrameSummary):
[380] Fix | Delete
result.append(frame)
[381] Fix | Delete
else:
[382] Fix | Delete
filename, lineno, name, line = frame
[383] Fix | Delete
result.append(FrameSummary(filename, lineno, name, line=line))
[384] Fix | Delete
return result
[385] Fix | Delete
[386] Fix | Delete
def format(self):
[387] Fix | Delete
"""Format the stack ready for printing.
[388] Fix | Delete
[389] Fix | Delete
Returns a list of strings ready for printing. Each string in the
[390] Fix | Delete
resulting list corresponds to a single frame from the stack.
[391] Fix | Delete
Each string ends in a newline; the strings may contain internal
[392] Fix | Delete
newlines as well, for those items with source text lines.
[393] Fix | Delete
[394] Fix | Delete
For long sequences of the same frame and line, the first few
[395] Fix | Delete
repetitions are shown, followed by a summary line stating the exact
[396] Fix | Delete
number of further repetitions.
[397] Fix | Delete
"""
[398] Fix | Delete
result = []
[399] Fix | Delete
last_file = None
[400] Fix | Delete
last_line = None
[401] Fix | Delete
last_name = None
[402] Fix | Delete
count = 0
[403] Fix | Delete
for frame in self:
[404] Fix | Delete
if (last_file is None or last_file != frame.filename or
[405] Fix | Delete
last_line is None or last_line != frame.lineno or
[406] Fix | Delete
last_name is None or last_name != frame.name):
[407] Fix | Delete
if count > _RECURSIVE_CUTOFF:
[408] Fix | Delete
count -= _RECURSIVE_CUTOFF
[409] Fix | Delete
result.append(
[410] Fix | Delete
f' [Previous line repeated {count} more '
[411] Fix | Delete
f'time{"s" if count > 1 else ""}]\n'
[412] Fix | Delete
)
[413] Fix | Delete
last_file = frame.filename
[414] Fix | Delete
last_line = frame.lineno
[415] Fix | Delete
last_name = frame.name
[416] Fix | Delete
count = 0
[417] Fix | Delete
count += 1
[418] Fix | Delete
if count > _RECURSIVE_CUTOFF:
[419] Fix | Delete
continue
[420] Fix | Delete
row = []
[421] Fix | Delete
row.append(' File "{}", line {}, in {}\n'.format(
[422] Fix | Delete
frame.filename, frame.lineno, frame.name))
[423] Fix | Delete
if frame.line:
[424] Fix | Delete
row.append(' {}\n'.format(frame.line.strip()))
[425] Fix | Delete
if frame.locals:
[426] Fix | Delete
for name, value in sorted(frame.locals.items()):
[427] Fix | Delete
row.append(' {name} = {value}\n'.format(name=name, value=value))
[428] Fix | Delete
result.append(''.join(row))
[429] Fix | Delete
if count > _RECURSIVE_CUTOFF:
[430] Fix | Delete
count -= _RECURSIVE_CUTOFF
[431] Fix | Delete
result.append(
[432] Fix | Delete
f' [Previous line repeated {count} more '
[433] Fix | Delete
f'time{"s" if count > 1 else ""}]\n'
[434] Fix | Delete
)
[435] Fix | Delete
return result
[436] Fix | Delete
[437] Fix | Delete
[438] Fix | Delete
class TracebackException:
[439] Fix | Delete
"""An exception ready for rendering.
[440] Fix | Delete
[441] Fix | Delete
The traceback module captures enough attributes from the original exception
[442] Fix | Delete
to this intermediary form to ensure that no references are held, while
[443] Fix | Delete
still being able to fully print or format it.
[444] Fix | Delete
[445] Fix | Delete
Use `from_exception` to create TracebackException instances from exception
[446] Fix | Delete
objects, or the constructor to create TracebackException instances from
[447] Fix | Delete
individual components.
[448] Fix | Delete
[449] Fix | Delete
- :attr:`__cause__` A TracebackException of the original *__cause__*.
[450] Fix | Delete
- :attr:`__context__` A TracebackException of the original *__context__*.
[451] Fix | Delete
- :attr:`__suppress_context__` The *__suppress_context__* value from the
[452] Fix | Delete
original exception.
[453] Fix | Delete
- :attr:`stack` A `StackSummary` representing the traceback.
[454] Fix | Delete
- :attr:`exc_type` The class of the original traceback.
[455] Fix | Delete
- :attr:`filename` For syntax errors - the filename where the error
[456] Fix | Delete
occurred.
[457] Fix | Delete
- :attr:`lineno` For syntax errors - the linenumber where the error
[458] Fix | Delete
occurred.
[459] Fix | Delete
- :attr:`text` For syntax errors - the text where the error
[460] Fix | Delete
occurred.
[461] Fix | Delete
- :attr:`offset` For syntax errors - the offset into the text where the
[462] Fix | Delete
error occurred.
[463] Fix | Delete
- :attr:`msg` For syntax errors - the compiler error message.
[464] Fix | Delete
"""
[465] Fix | Delete
[466] Fix | Delete
def __init__(self, exc_type, exc_value, exc_traceback, *, limit=None,
[467] Fix | Delete
lookup_lines=True, capture_locals=False, _seen=None):
[468] Fix | Delete
# NB: we need to accept exc_traceback, exc_value, exc_traceback to
[469] Fix | Delete
# permit backwards compat with the existing API, otherwise we
[470] Fix | Delete
# need stub thunk objects just to glue it together.
[471] Fix | Delete
# Handle loops in __cause__ or __context__.
[472] Fix | Delete
if _seen is None:
[473] Fix | Delete
_seen = set()
[474] Fix | Delete
_seen.add(id(exc_value))
[475] Fix | Delete
# Gracefully handle (the way Python 2.4 and earlier did) the case of
[476] Fix | Delete
# being called with no type or value (None, None, None).
[477] Fix | Delete
if (exc_value and exc_value.__cause__ is not None
[478] Fix | Delete
and id(exc_value.__cause__) not in _seen):
[479] Fix | Delete
cause = TracebackException(
[480] Fix | Delete
type(exc_value.__cause__),
[481] Fix | Delete
exc_value.__cause__,
[482] Fix | Delete
exc_value.__cause__.__traceback__,
[483] Fix | Delete
limit=limit,
[484] Fix | Delete
lookup_lines=False,
[485] Fix | Delete
capture_locals=capture_locals,
[486] Fix | Delete
_seen=_seen)
[487] Fix | Delete
else:
[488] Fix | Delete
cause = None
[489] Fix | Delete
if (exc_value and exc_value.__context__ is not None
[490] Fix | Delete
and id(exc_value.__context__) not in _seen):
[491] Fix | Delete
context = TracebackException(
[492] Fix | Delete
type(exc_value.__context__),
[493] Fix | Delete
exc_value.__context__,
[494] Fix | Delete
exc_value.__context__.__traceback__,
[495] Fix | Delete
limit=limit,
[496] Fix | Delete
lookup_lines=False,
[497] Fix | Delete
capture_locals=capture_locals,
[498] Fix | Delete
_seen=_seen)
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function