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

Function text

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

Return a plain text document describing a given traceback.

(einfo, context=5)

Source from the content-addressed store, hash-verified

201 ''.join(traceback.format_exception(etype, evalue, etb)))
202
203def text(einfo, context=5):
204 """Return a plain text document describing a given traceback."""
205 etype, evalue, etb = einfo
206 if isinstance(etype, type):
207 etype = etype.__name__
208 pyver = 'Python ' + sys.version.split()[0] + ': ' + sys.executable
209 date = time.ctime(time.time())
210 head = "%s\n%s\n%s\n" % (str(etype), pyver, date) + '''
211A problem occurred in a Python script. Here is the sequence of
212function calls leading up to the error, in the order they occurred.
213'''
214
215 frames = []
216 records = inspect.getinnerframes(etb, context)
217 for frame, file, lnum, func, lines, index in records:
218 file = file and os.path.abspath(file) or '?'
219 args, varargs, varkw, locals = inspect.getargvalues(frame)
220 call = ''
221 if func != '?':
222 call = 'in ' + func
223 if func != "<module>":
224 call += inspect.formatargvalues(args, varargs, varkw, locals,
225 formatvalue=lambda value: '=' + pydoc.text.repr(value))
226
227 highlight = {}
228 def reader(lnum=[lnum]):
229 highlight[lnum[0]] = 1
230 try: return linecache.getline(file, lnum[0])
231 finally: lnum[0] += 1
232 vars = scanvars(reader, frame, locals)
233
234 rows = [' %s %s' % (file, call)]
235 if index is not None:
236 i = lnum - index
237 for line in lines:
238 num = '%5d ' % i
239 rows.append(num+line.rstrip())
240 i += 1
241
242 done, dump = {}, []
243 for name, where, value in vars:
244 if name in done: continue
245 done[name] = 1
246 if value is not __UNDEF__:
247 if where == 'global': name = 'global ' + name
248 elif where != 'local': name = where + name.split('.')[-1]
249 dump.append('%s = %s' % (name, pydoc.text.repr(value)))
250 else:
251 dump.append(name + ' undefined')
252
253 rows.append('\n'.join(dump))
254 frames.append('\n%s\n' % '\n'.join(rows))
255
256 exception = ['%s: %s' % (str(etype), str(evalue))]
257 for name in dir(evalue):
258 value = pydoc.text.repr(getattr(evalue, name))
259 exception.append('\n%s%s = %s' % (" "*4, name, value))
260

Callers

nothing calls this directly

Calls 9

strFunction · 0.85
scanvarsFunction · 0.85
splitMethod · 0.45
ctimeMethod · 0.45
timeMethod · 0.45
reprMethod · 0.45
appendMethod · 0.45
rstripMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected