Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../usr/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 = \
[259] Fix | Delete
dict((k, repr(v)) for k, v in locals.items()) if locals else None
[260] Fix | Delete
[261] Fix | Delete
def __eq__(self, other):
[262] Fix | Delete
if isinstance(other, FrameSummary):
[263] Fix | Delete
return (self.filename == other.filename and
[264] Fix | Delete
self.lineno == other.lineno and
[265] Fix | Delete
self.name == other.name and
[266] Fix | Delete
self.locals == other.locals)
[267] Fix | Delete
if isinstance(other, tuple):
[268] Fix | Delete
return (self.filename, self.lineno, self.name, self.line) == other
[269] Fix | Delete
return NotImplemented
[270] Fix | Delete
[271] Fix | Delete
def __getitem__(self, pos):
[272] Fix | Delete
return (self.filename, self.lineno, self.name, self.line)[pos]
[273] Fix | Delete
[274] Fix | Delete
def __iter__(self):
[275] Fix | Delete
return iter([self.filename, self.lineno, self.name, self.line])
[276] Fix | Delete
[277] Fix | Delete
def __repr__(self):
[278] Fix | Delete
return "<FrameSummary file {filename}, line {lineno} in {name}>".format(
[279] Fix | Delete
filename=self.filename, lineno=self.lineno, name=self.name)
[280] Fix | Delete
[281] Fix | Delete
@property
[282] Fix | Delete
def line(self):
[283] Fix | Delete
if self._line is None:
[284] Fix | Delete
self._line = linecache.getline(self.filename, self.lineno).strip()
[285] Fix | Delete
return self._line
[286] Fix | Delete
[287] Fix | Delete
[288] Fix | Delete
def walk_stack(f):
[289] Fix | Delete
"""Walk a stack yielding the frame and line number for each frame.
[290] Fix | Delete
[291] Fix | Delete
This will follow f.f_back from the given frame. If no frame is given, the
[292] Fix | Delete
current stack is used. Usually used with StackSummary.extract.
[293] Fix | Delete
"""
[294] Fix | Delete
if f is None:
[295] Fix | Delete
f = sys._getframe().f_back.f_back
[296] Fix | Delete
while f is not None:
[297] Fix | Delete
yield f, f.f_lineno
[298] Fix | Delete
f = f.f_back
[299] Fix | Delete
[300] Fix | Delete
[301] Fix | Delete
def walk_tb(tb):
[302] Fix | Delete
"""Walk a traceback yielding the frame and line number for each frame.
[303] Fix | Delete
[304] Fix | Delete
This will follow tb.tb_next (and thus is in the opposite order to
[305] Fix | Delete
walk_stack). Usually used with StackSummary.extract.
[306] Fix | Delete
"""
[307] Fix | Delete
while tb is not None:
[308] Fix | Delete
yield tb.tb_frame, tb.tb_lineno
[309] Fix | Delete
tb = tb.tb_next
[310] Fix | Delete
[311] Fix | Delete
[312] Fix | Delete
_RECURSIVE_CUTOFF = 3 # Also hardcoded in traceback.c.
[313] Fix | Delete
[314] Fix | Delete
class StackSummary(list):
[315] Fix | Delete
"""A stack of frames."""
[316] Fix | Delete
[317] Fix | Delete
@classmethod
[318] Fix | Delete
def extract(klass, frame_gen, *, limit=None, lookup_lines=True,
[319] Fix | Delete
capture_locals=False):
[320] Fix | Delete
"""Create a StackSummary from a traceback or stack object.
[321] Fix | Delete
[322] Fix | Delete
:param frame_gen: A generator that yields (frame, lineno) tuples to
[323] Fix | Delete
include in the stack.
[324] Fix | Delete
:param limit: None to include all frames or the number of frames to
[325] Fix | Delete
include.
[326] Fix | Delete
:param lookup_lines: If True, lookup lines for each frame immediately,
[327] Fix | Delete
otherwise lookup is deferred until the frame is rendered.
[328] Fix | Delete
:param capture_locals: If True, the local variables from each frame will
[329] Fix | Delete
be captured as object representations into the FrameSummary.
[330] Fix | Delete
"""
[331] Fix | Delete
if limit is None:
[332] Fix | Delete
limit = getattr(sys, 'tracebacklimit', None)
[333] Fix | Delete
if limit is not None and limit < 0:
[334] Fix | Delete
limit = 0
[335] Fix | Delete
if limit is not None:
[336] Fix | Delete
if limit >= 0:
[337] Fix | Delete
frame_gen = itertools.islice(frame_gen, limit)
[338] Fix | Delete
else:
[339] Fix | Delete
frame_gen = collections.deque(frame_gen, maxlen=-limit)
[340] Fix | Delete
[341] Fix | Delete
result = klass()
[342] Fix | Delete
fnames = set()
[343] Fix | Delete
for f, lineno in frame_gen:
[344] Fix | Delete
co = f.f_code
[345] Fix | Delete
filename = co.co_filename
[346] Fix | Delete
name = co.co_name
[347] Fix | Delete
[348] Fix | Delete
fnames.add(filename)
[349] Fix | Delete
linecache.lazycache(filename, f.f_globals)
[350] Fix | Delete
# Must defer line lookups until we have called checkcache.
[351] Fix | Delete
if capture_locals:
[352] Fix | Delete
f_locals = f.f_locals
[353] Fix | Delete
else:
[354] Fix | Delete
f_locals = None
[355] Fix | Delete
result.append(FrameSummary(
[356] Fix | Delete
filename, lineno, name, lookup_line=False, locals=f_locals))
[357] Fix | Delete
for filename in fnames:
[358] Fix | Delete
linecache.checkcache(filename)
[359] Fix | Delete
# If immediate lookup was desired, trigger lookups now.
[360] Fix | Delete
if lookup_lines:
[361] Fix | Delete
for f in result:
[362] Fix | Delete
f.line
[363] Fix | Delete
return result
[364] Fix | Delete
[365] Fix | Delete
@classmethod
[366] Fix | Delete
def from_list(klass, a_list):
[367] Fix | Delete
"""
[368] Fix | Delete
Create a StackSummary object from a supplied list of
[369] Fix | Delete
FrameSummary objects or old-style list of tuples.
[370] Fix | Delete
"""
[371] Fix | Delete
# While doing a fast-path check for isinstance(a_list, StackSummary) is
[372] Fix | Delete
# appealing, idlelib.run.cleanup_traceback and other similar code may
[373] Fix | Delete
# break this by making arbitrary frames plain tuples, so we need to
[374] Fix | Delete
# check on a frame by frame basis.
[375] Fix | Delete
result = StackSummary()
[376] Fix | Delete
for frame in a_list:
[377] Fix | Delete
if isinstance(frame, FrameSummary):
[378] Fix | Delete
result.append(frame)
[379] Fix | Delete
else:
[380] Fix | Delete
filename, lineno, name, line = frame
[381] Fix | Delete
result.append(FrameSummary(filename, lineno, name, line=line))
[382] Fix | Delete
return result
[383] Fix | Delete
[384] Fix | Delete
def format(self):
[385] Fix | Delete
"""Format the stack ready for printing.
[386] Fix | Delete
[387] Fix | Delete
Returns a list of strings ready for printing. Each string in the
[388] Fix | Delete
resulting list corresponds to a single frame from the stack.
[389] Fix | Delete
Each string ends in a newline; the strings may contain internal
[390] Fix | Delete
newlines as well, for those items with source text lines.
[391] Fix | Delete
[392] Fix | Delete
For long sequences of the same frame and line, the first few
[393] Fix | Delete
repetitions are shown, followed by a summary line stating the exact
[394] Fix | Delete
number of further repetitions.
[395] Fix | Delete
"""
[396] Fix | Delete
result = []
[397] Fix | Delete
last_file = None
[398] Fix | Delete
last_line = None
[399] Fix | Delete
last_name = None
[400] Fix | Delete
count = 0
[401] Fix | Delete
for frame in self:
[402] Fix | Delete
if (last_file is None or last_file != frame.filename or
[403] Fix | Delete
last_line is None or last_line != frame.lineno or
[404] Fix | Delete
last_name is None or last_name != frame.name):
[405] Fix | Delete
if count > _RECURSIVE_CUTOFF:
[406] Fix | Delete
count -= _RECURSIVE_CUTOFF
[407] Fix | Delete
result.append(
[408] Fix | Delete
f' [Previous line repeated {count} more '
[409] Fix | Delete
f'time{"s" if count > 1 else ""}]\n'
[410] Fix | Delete
)
[411] Fix | Delete
last_file = frame.filename
[412] Fix | Delete
last_line = frame.lineno
[413] Fix | Delete
last_name = frame.name
[414] Fix | Delete
count = 0
[415] Fix | Delete
count += 1
[416] Fix | Delete
if count > _RECURSIVE_CUTOFF:
[417] Fix | Delete
continue
[418] Fix | Delete
row = []
[419] Fix | Delete
row.append(' File "{}", line {}, in {}\n'.format(
[420] Fix | Delete
frame.filename, frame.lineno, frame.name))
[421] Fix | Delete
if frame.line:
[422] Fix | Delete
row.append(' {}\n'.format(frame.line.strip()))
[423] Fix | Delete
if frame.locals:
[424] Fix | Delete
for name, value in sorted(frame.locals.items()):
[425] Fix | Delete
row.append(' {name} = {value}\n'.format(name=name, value=value))
[426] Fix | Delete
result.append(''.join(row))
[427] Fix | Delete
if count > _RECURSIVE_CUTOFF:
[428] Fix | Delete
count -= _RECURSIVE_CUTOFF
[429] Fix | Delete
result.append(
[430] Fix | Delete
f' [Previous line repeated {count} more '
[431] Fix | Delete
f'time{"s" if count > 1 else ""}]\n'
[432] Fix | Delete
)
[433] Fix | Delete
return result
[434] Fix | Delete
[435] Fix | Delete
[436] Fix | Delete
class TracebackException:
[437] Fix | Delete
"""An exception ready for rendering.
[438] Fix | Delete
[439] Fix | Delete
The traceback module captures enough attributes from the original exception
[440] Fix | Delete
to this intermediary form to ensure that no references are held, while
[441] Fix | Delete
still being able to fully print or format it.
[442] Fix | Delete
[443] Fix | Delete
Use `from_exception` to create TracebackException instances from exception
[444] Fix | Delete
objects, or the constructor to create TracebackException instances from
[445] Fix | Delete
individual components.
[446] Fix | Delete
[447] Fix | Delete
- :attr:`__cause__` A TracebackException of the original *__cause__*.
[448] Fix | Delete
- :attr:`__context__` A TracebackException of the original *__context__*.
[449] Fix | Delete
- :attr:`__suppress_context__` The *__suppress_context__* value from the
[450] Fix | Delete
original exception.
[451] Fix | Delete
- :attr:`stack` A `StackSummary` representing the traceback.
[452] Fix | Delete
- :attr:`exc_type` The class of the original traceback.
[453] Fix | Delete
- :attr:`filename` For syntax errors - the filename where the error
[454] Fix | Delete
occurred.
[455] Fix | Delete
- :attr:`lineno` For syntax errors - the linenumber where the error
[456] Fix | Delete
occurred.
[457] Fix | Delete
- :attr:`text` For syntax errors - the text where the error
[458] Fix | Delete
occurred.
[459] Fix | Delete
- :attr:`offset` For syntax errors - the offset into the text where the
[460] Fix | Delete
error occurred.
[461] Fix | Delete
- :attr:`msg` For syntax errors - the compiler error message.
[462] Fix | Delete
"""
[463] Fix | Delete
[464] Fix | Delete
def __init__(self, exc_type, exc_value, exc_traceback, *, limit=None,
[465] Fix | Delete
lookup_lines=True, capture_locals=False, _seen=None):
[466] Fix | Delete
# NB: we need to accept exc_traceback, exc_value, exc_traceback to
[467] Fix | Delete
# permit backwards compat with the existing API, otherwise we
[468] Fix | Delete
# need stub thunk objects just to glue it together.
[469] Fix | Delete
# Handle loops in __cause__ or __context__.
[470] Fix | Delete
if _seen is None:
[471] Fix | Delete
_seen = set()
[472] Fix | Delete
_seen.add(id(exc_value))
[473] Fix | Delete
# Gracefully handle (the way Python 2.4 and earlier did) the case of
[474] Fix | Delete
# being called with no type or value (None, None, None).
[475] Fix | Delete
if (exc_value and exc_value.__cause__ is not None
[476] Fix | Delete
and id(exc_value.__cause__) not in _seen):
[477] Fix | Delete
cause = TracebackException(
[478] Fix | Delete
type(exc_value.__cause__),
[479] Fix | Delete
exc_value.__cause__,
[480] Fix | Delete
exc_value.__cause__.__traceback__,
[481] Fix | Delete
limit=limit,
[482] Fix | Delete
lookup_lines=False,
[483] Fix | Delete
capture_locals=capture_locals,
[484] Fix | Delete
_seen=_seen)
[485] Fix | Delete
else:
[486] Fix | Delete
cause = None
[487] Fix | Delete
if (exc_value and exc_value.__context__ is not None
[488] Fix | Delete
and id(exc_value.__context__) not in _seen):
[489] Fix | Delete
context = TracebackException(
[490] Fix | Delete
type(exc_value.__context__),
[491] Fix | Delete
exc_value.__context__,
[492] Fix | Delete
exc_value.__context__.__traceback__,
[493] Fix | Delete
limit=limit,
[494] Fix | Delete
lookup_lines=False,
[495] Fix | Delete
capture_locals=capture_locals,
[496] Fix | Delete
_seen=_seen)
[497] Fix | Delete
else:
[498] Fix | Delete
context = None
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function