Return a nice HTML document describing a given traceback.
(einfo, context=5)
| 104 | return vars |
| 105 | |
| 106 | def html(einfo, context=5): |
| 107 | """Return a nice HTML document describing a given traceback.""" |
| 108 | etype, evalue, etb = einfo |
| 109 | if isinstance(etype, type): |
| 110 | etype = etype.__name__ |
| 111 | pyver = 'Python ' + sys.version.split()[0] + ': ' + sys.executable |
| 112 | date = time.ctime(time.time()) |
| 113 | head = f''' |
| 114 | <body bgcolor="#f0f0f8"> |
| 115 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading"> |
| 116 | <tr bgcolor="#6622aa"> |
| 117 | <td valign=bottom> <br> |
| 118 | <font color="#ffffff" face="helvetica, arial"> <br> |
| 119 | <big><big><strong>{html_escape(str(etype))}</strong></big></big></font></td> |
| 120 | <td align=right valign=bottom> |
| 121 | <font color="#ffffff" face="helvetica, arial">{pyver}<br>{date}</font></td> |
| 122 | </tr></table> |
| 123 | <p>A problem occurred in a Python script. Here is the sequence of |
| 124 | function calls leading up to the error, in the order they occurred.</p>''' |
| 125 | |
| 126 | indent = '<tt>' + small(' ' * 5) + ' </tt>' |
| 127 | frames = [] |
| 128 | records = inspect.getinnerframes(etb, context) |
| 129 | for frame, file, lnum, func, lines, index in records: |
| 130 | if file: |
| 131 | file = os.path.abspath(file) |
| 132 | link = '<a href="file://%s">%s</a>' % (file, pydoc.html.escape(file)) |
| 133 | else: |
| 134 | file = link = '?' |
| 135 | args, varargs, varkw, locals = inspect.getargvalues(frame) |
| 136 | call = '' |
| 137 | if func != '?': |
| 138 | call = 'in ' + strong(pydoc.html.escape(func)) |
| 139 | if func != "<module>": |
| 140 | call += inspect.formatargvalues(args, varargs, varkw, locals, |
| 141 | formatvalue=lambda value: '=' + pydoc.html.repr(value)) |
| 142 | |
| 143 | highlight = {} |
| 144 | def reader(lnum=[lnum]): |
| 145 | highlight[lnum[0]] = 1 |
| 146 | try: return linecache.getline(file, lnum[0]) |
| 147 | finally: lnum[0] += 1 |
| 148 | vars = scanvars(reader, frame, locals) |
| 149 | |
| 150 | rows = ['<tr><td bgcolor="#d8bbff">%s%s %s</td></tr>' % |
| 151 | ('<big> </big>', link, call)] |
| 152 | if index is not None: |
| 153 | i = lnum - index |
| 154 | for line in lines: |
| 155 | num = small(' ' * (5-len(str(i))) + str(i)) + ' ' |
| 156 | if i in highlight: |
| 157 | line = '<tt>=>%s%s</tt>' % (num, pydoc.html.preformat(line)) |
| 158 | rows.append('<tr><td bgcolor="#ffccee">%s</td></tr>' % line) |
| 159 | else: |
| 160 | line = '<tt> %s%s</tt>' % (num, pydoc.html.preformat(line)) |
| 161 | rows.append('<tr><td>%s</td></tr>' % grey(line)) |
| 162 | i += 1 |
| 163 |
nothing calls this directly
no test coverage detected