Source

hotdebug / pretty_tb.py

jayven 1b787fa 







































#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: set ai et si ts=4 sts=4 sw=4:

import codebase


def pretty_tb(exc_type, exc_value, exc_tb):
    res = []
    res.append('<h1>%s</h1>' % exc_type)
    res.append('<h2>%s</h2>' % exc_value)
    res.append('<h2>Tracebacks</h2>')
    res.append('<ul class="traceback">')

    tb = exc_tb.tb_next # skip the first one
    
    for depth, filename, where, lineno, line, lines, local in \
            codebase.iter_tracback(tb, 7):
        res.append('<li class="tb">')
        res.append('<code>%s</code> in <code>%s</code>' % (filename, where))
        if lines:
            res.append('<ol start="%d">' % lines[0][0])
            for l in lines:
                res.append('<li><code>%s</code></li>' % l[1])
        else:
            pass

        res.append('</li>')

    res.append('</ul>')
    return '\n'.join(res)


if __name__ == '__main__':
    import sys
    try:
        import debugger
    except:
        sys.stdout.write(pretty_tb(*sys.exc_info()))

        
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.