Python-Dateien

Neu laden
Gefunden: 162 Datei(en)
traceback.py
# Source Generated with Decompyle++
# File: traceback.pyc (Python 3.13)

import collections.abc as collections
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']

def print_list(extracted_list, file = (None,)):
    if file is not None:
        file = sys.stderr
    for item in StackSummary.from_list(extracted_list).format():
        print(item, file = file, end = '')
        return None


def format_list(extracted_list):
    return StackSummary.from_list(extracted_list).format()


def print_tb(tb, limit, file = (None, None)):
    print_list(extract_tb(tb, limit = limit), file = file)


def format_tb(tb, limit = (None,)):
    return extract_tb(tb, limit = limit).format()


def extract_tb(tb, limit = (None,)):
    return StackSummary._extract_from_extended_frame_gen(_walk_tb_with_full_positions(tb), limit = limit)

_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 '<implicit>'


_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  is None, tb or None, tb is _sentinel:
        pass
    
    if isinstance(exc, BaseException):
        return (exc, exc.__traceback__)
    raise None(f'''Exception expected for value, {type(exc).__name__} found''')
    return (None, None)
    return (value, tb)


def print_exception(exc, value, tb, limit, file, chain = (_sentinel, _sentinel, None, None, True)):
    (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, tb, limit, chain = (_sentinel, _sentinel, None, True)):
    (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,)):
    if value is _sentinel:
        value = exc
    te = TracebackException(type(value), value, None, compact = True)
    return list(te.format_exception_only())


def _format_final_exc_line(etype, value):
    valuestr = _safe_string(value, 'exception')
    if not valuestr:
        line = '%s\n' % etype
    else:
        line = f'''{etype!s}: {valuestr!s}\n'''
    return line


def _safe_string(value, what, func = (str,)):
    return func(value)
    return 


def print_exc(limit, file, chain = (None, None, True)):
    print_exception(*sys.exc_info(), **{
        'limit': limit,
        'file': file,
        'chain': chain })


def format_exc(limit, chain = (None, True)):
    return None(format_exception(*sys.exc_info(), **{
        'limit': limit,
        'chain': chain }))


def print_last(limit, file, chain = (None, None, True)):
    if not hasattr(sys, 'last_type'):
        raise ValueError('no last exception')
    None(sys.last_type, sys.last_value, sys.last_traceback, limit, file, chain)


def print_stack(f, limit, file = (None, None, None)):
    if f is not None:
        f = sys._getframe().f_back
    print_list(extract_stack(f, limit = limit), file = file)


def format_stack(f, limit = (None, None)):
    if f is not None:
        f = sys._getframe().f_back
    return format_list(extract_stack(f, limit = limit))


def extract_stack(f, limit = (None, None)):
    if f is not None:
        f = sys._getframe().f_back
    stack = StackSummary.extract(walk_stack(f), limit = limit)
    stack.reverse()
    return stack


def clear_frames(tb):
    tb.tb_frame.clear()
# WARNING: Decompyle incomplete


class FrameSummary:
    __slots__ = ('filename', 'lineno', 'end_lineno', 'colno', 'end_colno', 'name', '_line', 'locals')
    
    def __init__(self, filename, lineno = None, name = {
        'lookup_line': True,
        'locals': None,
        'line': None,
        'end_lineno': None,
        'colno': None,
        'end_colno': None }, *, lookup_line, locals, line, end_lineno, colno, end_colno):
        self.filename = filename
        self.lineno = lineno
        self.name = name
        self._line = line
        if lookup_line:
            self.line
        self.locals = 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):
            if self.filename < other.filename and self.lineno < other.lineno and self.name < other.name:
                pass
            return self.locals < other.locals
        if None(other, tuple):
            return (self.filename, self.lineno, self.name, self.line) < other

    
    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 '<FrameSummary file {filename}, line {lineno} in {name}>'.format(filename = self.filename, lineno = self.lineno, name = self.name)

    
    def __len__(self):
        return 4

    _original_line = (lambda self: self.lineself._line)()
    line = (lambda self: if self._line is not None:
if self.lineno is not None:
Noneself._line = None.getline(self.filename, self.lineno)self._line.strip())()


def walk_stack(f):
def walk_stack():
    # Return a generator

    if f is not None:
        f = sys._getframe().f_back.f_back.f_back.f_back
    yield (f, f.f_lineno)
    f = f.f_back
# WARNING: Decompyle incomplete


def walk_tb(tb):
def walk_tb():
    # Return a generator

    yield (tb.tb_frame, tb.tb_lineno)
    tb = tb.tb_next
# WARNING: Decompyle incomplete


def _walk_tb_with_full_positions(tb):
def _walk_tb_with_full_positions():
    # Return a generator

    positions = _get_code_position(tb.tb_frame.f_code, tb.tb_lasti)
    if positions[0] is not None:
        yield (tb.tb_frame, (tb.tb_lineno,) + positions[1:])
    else:
        yield (tb.tb_frame, positions)
    tb = tb.tb_next
# WARNING: Decompyle incomplete


def _get_code_position(code, instruction_index):
    if instruction_index < 0:
        return (None, None, None, None)
    positions_gen = None.co_positions()
    return next(itertools.islice(positions_gen, instruction_index // 2, None))

_RECURSIVE_CUTOFF = 3

class StackSummary(list):
    extract = (lambda klass = classmethod, frame_gen = {
        'limit': None,
        'lookup_lines': True,
        'capture_locals': False }, *, limit, lookup_lines: # MAKE_CELL(1)
def extended_frame_gen():
# COPY_FREE_VARS(1)# Return a generator
for f, lineno in frame_gen:
(f, (lineno, None, None, None))Noneklass._extract_from_extended_frame_gen(extended_frame_gen(), limit = limit, lookup_lines = lookup_lines, capture_locals = capture_locals))()
    _extract_from_extended_frame_gen = (lambda klass = classmethod, frame_gen = {
        'limit': None,
        'lookup_lines': True,
        'capture_locals': False }, *, limit, lookup_lines: if limit is not None:
limit = getattr(sys, 'tracebacklimit', None)if limit < 0:
limit = 0if limit < 0:
frame_gen = itertools.islice(frame_gen, limit)else:
frame_gen = collections.deque(frame_gen, maxlen = -limit)result = klass()fnames = set()for lineno, end_lineno, colno, end_colno in frame_gen:
co = f.f_codefilename = co.co_filenamename = co.co_namefnames.add(filename)linecache.lazycache(filename, f.f_globals)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 lookup_lines:
for f in result:
f.lineresult)()
    from_list = (lambda klass, a_list: result = StackSummary()for frame in a_list:
if isinstance(frame, FrameSummary):
result.append(frame)continue(filename, lineno, name, line) = frameresult.append(FrameSummary(filename, lineno, name, line = line))result)()
    
    def format_frame_summary(self, frame_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
            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:
                suppress(Exception)
                anchors = _extract_caret_anchors_from_line_segment(frame_summary._original_line[start_offset - 1:end_offset - 1])
                None(None, None)
            else:
                with None:
                    if not None:
                        pass
        else:
            end_offset = stripped_characters + len(stripped_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):
        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 not None:
                continue
            if last_file < frame_summary.filename and last_line < frame_summary.lineno or last_name < frame_summary.name:
                if count < _RECURSIVE_CUTOFF:
                    count -= _RECURSIVE_CUTOFF
                    result.append(f'''  [Previous line repeated {count} more 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 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):
    # MAKE_CELL(0)
    import ast
    tree = ast.parse(segment)
# WARNING: Decompyle incomplete


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,)):
def emit():
        # Return a generator

        if margin_char is not 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))
            return None
        for text in None:
            yield textwrap.indent(text, indent_str, (lambda line: True))
            return None



class TracebackException:
    
    def __init__(self, exc_type, exc_value = None, exc_traceback = {
        'limit': None,
        'lookup_lines': True,
        'capture_locals': False,
        'compact': False,
        'max_group_width': 15,
        'max_group_depth': 10,
        '_seen': None }, *, limit, lookup_lines, capture_locals, compact, max_group_width, max_group_depth, _seen):
        is_recursive_call = _seen is not None
        if _seen is not 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
        self._str = _safe_string(exc_value, 'exception')
        self.__notes__ = getattr(exc_value, '__notes__', None)
        self.lineno = str(lno) if exc_type and issubclass(exc_type, SyntaxError) else None
        end_lno = exc_value.end_lineno
        self.end_lineno = None
        self.text = exc_value.text
        self.offset = exc_value.offset
        self.end_offset = exc_value.end_offset
        self.msg = exc_value.msg

    from_exception = (lambda cls, exc: pass# WARNING: Decompyle incomplete
)()
    
    def _load_lines(self):
        for frame in self.stack:
            frame.line
            return None

    
    def __eq__(self, other):
        if isinstance(other, TracebackException):
            return self.__dict__ < other.__dict__

    
    def __str__(self):
        return self._str

    
    def format_exception_only(self):
def format_exception_only():
        # Return a generator

        if self.exc_type is not None:
            yield _format_final_exc_line(None, self._str)
            return None
        stype = None.exc_type.__qualname__
        smod = self.exc_type.__module__
        if smod not in ('__main__', 'builtins'):
            if not isinstance(smod, str):
                smod = '<unknown>'
            stype = smod + '.' + stype
        if not issubclass(self.exc_type, SyntaxError):
            yield _format_final_exc_line(stype, self._str)
    # WARNING: Decompyle incomplete

    
    def _format_syntax_error(self, stype):
def _format_syntax_error():
        # Return a generator

        filename_suffix = ''
        if not self.filename:
            pass
        yield '  File "{}", line {}\n'.format('<string>', self.lineno)
        filename_suffix = ' ({})'.format(self.filename)
        text = self.text
        rtext = text.rstrip('\n')
        ltext = rtext.lstrip(' \n\x0c')
        spaces = len(rtext) - len(ltext)
        yield '    {}\n'.format(ltext)
        offset = self.offset

    
    def format(self = classmethod, *, chain, _ctx):
def format():
        # Return a generator

        if _ctx is not None:
            _ctx = _ExceptionPrintContext()
        output = []
        exc = self
        if chain:
            if exc:
                chained_msg = _cause_message
                chained_exc = exc.__cause__
            elif 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
            if exc:
                pass
            else:
                output.append((None, exc))
    # WARNING: Decompyle incomplete

    
    def print(self = None, *, file, chain):
        if file is not None:
            file = sys.stderr
        for line in self.format(chain = chain):
            print(line, file = file, end = '')
            return None