Пример #1
0
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.
    """
    if file is None:
        file = sys.stderr
    if limit is None:
        if hasattr(sys, 'tracebacklimit'):
            limit = sys.tracebacklimit
    n = 0
    while tb is not None and (limit is None or n < limit):
        f = tb.tb_frame
        lineno = tb.tb_lineno
        co = f.f_code
        filename = co.co_filename
        name = co.co_name
        traceback._print(file,
               '  File "%s", line %d, in %s' % (filename,lineno,name))
        linecache.checkcache(filename)
        line = linecache.getline(filename, lineno, {})#f.f_globals)
        if line: traceback._print(file, '    ' + line.strip())
        tb = tb.tb_next
        n = n+1
Пример #2
0
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.
    """
    if file is None:
        file = sys.stderr
    if limit is None:
        if hasattr(sys, 'tracebacklimit'):
            limit = sys.tracebacklimit
    n = 0
    while tb is not None and (limit is None or n < limit):
        f = tb.tb_frame
        lineno = tb.tb_lineno
        co = f.f_code
        filename = co.co_filename
        name = co.co_name
        traceback._print(
            file, '  File "%s", line %d, in %s' % (filename, lineno, name))
        linecache.checkcache(filename)
        line = linecache.getline(filename, lineno, {})  #f.f_globals)
        if line: traceback._print(file, '    ' + line.strip())
        tb = tb.tb_next
        n = n + 1
Пример #3
0
def print_exception(etype, value, tb, limit=None, file=None):
    """As traceback.print_exception, but include local variable information."""

    if not file:
        file = sys.stderr
    # endif

    lines = format_exception(etype, value, tb, limit)
    for line in lines:
        traceback._print(file, line, '')
Пример #4
0
    def print_exception(etype, value, tb, limit=None, file=None):
        # Build the exception chain.
        chain = deque()
        cause = value
        while True:
            cause = cause.__dict__.get('__cause__', None)
            if cause is None:
                break
            chain.appendleft(cause)

        # Print the exception chain.
        for cause in chain:
            _print_exception(type(cause), cause,
                    cause.__dict__.get('__traceback__', None), limit, file)
            traceback._print(file, '\nThe above exception was the direct '
                      'cause of the following exception:\n')

        _print_exception(etype, value, tb, limit, file)
Пример #5
0
    def print_exception(etype, value, tb, limit=None, file=None):
        # Build the exception chain.
        chain = deque()
        cause = value
        while True:
            cause = cause.__dict__.get('__cause__', None)
            if cause is None:
                break
            chain.appendleft(cause)

        # Print the exception chain.
        for cause in chain:
            _print_exception(type(cause), cause,
                             cause.__dict__.get('__traceback__', None), limit,
                             file)
            traceback._print(
                file, '\nThe above exception was the direct '
                'cause of the following exception:\n')

        _print_exception(etype, value, tb, limit, file)
Пример #6
0
            def _wrap(*args, **kwargs):
                _kwargs = {}  # The args we will send via the signal
                # Update the _kwargs with the kwargs sent to our function
                _kwargs.update(kwargs)
                # Go through each argument name and update the _kwargs with
                # the arguments passed to our function.
                for i, k in enumerate(argnames):
                    if i < len(args):
                        _kwargs[k] = args[i]

                try:
                    self.events["pre_%s" % name].send(sender=self, **_kwargs)
                    _kwargs["return_"] = fn(*args, **kwargs)
                    self.events["post_%s" % name].send(sender=self, **_kwargs)
                except TypeError, e:
                    traceback.print_exc()
                    traceback._print(sys.stderr, e.message)
                    traceback._print(
                        sys.stderr,
                        "Ensure that the function that is "
                        "catching the signal has the same exact signature "
                        "(meaning, same names of parameters) as the "
                        "function sending the signal",
                    )