File: text.py

package info (click to toggle)
python-catcher 0.1.7%2Bgit20140530-1
  • links: PTS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 116 kB
  • ctags: 37
  • sloc: python: 257; makefile: 47
file content (33 lines) | stat: -rw-r--r-- 815 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from datetime import datetime


class TextFormatter:
    def __format_frame(self, frame):
        lines, current_line = frame.code
        code = ''.join(
            '    ' +
            ('>>' if lines.index(line) == frame.line - current_line else '  ') +
            ' ' + line
            for line in lines
        )

        return """
    %(file)s:%(line)s
%(code)s
        """ % {
            'file': frame.file,
            'line': frame.line,
            'code': code,
        }

    def format(self, report):
        traceback = '\n'.join(self.__format_frame(frame) for frame in report.traceback)
        return """
Error report at %(timestamp)s

Traceback:
%(traceback)s
        """ % {
            'timestamp': datetime.fromtimestamp(int(report.timestamp)),
            'traceback': traceback,
        }