Server: appserver-7f0f8755-nginx-15961cad18524ec5a9db05f2a6a7e440
Current directory: /usr/lib/python3.11
Software: nginx/1.27.5
Shell Command
Create a new file
Upload file
File: traceback.py
"""Extract, format and print information about Python stack traces.""" import collections.abc import itertools import linecache import sys import textwrap from contextlib import suppress __all__ = ['extract_stack', 'extract_tb', 'format_exception', 'format_exception_only', 'format_list', 'format_stack', 'format_tb', 'print_exc', 'format_exc', 'print_exception', 'print_last', 'print_stack', 'print_tb', 'clear_frames', 'FrameSummary', 'StackSummary', 'TracebackException', 'walk_stack', 'walk_tb'] # # Formatting and printing lists of traceback lines. # def print_list(extracted_list, file=None): """Print the list of tuples as returned by extract_tb() or extract_stack() as a formatted stack trace to the given file.""" if file is None: file = sys.stderr for item in StackSummary.from_list(extracted_list).format(): print(item, file=file, end="") def format_list(extracted_list): """Format a list of tuples or FrameSummary objects for printing. Given a list of tuples or FrameSummary objects as returned by extract_tb() or extract_stack(), return a list of strings ready for printing. Each string in the resulting list corresponds to the item with the same index in the argument list. Each string ends in a newline; the strings may contain internal newlines as well, for those items whose source text line is not None. """ return StackSummary.from_list(extracted_list).format() # # Printing and Extracting Tracebacks. # def print_tb(tb, limit=None, file=None): """Print up to 'limit' stack trace entries from the traceback 'tb'. If 'limit' is omitted or None, all entries are printed. If 'file' is omitted or None, the output goes to sys.stderr; otherwise 'file' should be an open file or file-like object with a write() method. """ print_list(extract_tb(tb, limit=limit), file=file) def format_tb(tb, limit=None): """A shorthand for 'format_list(extract_tb(tb, limit))'.""" return extract_tb(tb, limit=limit).format() def extract_tb(tb, limit=None): """ Return a StackSummary object representing a list of pre-processed entries from traceback. This is useful for alternate formatting of stack traces. If 'limit' is omitted or None, all entries are extracted. A pre-processed stack trace entry is a FrameSummary object containing attributes filename, lineno, name, and line representing the information that is usually printed for a stack trace. The line is a string with leading and trailing whitespace stripped; if the source is not available it is None. """ return StackSummary._extract_from_extended_frame_gen( _walk_tb_with_full_positions(tb), limit=limit) # # Exception formatting and output. # _cause_message = ( "\nThe above exception was the direct cause " "of the following exception:\n\n") _context_message = ( "\nDuring handling of the above exception, " "another exception occurred:\n\n") class _Sentinel: def __repr__(self): return "
" _sentinel = _Sentinel() def _parse_value_tb(exc, value, tb): if (value is _sentinel) != (tb is _sentinel): raise ValueError("Both or neither of value and tb must be given") if value is tb is _sentinel: if exc is not None: if isinstance(exc, BaseException): return exc, exc.__traceback__ raise TypeError(f'Exception expected for value, ' f'{type(exc).__name__} found') else: return None, None return value, tb def print_exception(exc, /, value=_sentinel, tb=_sentinel, limit=None, \ file=None, chain=True): """Print exception up to 'limit' stack trace entries from 'tb' to 'file'. This differs from print_tb() in the following ways: (1) if traceback is not None, it prints a header "Traceback (most recent call last):"; (2) it prints the exception type and value after the stack trace; (3) if type is SyntaxError and value has the appropriate format, it prints the line where the syntax error occurred with a caret on the next line indicating the approximate position of the error. """ value, tb = _parse_value_tb(exc, value, tb) te = TracebackException(type(value), value, tb, limit=limit, compact=True) te.print(file=file, chain=chain) def format_exception(exc, /, value=_sentinel, tb=_sentinel, limit=None, \ chain=True): """Format a stack trace and the exception information. The arguments have the same meaning as the corresponding arguments to print_exception(). The return value is a list of strings, each ending in a newline and some containing internal newlines. When these lines are concatenated and printed, exactly the same text is printed as does print_exception(). """ value, tb = _parse_value_tb(exc, value, tb) te = TracebackException(type(value), value, tb, limit=limit, compact=True) return list(te.format(chain=chain)) def format_exception_only(exc, /, value=_sentinel): """Format the exception part of a traceback. 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. """ if value is _sentinel: value = exc te = TracebackException(type(value), value, None, compact=True) return list(te.format_exception_only()) # -- not official API but folk probably use these two functions. def _format_final_exc_line(etype, value): valuestr = _safe_string(value, 'exception') if value is None or not valuestr: line = "%s\n" % etype else: line = "%s: %s\n" % (etype, valuestr) return line def _safe_string(value, what, func=str): try: return func(value) except: return f'<{what} {func.__name__}() failed>' # -- def print_exc(limit=None, file=None, chain=True): """Shorthand for 'print_exception(*sys.exc_info(), limit, file)'.""" print_exception(*sys.exc_info(), limit=limit, file=file, chain=chain) def format_exc(limit=None, chain=True): """Like print_exc() but return a string.""" return "".join(format_exception(*sys.exc_info(), limit=limit, chain=chain)) def print_last(limit=None, file=None, chain=True): """This is a shorthand for 'print_exception(sys.last_type, sys.last_value, sys.last_traceback, limit, file)'.""" if not hasattr(sys, "last_type"): raise ValueError("no last exception") print_exception(sys.last_type, sys.last_value, sys.last_traceback, limit, file, chain) # # Printing and Extracting Stacks. # def print_stack(f=None, limit=None, file=None): """Print a stack trace from its invocation point. The optional 'f' argument can be used to specify an alternate stack frame at which to start. The optional 'limit' and 'file' arguments have the same meaning as for print_exception(). """ if f is None: f = sys._getframe().f_back print_list(extract_stack(f, limit=limit), file=file) def format_stack(f=None, limit=None): """Shorthand for 'format_list(extract_stack(f, limit))'.""" if f is None: f = sys._getframe().f_back return format_list(extract_stack(f, limit=limit)) def extract_stack(f=None, limit=None): """Extract the raw traceback from the current stack frame. The return value has the same format as for extract_tb(). The optional 'f' and 'limit' arguments have the same meaning as for print_stack(). Each item in the list is a quadruple (filename, line number, function name, text), and the entries are in order from oldest to newest stack frame. """ if f is None: f = sys._getframe().f_back stack = StackSummary.extract(walk_stack(f), limit=limit) stack.reverse() return stack def clear_frames(tb): "Clear all references to local variables in the frames of a traceback." while tb is not None: try: tb.tb_frame.clear() except RuntimeError: # Ignore the exception raised if the frame is still executing. pass tb = tb.tb_next class FrameSummary: """Information about a single frame from a traceback. - :attr:`filename` The filename for the frame. - :attr:`lineno` The line within filename for the frame that was active when the frame was captured. - :attr:`name` The name of the function or method that was executing when the frame was captured. - :attr:`line` The text from the linecache module for the of code that was running when the frame was captured. - :attr:`locals` Either None if locals were not supplied, or a dict mapping the name to the repr() of the variable. """ __slots__ = ('filename', 'lineno', 'end_lineno', 'colno', 'end_colno', 'name', '_line', 'locals') def __init__(self, filename, lineno, name, *, lookup_line=True, locals=None, line=None, end_lineno=None, colno=None, end_colno=None): """Construct a FrameSummary. :param lookup_line: If True, `linecache` is consulted for the source code line. Otherwise, the line will be looked up when first needed. :param locals: If supplied the frame locals, which will be captured as object representations. :param line: If provided, use this instead of looking up the line in the linecache. """ self.filename = filename self.lineno = lineno self.name = name self._line = line if lookup_line: self.line self.locals = {k: repr(v) for k, v in locals.items()} if locals else None self.end_lineno = end_lineno self.colno = colno self.end_colno = end_colno def __eq__(self, other): if isinstance(other, FrameSummary): return (self.filename == other.filename and self.lineno == other.lineno and self.name == other.name and self.locals == other.locals) if isinstance(other, tuple): return (self.filename, self.lineno, self.name, self.line) == other return NotImplemented def __getitem__(self, pos): return (self.filename, self.lineno, self.name, self.line)[pos] def __iter__(self): return iter([self.filename, self.lineno, self.name, self.line]) def __repr__(self): return "
".format( filename=self.filename, lineno=self.lineno, name=self.name) def __len__(self): return 4 @property def _original_line(self): # Returns the line as-is from the source, without modifying whitespace. self.line return self._line @property def line(self): if self._line is None: if self.lineno is None: return None self._line = linecache.getline(self.filename, self.lineno) return self._line.strip() def walk_stack(f): """Walk a stack yielding the frame and line number for each frame. This will follow f.f_back from the given frame. If no frame is given, the current stack is used. Usually used with StackSummary.extract. """ if f is None: f = sys._getframe().f_back.f_back.f_back.f_back while f is not None: yield f, f.f_lineno f = f.f_back def walk_tb(tb): """Walk a traceback yielding the frame and line number for each frame. This will follow tb.tb_next (and thus is in the opposite order to walk_stack). Usually used with StackSummary.extract. """ while tb is not None: yield tb.tb_frame, tb.tb_lineno tb = tb.tb_next def _walk_tb_with_full_positions(tb): # Internal version of walk_tb that yields full code positions including # end line and column information. while tb is not None: positions = _get_code_position(tb.tb_frame.f_code, tb.tb_lasti) # Yield tb_lineno when co_positions does not have a line number to # maintain behavior with walk_tb. if positions[0] is None: yield tb.tb_frame, (tb.tb_lineno, ) + positions[1:] else: yield tb.tb_frame, positions tb = tb.tb_next def _get_code_position(code, instruction_index): if instruction_index < 0: return (None, None, None, None) positions_gen = code.co_positions() return next(itertools.islice(positions_gen, instruction_index // 2, None)) _RECURSIVE_CUTOFF = 3 # Also hardcoded in traceback.c. class StackSummary(list): """A list of FrameSummary objects, representing a stack of frames.""" @classmethod def extract(klass, frame_gen, *, limit=None, lookup_lines=True, capture_locals=False): """Create a StackSummary from a traceback or stack object. :param frame_gen: A generator that yields (frame, lineno) tuples whose summaries are to be included in the stack. :param limit: None to include all frames or the number of frames to include. :param lookup_lines: If True, lookup lines for each frame immediately, otherwise lookup is deferred until the frame is rendered. :param capture_locals: If True, the local variables from each frame will be captured as object representations into the FrameSummary. """ def extended_frame_gen(): for f, lineno in frame_gen: yield f, (lineno, None, None, None) return klass._extract_from_extended_frame_gen( extended_frame_gen(), limit=limit, lookup_lines=lookup_lines, capture_locals=capture_locals) @classmethod def _extract_from_extended_frame_gen(klass, frame_gen, *, limit=None, lookup_lines=True, capture_locals=False): # Same as extract but operates on a frame generator that yields # (frame, (lineno, end_lineno, colno, end_colno)) in the stack. # Only lineno is required, the remaining fields can be None if the # information is not available. if limit is None: limit = getattr(sys, 'tracebacklimit', None) if limit is not None and limit < 0: limit = 0 if limit is not None: if limit >= 0: frame_gen = itertools.islice(frame_gen, limit) else: frame_gen = collections.deque(frame_gen, maxlen=-limit) result = klass() fnames = set() for f, (lineno, end_lineno, colno, end_colno) in frame_gen: co = f.f_code filename = co.co_filename name = co.co_name fnames.add(filename) linecache.lazycache(filename, f.f_globals) # Must defer line lookups until we have called checkcache. if capture_locals: f_locals = f.f_locals else: f_locals = None result.append(FrameSummary( filename, lineno, name, lookup_line=False, locals=f_locals, end_lineno=end_lineno, colno=colno, end_colno=end_colno)) for filename in fnames: linecache.checkcache(filename) # If immediate lookup was desired, trigger lookups now. if lookup_lines: for f in result: f.line return result @classmethod def from_list(klass, a_list): """ Create a StackSummary object from a supplied list of FrameSummary objects or old-style list of tuples. """ # While doing a fast-path check for isinstance(a_list, StackSummary) is # appealing, idlelib.run.cleanup_traceback and other similar code may # break this by making arbitrary frames plain tuples, so we need to # check on a frame by frame basis. result = StackSummary() for frame in a_list: if isinstance(frame, FrameSummary): result.append(frame) else: filename, lineno, name, line = frame result.append(FrameSummary(filename, lineno, name, line=line)) return result def format_frame_summary(self, frame_summary): """Format the lines for a single FrameSummary. Returns a string representing one frame involved in the stack. This gets called for every frame to be printed in the stack summary. """ row = [] row.append(' File "{}", line {}, in {}\n'.format( frame_summary.filename, frame_summary.lineno, frame_summary.name)) if frame_summary.line: stripped_line = frame_summary.line.strip() row.append(' {}\n'.format(stripped_line)) orig_line_len = len(frame_summary._original_line) frame_line_len = len(frame_summary.line.lstrip()) stripped_characters = orig_line_len - frame_line_len if ( frame_summary.colno is not None and frame_summary.end_colno is not None ): start_offset = _byte_offset_to_character_offset( frame_summary._original_line, frame_summary.colno) + 1 end_offset = _byte_offset_to_character_offset( frame_summary._original_line, frame_summary.end_colno) + 1 anchors = None if frame_summary.lineno == frame_summary.end_lineno: with suppress(Exception): anchors = _extract_caret_anchors_from_line_segment( frame_summary._original_line[start_offset - 1:end_offset - 1] ) else: end_offset = stripped_characters + len(stripped_line) # show indicators if primary char doesn't span the frame line if end_offset - start_offset < len(stripped_line) or ( anchors and anchors.right_start_offset - anchors.left_end_offset > 0): row.append(' ') row.append(' ' * (start_offset - stripped_characters)) if anchors: row.append(anchors.primary_char * (anchors.left_end_offset)) row.append(anchors.secondary_char * (anchors.right_start_offset - anchors.left_end_offset)) row.append(anchors.primary_char * (end_offset - start_offset - anchors.right_start_offset)) else: row.append('^' * (end_offset - start_offset)) row.append('\n') if frame_summary.locals: for name, value in sorted(frame_summary.locals.items()): row.append(' {name} = {value}\n'.format(name=name, value=value)) return ''.join(row) def format(self): """Format the stack ready for printing. Returns a list of strings ready for printing. Each string in the resulting list corresponds to a single frame from the stack. Each string ends in a newline; the strings may contain internal newlines as well, for those items with source text lines. For long sequences of the same frame and line, the first few repetitions are shown, followed by a summary line stating the exact number of further repetitions. """ result = [] last_file = None last_line = None last_name = None count = 0 for frame_summary in self: formatted_frame = self.format_frame_summary(frame_summary) if formatted_frame is None: continue if (last_file is None or last_file != frame_summary.filename or last_line is None or last_line != frame_summary.lineno or last_name is None or last_name != frame_summary.name): if count > _RECURSIVE_CUTOFF: count -= _RECURSIVE_CUTOFF result.append( f' [Previous line repeated {count} more ' f'time{"s" if count > 1 else ""}]\n' ) last_file = frame_summary.filename last_line = frame_summary.lineno last_name = frame_summary.name count = 0 count += 1 if count > _RECURSIVE_CUTOFF: continue result.append(formatted_frame) if count > _RECURSIVE_CUTOFF: count -= _RECURSIVE_CUTOFF result.append( f' [Previous line repeated {count} more ' f'time{"s" if count > 1 else ""}]\n' ) return result def _byte_offset_to_character_offset(str, offset): as_utf8 = str.encode('utf-8') return len(as_utf8[:offset].decode("utf-8", errors="replace")) _Anchors = collections.namedtuple( "_Anchors", [ "left_end_offset", "right_start_offset", "primary_char", "secondary_char", ], defaults=["~", "^"] ) def _extract_caret_anchors_from_line_segment(segment): import ast try: tree = ast.parse(segment) except SyntaxError: return None if len(tree.body) != 1: return None normalize = lambda offset: _byte_offset_to_character_offset(segment, offset) statement = tree.body[0] match statement: case ast.Expr(expr): match expr: case ast.BinOp(): operator_start = normalize(expr.left.end_col_offset) operator_end = normalize(expr.right.col_offset) operator_str = segment[operator_start:operator_end] operator_offset = len(operator_str) - len(operator_str.lstrip()) left_anchor = expr.left.end_col_offset + operator_offset right_anchor = left_anchor + 1 if ( operator_offset + 1 < len(operator_str) and not operator_str[operator_offset + 1].isspace() ): right_anchor += 1 return _Anchors(normalize(left_anchor), normalize(right_anchor)) case ast.Subscript(): subscript_start = normalize(expr.value.end_col_offset) subscript_end = normalize(expr.slice.end_col_offset + 1) return _Anchors(subscript_start, subscript_end) return None class _ExceptionPrintContext: def __init__(self): self.seen = set() self.exception_group_depth = 0 self.need_close = False def indent(self): return ' ' * (2 * self.exception_group_depth) def emit(self, text_gen, margin_char=None): if margin_char is None: margin_char = '|' indent_str = self.indent() if self.exception_group_depth: indent_str += margin_char + ' ' if isinstance(text_gen, str): yield textwrap.indent(text_gen, indent_str, lambda line: True) else: for text in text_gen: yield textwrap.indent(text, indent_str, lambda line: True) class TracebackException: """An exception ready for rendering. The traceback module captures enough attributes from the original exception to this intermediary form to ensure that no references are held, while still being able to fully print or format it. max_group_width and max_group_depth control the formatting of exception groups. The depth refers to the nesting level of the group, and the width refers to the size of a single exception group's exceptions array. The formatted output is truncated when either limit is exceeded. Use `from_exception` to create TracebackException instances from exception objects, or the constructor to create TracebackException instances from individual components. - :attr:`__cause__` A TracebackException of the original *__cause__*. - :attr:`__context__` A TracebackException of the original *__context__*. - :attr:`__suppress_context__` The *__suppress_context__* value from the original exception. - :attr:`stack` A `StackSummary` representing the traceback. - :attr:`exc_type` The class of the original traceback. - :attr:`filename` For syntax errors - the filename where the error occurred. - :attr:`lineno` For syntax errors - the linenumber where the error occurred. - :attr:`end_lineno` For syntax errors - the end linenumber where the error occurred. Can be `None` if not present. - :attr:`text` For syntax errors - the text where the error occurred. - :attr:`offset` For syntax errors - the offset into the text where the error occurred. - :attr:`end_offset` For syntax errors - the offset into the text where the error occurred. Can be `None` if not present. - :attr:`msg` For syntax errors - the compiler error message. """ def __init__(self, exc_type, exc_value, exc_traceback, *, limit=None, lookup_lines=True, capture_locals=False, compact=False, max_group_width=15, max_group_depth=10, _seen=None): # NB: we need to accept exc_traceback, exc_value, exc_traceback to # permit backwards compat with the existing API, otherwise we # need stub thunk objects just to glue it together. # Handle loops in __cause__ or __context__. is_recursive_call = _seen is not None if _seen is None: _seen = set() _seen.add(id(exc_value)) self.max_group_width = max_group_width self.max_group_depth = max_group_depth self.stack = StackSummary._extract_from_extended_frame_gen( _walk_tb_with_full_positions(exc_traceback), limit=limit, lookup_lines=lookup_lines, capture_locals=capture_locals) self.exc_type = exc_type # Capture now to permit freeing resources: only complication is in the # unofficial API _format_final_exc_line self._str = _safe_string(exc_value, 'exception') self.__notes__ = getattr(exc_value, '__notes__', None) if exc_type and issubclass(exc_type, SyntaxError): # Handle SyntaxError's specially self.filename = exc_value.filename lno = exc_value.lineno self.lineno = str(lno) if lno is not None else None end_lno = exc_value.end_lineno self.end_lineno = str(end_lno) if end_lno is not None else None self.text = exc_value.text self.offset = exc_value.offset self.end_offset = exc_value.end_offset self.msg = exc_value.msg if lookup_lines: self._load_lines() self.__suppress_context__ = \ exc_value.__suppress_context__ if exc_value is not None else False # Convert __cause__ and __context__ to `TracebackExceptions`s, use a # queue to avoid recursion (only the top-level call gets _seen == None) if not is_recursive_call: queue = [(self, exc_value)] while queue: te, e = queue.pop() if (e and e.__cause__ is not None and id(e.__cause__) not in _seen): cause = TracebackException( type(e.__cause__), e.__cause__, e.__cause__.__traceback__, limit=limit, lookup_lines=lookup_lines, capture_locals=capture_locals, max_group_width=max_group_width, max_group_depth=max_group_depth, _seen=_seen) else: cause = None if compact: need_context = (cause is None and e is not None and not e.__suppress_context__) else: need_context = True if (e and e.__context__ is not None and need_context and id(e.__context__) not in _seen): context = TracebackException( type(e.__context__), e.__context__, e.__context__.__traceback__, limit=limit, lookup_lines=lookup_lines, capture_locals=capture_locals, max_group_width=max_group_width, max_group_depth=max_group_depth, _seen=_seen) else: context = None if e and isinstance(e, BaseExceptionGroup): exceptions = [] for exc in e.exceptions: texc = TracebackException( type(exc), exc, exc.__traceback__, limit=limit, lookup_lines=lookup_lines, capture_locals=capture_locals, max_group_width=max_group_width, max_group_depth=max_group_depth, _seen=_seen) exceptions.append(texc) else: exceptions = None te.__cause__ = cause te.__context__ = context te.exceptions = exceptions if cause: queue.append((te.__cause__, e.__cause__)) if context: queue.append((te.__context__, e.__context__)) if exceptions: queue.extend(zip(te.exceptions, e.exceptions)) @classmethod def from_exception(cls, exc, *args, **kwargs): """Create a TracebackException from an exception.""" return cls(type(exc), exc, exc.__traceback__, *args, **kwargs) def _load_lines(self): """Private API. force all lines in the stack to be loaded.""" for frame in self.stack: frame.line def __eq__(self, other): if isinstance(other, TracebackException): return self.__dict__ == other.__dict__ return NotImplemented def __str__(self): return self._str def format_exception_only(self): """Format the exception part of the traceback. The return value is a generator of strings, each ending in a newline. Normally, the generator emits a single string; however, for SyntaxError exceptions, it emits 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 output. """ if self.exc_type is None: yield _format_final_exc_line(None, self._str) return stype = self.exc_type.__qualname__ smod = self.exc_type.__module__ if smod not in ("__main__", "builtins"): if not isinstance(smod, str): smod = "
" stype = smod + '.' + stype if not issubclass(self.exc_type, SyntaxError): yield _format_final_exc_line(stype, self._str) else: yield from self._format_syntax_error(stype) if isinstance(self.__notes__, collections.abc.Sequence): for note in self.__notes__: note = _safe_string(note, 'note') yield from [l + '\n' for l in note.split('\n')] elif self.__notes__ is not None: yield _safe_string(self.__notes__, '__notes__', func=repr) def _format_syntax_error(self, stype): """Format SyntaxError exceptions (internal helper).""" # Show exactly where the problem was found. filename_suffix = '' if self.lineno is not None: yield ' File "{}", line {}\n'.format( self.filename or "
", self.lineno) elif self.filename is not None: filename_suffix = ' ({})'.format(self.filename) text = self.text if text is not None: # text = " foo\n" # rtext = " foo" # ltext = "foo" rtext = text.rstrip('\n') ltext = rtext.lstrip(' \n\f') spaces = len(rtext) - len(ltext) yield ' {}\n'.format(ltext) if self.offset is not None: offset = self.offset end_offset = self.end_offset if self.end_offset not in {None, 0} else offset if offset == end_offset or end_offset == -1: end_offset = offset + 1 # Convert 1-based column offset to 0-based index into stripped text colno = offset - 1 - spaces end_colno = end_offset - 1 - spaces if colno >= 0: # non-space whitespace (likes tabs) must be kept for alignment caretspace = ((c if c.isspace() else ' ') for c in ltext[:colno]) yield ' {}{}'.format("".join(caretspace), ('^' * (end_colno - colno) + "\n")) msg = self.msg or "
" yield "{}: {}{}\n".format(stype, msg, filename_suffix) def format(self, *, chain=True, _ctx=None): """Format the exception. If chain is not *True*, *__cause__* and *__context__* will not be formatted. The return value is a generator of strings, each ending in a newline and some containing internal newlines. `print_exception` is a wrapper around this method which just prints the lines to a file. The message indicating which exception occurred is always the last string in the output. """ if _ctx is None: _ctx = _ExceptionPrintContext() output = [] exc = self if chain: while exc: if exc.__cause__ is not None: chained_msg = _cause_message chained_exc = exc.__cause__ elif (exc.__context__ is not None and not exc.__suppress_context__): chained_msg = _context_message chained_exc = exc.__context__ else: chained_msg = None chained_exc = None output.append((chained_msg, exc)) exc = chained_exc else: output.append((None, exc)) for msg, exc in reversed(output): if msg is not None: yield from _ctx.emit(msg) if exc.exceptions is None: if exc.stack: yield from _ctx.emit('Traceback (most recent call last):\n') yield from _ctx.emit(exc.stack.format()) yield from _ctx.emit(exc.format_exception_only()) elif _ctx.exception_group_depth > self.max_group_depth: # exception group, but depth exceeds limit yield from _ctx.emit( f"... (max_group_depth is {self.max_group_depth})\n") else: # format exception group is_toplevel = (_ctx.exception_group_depth == 0) if is_toplevel: _ctx.exception_group_depth += 1 if exc.stack: yield from _ctx.emit( 'Exception Group Traceback (most recent call last):\n', margin_char = '+' if is_toplevel else None) yield from _ctx.emit(exc.stack.format()) yield from _ctx.emit(exc.format_exception_only()) num_excs = len(exc.exceptions) if num_excs <= self.max_group_width: n = num_excs else: n = self.max_group_width + 1 _ctx.need_close = False for i in range(n): last_exc = (i == n-1) if last_exc: # The closing frame may be added by a recursive call _ctx.need_close = True if self.max_group_width is not None: truncated = (i >= self.max_group_width) else: truncated = False title = f'{i+1}' if not truncated else '...' yield (_ctx.indent() + ('+-' if i==0 else ' ') + f'+---------------- {title} ----------------\n') _ctx.exception_group_depth += 1 if not truncated: yield from exc.exceptions[i].format(chain=chain, _ctx=_ctx) else: remaining = num_excs - self.max_group_width plural = 's' if remaining > 1 else '' yield from _ctx.emit( f"and {remaining} more exception{plural}\n") if last_exc and _ctx.need_close: yield (_ctx.indent() + "+------------------------------------\n") _ctx.need_close = False _ctx.exception_group_depth -= 1 if is_toplevel: assert _ctx.exception_group_depth == 1 _ctx.exception_group_depth = 0 def print(self, *, file=None, chain=True): """Print the result of self.format(chain=chain) to 'file'.""" if file is None: file = sys.stderr for line in self.format(chain=chain): print(line, file=file, end="")
.
204 Items
Change directory
Remove directory
Rename directory
..
72 Items
Change directory
Remove directory
Rename directory
EXTERNALLY-MANAGED
0.63 KB
Edit
Delete
Copy
Move
Remame
LICENSE.txt
13.61 KB
Edit
Delete
Copy
Move
Remame
__future__.py
5.1 KB
Edit
Delete
Copy
Move
Remame
__hello__.py
0.22 KB
Edit
Delete
Copy
Move
Remame
__phello__
3 Items
Change directory
Remove directory
Rename directory
__pycache__
171 Items
Change directory
Remove directory
Rename directory
_aix_support.py
3.31 KB
Edit
Delete
Copy
Move
Remame
_bootsubprocess.py
2.61 KB
Edit
Delete
Copy
Move
Remame
_collections_abc.py
29.49 KB
Edit
Delete
Copy
Move
Remame
_compat_pickle.py
8.56 KB
Edit
Delete
Copy
Move
Remame
_compression.py
5.55 KB
Edit
Delete
Copy
Move
Remame
_distutils_system_mod.py
6.16 KB
Edit
Delete
Copy
Move
Remame
_markupbase.py
14.31 KB
Edit
Delete
Copy
Move
Remame
_osx_support.py
21.28 KB
Edit
Delete
Copy
Move
Remame
_py_abc.py
6.04 KB
Edit
Delete
Copy
Move
Remame
_pydecimal.py
223.83 KB
Edit
Delete
Copy
Move
Remame
_pyio.py
91.83 KB
Edit
Delete
Copy
Move
Remame
_sitebuiltins.py
3.05 KB
Edit
Delete
Copy
Move
Remame
_strptime.py
24.68 KB
Edit
Delete
Copy
Move
Remame
_sysconfigdata__linux_x86_64-linux-gnu.py
42.36 KB
Edit
Delete
Copy
Move
Remame
_sysconfigdata__x86_64-linux-gnu.py
42.36 KB
Edit
Delete
Copy
Move
Remame
_threading_local.py
7.05 KB
Edit
Delete
Copy
Move
Remame
_weakrefset.py
5.75 KB
Edit
Delete
Copy
Move
Remame
abc.py
6.37 KB
Edit
Delete
Copy
Move
Remame
aifc.py
33.41 KB
Edit
Delete
Copy
Move
Remame
antigravity.py
0.49 KB
Edit
Delete
Copy
Move
Remame
argparse.py
97.28 KB
Edit
Delete
Copy
Move
Remame
ast.py
59.25 KB
Edit
Delete
Copy
Move
Remame
asynchat.py
11.3 KB
Edit
Delete
Copy
Move
Remame
asyncio
34 Items
Change directory
Remove directory
Rename directory
asyncore.py
19.83 KB
Edit
Delete
Copy
Move
Remame
base64.py
20.53 KB
Edit
Delete
Copy
Move
Remame
bdb.py
31.59 KB
Edit
Delete
Copy
Move
Remame
bisect.py
3.06 KB
Edit
Delete
Copy
Move
Remame
bz2.py
11.57 KB
Edit
Delete
Copy
Move
Remame
cProfile.py
6.19 KB
Edit
Delete
Copy
Move
Remame
calendar.py
24.17 KB
Edit
Delete
Copy
Move
Remame
cgi.py
33.61 KB
Edit
Delete
Copy
Move
Remame
cgitb.py
12.13 KB
Edit
Delete
Copy
Move
Remame
chunk.py
5.37 KB
Edit
Delete
Copy
Move
Remame
cmd.py
14.52 KB
Edit
Delete
Copy
Move
Remame
code.py
10.37 KB
Edit
Delete
Copy
Move
Remame
codecs.py
35.85 KB
Edit
Delete
Copy
Move
Remame
codeop.py
5.47 KB
Edit
Delete
Copy
Move
Remame
collections
3 Items
Change directory
Remove directory
Rename directory
colorsys.py
3.93 KB
Edit
Delete
Copy
Move
Remame
compileall.py
19.78 KB
Edit
Delete
Copy
Move
Remame
concurrent
3 Items
Change directory
Remove directory
Rename directory
configparser.py
53.96 KB
Edit
Delete
Copy
Move
Remame
contextlib.py
26.44 KB
Edit
Delete
Copy
Move
Remame
contextvars.py
0.13 KB
Edit
Delete
Copy
Move
Remame
copy.py
8.48 KB
Edit
Delete
Copy
Move
Remame
copyreg.py
7.5 KB
Edit
Delete
Copy
Move
Remame
crypt.py
3.82 KB
Edit
Delete
Copy
Move
Remame
csv.py
15.65 KB
Edit
Delete
Copy
Move
Remame
ctypes
6 Items
Change directory
Remove directory
Rename directory
curses
6 Items
Change directory
Remove directory
Rename directory
dataclasses.py
56.5 KB
Edit
Delete
Copy
Move
Remame
datetime.py
89.85 KB
Edit
Delete
Copy
Move
Remame
dbm
5 Items
Change directory
Remove directory
Rename directory
decimal.py
0.31 KB
Edit
Delete
Copy
Move
Remame
difflib.py
81.36 KB
Edit
Delete
Copy
Move
Remame
dis.py
28.28 KB
Edit
Delete
Copy
Move
Remame
distutils
31 Items
Change directory
Remove directory
Rename directory
doctest.py
102.71 KB
Edit
Delete
Copy
Move
Remame
email
23 Items
Change directory
Remove directory
Rename directory
encodings
123 Items
Change directory
Remove directory
Rename directory
enum.py
76.81 KB
Edit
Delete
Copy
Move
Remame
filecmp.py
9.94 KB
Edit
Delete
Copy
Move
Remame
fileinput.py
15.33 KB
Edit
Delete
Copy
Move
Remame
fnmatch.py
5.86 KB
Edit
Delete
Copy
Move
Remame
fractions.py
28 KB
Edit
Delete
Copy
Move
Remame
ftplib.py
34.66 KB
Edit
Delete
Copy
Move
Remame
functools.py
37.51 KB
Edit
Delete
Copy
Move
Remame
genericpath.py
4.86 KB
Edit
Delete
Copy
Move
Remame
getopt.py
7.31 KB
Edit
Delete
Copy
Move
Remame
getpass.py
5.85 KB
Edit
Delete
Copy
Move
Remame
gettext.py
20.8 KB
Edit
Delete
Copy
Move
Remame
glob.py
8.48 KB
Edit
Delete
Copy
Move
Remame
graphlib.py
9.43 KB
Edit
Delete
Copy
Move
Remame
gzip.py
23.51 KB
Edit
Delete
Copy
Move
Remame
hashlib.py
11.49 KB
Edit
Delete
Copy
Move
Remame
heapq.py
22.48 KB
Edit
Delete
Copy
Move
Remame
hmac.py
7.54 KB
Edit
Delete
Copy
Move
Remame
html
4 Items
Change directory
Remove directory
Rename directory
http
6 Items
Change directory
Remove directory
Rename directory
imaplib.py
53.58 KB
Edit
Delete
Copy
Move
Remame
imghdr.py
3.86 KB
Edit
Delete
Copy
Move
Remame
imp.py
10.36 KB
Edit
Delete
Copy
Move
Remame
importlib
12 Items
Change directory
Remove directory
Rename directory
inspect.py
121.28 KB
Edit
Delete
Copy
Move
Remame
io.py
4.14 KB
Edit
Delete
Copy
Move
Remame
ipaddress.py
76.45 KB
Edit
Delete
Copy
Move
Remame
json
6 Items
Change directory
Remove directory
Rename directory
keyword.py
1.04 KB
Edit
Delete
Copy
Move
Remame
lib-dynload
46 Items
Change directory
Remove directory
Rename directory
lib2to3
16 Items
Change directory
Remove directory
Rename directory
linecache.py
5.56 KB
Edit
Delete
Copy
Move
Remame
locale.py
77.15 KB
Edit
Delete
Copy
Move
Remame
logging
4 Items
Change directory
Remove directory
Rename directory
lzma.py
12.97 KB
Edit
Delete
Copy
Move
Remame
mailbox.py
76.95 KB
Edit
Delete
Copy
Move
Remame
mailcap.py
9.15 KB
Edit
Delete
Copy
Move
Remame
mimetypes.py
22.26 KB
Edit
Delete
Copy
Move
Remame
modulefinder.py
23.14 KB
Edit
Delete
Copy
Move
Remame
multiprocessing
23 Items
Change directory
Remove directory
Rename directory
netrc.py
6.77 KB
Edit
Delete
Copy
Move
Remame
nntplib.py
40.12 KB
Edit
Delete
Copy
Move
Remame
ntpath.py
28.95 KB
Edit
Delete
Copy
Move
Remame
nturl2path.py
2.82 KB
Edit
Delete
Copy
Move
Remame
numbers.py
10.11 KB
Edit
Delete
Copy
Move
Remame
opcode.py
10.2 KB
Edit
Delete
Copy
Move
Remame
operator.py
10.71 KB
Edit
Delete
Copy
Move
Remame
optparse.py
58.95 KB
Edit
Delete
Copy
Move
Remame
os.py
38.58 KB
Edit
Delete
Copy
Move
Remame
pathlib.py
47.44 KB
Edit
Delete
Copy
Move
Remame
pdb.py
62.4 KB
Edit
Delete
Copy
Move
Remame
pickle.py
63.43 KB
Edit
Delete
Copy
Move
Remame
pickletools.py
91.29 KB
Edit
Delete
Copy
Move
Remame
pipes.py
8.77 KB
Edit
Delete
Copy
Move
Remame
pkgutil.py
24.04 KB
Edit
Delete
Copy
Move
Remame
platform.py
41.28 KB
Edit
Delete
Copy
Move
Remame
plistlib.py
27.59 KB
Edit
Delete
Copy
Move
Remame
poplib.py
14.84 KB
Edit
Delete
Copy
Move
Remame
posixpath.py
16.61 KB
Edit
Delete
Copy
Move
Remame
pprint.py
23.92 KB
Edit
Delete
Copy
Move
Remame
profile.py
22.33 KB
Edit
Delete
Copy
Move
Remame
pstats.py
28.67 KB
Edit
Delete
Copy
Move
Remame
pty.py
5.09 KB
Edit
Delete
Copy
Move
Remame
py_compile.py
7.69 KB
Edit
Delete
Copy
Move
Remame
pyclbr.py
11.13 KB
Edit
Delete
Copy
Move
Remame
pydoc.py
106.57 KB
Edit
Delete
Copy
Move
Remame
pydoc_data
4 Items
Change directory
Remove directory
Rename directory
queue.py
11.23 KB
Edit
Delete
Copy
Move
Remame
quopri.py
7.1 KB
Edit
Delete
Copy
Move
Remame
random.py
31.41 KB
Edit
Delete
Copy
Move
Remame
re
6 Items
Change directory
Remove directory
Rename directory
reprlib.py
5.31 KB
Edit
Delete
Copy
Move
Remame
rlcompleter.py
7.64 KB
Edit
Delete
Copy
Move
Remame
runpy.py
12.85 KB
Edit
Delete
Copy
Move
Remame
sched.py
6.2 KB
Edit
Delete
Copy
Move
Remame
secrets.py
1.98 KB
Edit
Delete
Copy
Move
Remame
selectors.py
19.03 KB
Edit
Delete
Copy
Move
Remame
shelve.py
8.36 KB
Edit
Delete
Copy
Move
Remame
shlex.py
13.18 KB
Edit
Delete
Copy
Move
Remame
shutil.py
53.58 KB
Edit
Delete
Copy
Move
Remame
signal.py
2.38 KB
Edit
Delete
Copy
Move
Remame
site.py
23.17 KB
Edit
Delete
Copy
Move
Remame
sitecustomize.py
0.15 KB
Edit
Delete
Copy
Move
Remame
smtpd.py
30.43 KB
Edit
Delete
Copy
Move
Remame
smtplib.py
44.35 KB
Edit
Delete
Copy
Move
Remame
sndhdr.py
7.27 KB
Edit
Delete
Copy
Move
Remame
socket.py
36.41 KB
Edit
Delete
Copy
Move
Remame
socketserver.py
26.94 KB
Edit
Delete
Copy
Move
Remame
sqlite3
4 Items
Change directory
Remove directory
Rename directory
sre_compile.py
0.23 KB
Edit
Delete
Copy
Move
Remame
sre_constants.py
0.23 KB
Edit
Delete
Copy
Move
Remame
sre_parse.py
0.22 KB
Edit
Delete
Copy
Move
Remame
ssl.py
52.71 KB
Edit
Delete
Copy
Move
Remame
stat.py
5.36 KB
Edit
Delete
Copy
Move
Remame
statistics.py
46.59 KB
Edit
Delete
Copy
Move
Remame
string.py
11.51 KB
Edit
Delete
Copy
Move
Remame
stringprep.py
12.61 KB
Edit
Delete
Copy
Move
Remame
struct.py
0.25 KB
Edit
Delete
Copy
Move
Remame
subprocess.py
83.74 KB
Edit
Delete
Copy
Move
Remame
sunau.py
18.05 KB
Edit
Delete
Copy
Move
Remame
symtable.py
10.13 KB
Edit
Delete
Copy
Move
Remame
sysconfig.py
31.35 KB
Edit
Delete
Copy
Move
Remame
tabnanny.py
11.03 KB
Edit
Delete
Copy
Move
Remame
tarfile.py
95.25 KB
Edit
Delete
Copy
Move
Remame
telnetlib.py
22.75 KB
Edit
Delete
Copy
Move
Remame
tempfile.py
34.66 KB
Edit
Delete
Copy
Move
Remame
test
10 Items
Change directory
Remove directory
Rename directory
textwrap.py
19.26 KB
Edit
Delete
Copy
Move
Remame
this.py
0.98 KB
Edit
Delete
Copy
Move
Remame
threading.py
56.46 KB
Edit
Delete
Copy
Move
Remame
timeit.py
13.18 KB
Edit
Delete
Copy
Move
Remame
token.py
2.33 KB
Edit
Delete
Copy
Move
Remame
tokenize.py
25.72 KB
Edit
Delete
Copy
Move
Remame
tomllib
5 Items
Change directory
Remove directory
Rename directory
trace.py
28.52 KB
Edit
Delete
Copy
Move
Remame
traceback.py
37.52 KB
Edit
Delete
Copy
Move
Remame
tracemalloc.py
17.62 KB
Edit
Delete
Copy
Move
Remame
tty.py
0.86 KB
Edit
Delete
Copy
Move
Remame
turtle.py
140.97 KB
Edit
Delete
Copy
Move
Remame
types.py
9.83 KB
Edit
Delete
Copy
Move
Remame
typing.py
114.35 KB
Edit
Delete
Copy
Move
Remame
unittest
14 Items
Change directory
Remove directory
Rename directory
urllib
7 Items
Change directory
Remove directory
Rename directory
uu.py
6.86 KB
Edit
Delete
Copy
Move
Remame
uuid.py
26.95 KB
Edit
Delete
Copy
Move
Remame
venv
4 Items
Change directory
Remove directory
Rename directory
warnings.py
20.53 KB
Edit
Delete
Copy
Move
Remame
wave.py
21.33 KB
Edit
Delete
Copy
Move
Remame
weakref.py
21.01 KB
Edit
Delete
Copy
Move
Remame
webbrowser.py
24.5 KB
Edit
Delete
Copy
Move
Remame
wsgiref
8 Items
Change directory
Remove directory
Rename directory
xdrlib.py
5.84 KB
Edit
Delete
Copy
Move
Remame
xml
6 Items
Change directory
Remove directory
Rename directory
xmlrpc
4 Items
Change directory
Remove directory
Rename directory
zipapp.py
7.36 KB
Edit
Delete
Copy
Move
Remame
zipfile.py
90.81 KB
Edit
Delete
Copy
Move
Remame
zipimport.py
30.17 KB
Edit
Delete
Copy
Move
Remame
zoneinfo
5 Items
Change directory
Remove directory
Rename directory