def _format_list(self, extracted_list):
"""Format a list of traceback entry tuples for printing.
Given a list of tuples as returned by extract_tb() or
extract_stack(), return a list of strings ready for printing.
Each string in the resulting list corresponds to the item with the
same index in the argument list. Each string ends in a newline;
the strings may contain internal newlines as well, for those items
whose source text line is not None.
Lifted almost verbatim from traceback.py
"""
Colors = self.Colors
list = []
for filename, lineno, name, line in extracted_list[:-1]:
item = ' File %s"%s"%s, line %s%d%s, in %s%s%s\n' % \
(Colors.filename, filename, Colors.Normal,
Colors.lineno, lineno, Colors.Normal,
Colors.name, name, Colors.Normal)
if line:
item += ' %s\n' % line.strip()
list.append(item)
# Emphasize the last entry
filename, lineno, name, line = extracted_list[-1]
item = '%s File %s"%s"%s, line %s%d%s, in %s%s%s%s\n' % \
(Colors.normalEm,
Colors.filenameEm, filename, Colors.normalEm,
Colors.linenoEm, lineno, Colors.normalEm,
Colors.nameEm, name, Colors.normalEm,
Colors.Normal)
if line:
item += '%s %s%s\n' % (Colors.line, line.strip(),
Colors.Normal)
list.append(item)
return list
评论列表
文章目录