MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / html

Function html

tools/python-3.11.9-amd64/Lib/cgitb.py:106–201  ·  view source on GitHub ↗

Return a nice HTML document describing a given traceback.

(einfo, context=5)

Source from the content-addressed store, hash-verified

104 return vars
105
106def 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>&nbsp;<br>
118<font color="#ffffff" face="helvetica, arial">&nbsp;<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
124function calls leading up to the error, in the order they occurred.</p>''&#x27;
125
126 indent = '<tt>' + small('&nbsp;' * 5) + '&nbsp;</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>&nbsp;</big>', link, call)]
152 if index is not None:
153 i = lnum - index
154 for line in lines:
155 num = small('&nbsp;' * (5-len(str(i))) + str(i)) + '&nbsp;'
156 if i in highlight:
157 line = '<tt>=&gt;%s%s</tt>' % (num, pydoc.html.preformat(line))
158 rows.append('<tr><td bgcolor="#ffccee">%s</td></tr>' % line)
159 else:
160 line = '<tt>&nbsp;&nbsp;%s%s</tt>' % (num, pydoc.html.preformat(line))
161 rows.append('<tr><td>%s</td></tr>' % grey(line))
162 i += 1
163

Callers

nothing calls this directly

Calls 13

strFunction · 0.85
smallFunction · 0.85
strongFunction · 0.85
scanvarsFunction · 0.85
greyFunction · 0.85
preformatMethod · 0.80
splitMethod · 0.45
ctimeMethod · 0.45
timeMethod · 0.45
escapeMethod · 0.45
reprMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected