Show More
@@ -169,6 +169,31 b' def _format_traceback_lines(lines, Colors, has_colors, lvals):' | |||
|
169 | 169 | return res |
|
170 | 170 | |
|
171 | 171 | |
|
172 | def _format_filename(file, Colors, ColorNormal): | |
|
173 | """ | |
|
174 | Format filename lines with `In [n]` if it's the nth code cell or `File *.py` if it's a module... | |
|
175 | ||
|
176 | Parameters | |
|
177 | ---------- | |
|
178 | file : str | |
|
179 | Colors | |
|
180 | ColorScheme used. | |
|
181 | ColorsNormal | |
|
182 | ColorScheme's normal coloring to be used. | |
|
183 | """ | |
|
184 | ipinst = get_ipython() | |
|
185 | ||
|
186 | if ipinst is not None and file in ipinst.compile._filename_map: | |
|
187 | file = "[%s]" % ipinst.compile._filename_map[file] | |
|
188 | tpl_link = "In %s%%s%s" % (Colors.filenameEm, ColorNormal) | |
|
189 | else: | |
|
190 | file = util_path.compress_user( | |
|
191 | py3compat.cast_unicode(file, util_path.fs_encoding) | |
|
192 | ) | |
|
193 | tpl_link = "File %s%%s%s" % (Colors.filenameEm, ColorNormal) | |
|
194 | ||
|
195 | return tpl_link % file | |
|
196 | ||
|
172 | 197 | #--------------------------------------------------------------------------- |
|
173 | 198 | # Module classes |
|
174 | 199 | class TBTools(colorable.Colorable): |
@@ -414,8 +439,8 b' class ListTB(TBTools):' | |||
|
414 | 439 | Colors = self.Colors |
|
415 | 440 | list = [] |
|
416 | 441 | for filename, lineno, name, line in extracted_list[:-1]: |
|
417 |
item = ' |
|
|
418 |
( |
|
|
442 | item = ' %s, line %s%d%s, in %s%s%s\n' % \ | |
|
443 | (_format_filename(filename, Colors, Colors.normalEm), | |
|
419 | 444 | Colors.lineno, lineno, Colors.Normal, |
|
420 | 445 | Colors.name, name, Colors.Normal) |
|
421 | 446 | if line: |
@@ -423,9 +448,9 b' class ListTB(TBTools):' | |||
|
423 | 448 | list.append(item) |
|
424 | 449 | # Emphasize the last entry |
|
425 | 450 | filename, lineno, name, line = extracted_list[-1] |
|
426 |
item = '%s |
|
|
451 | item = '%s %s, line %s%d%s, in %s%s%s%s\n' % \ | |
|
427 | 452 | (Colors.normalEm, |
|
428 |
|
|
|
453 | _format_filename(filename, Colors, Colors.normalEm), | |
|
429 | 454 | Colors.linenoEm, lineno, Colors.normalEm, |
|
430 | 455 | Colors.nameEm, name, Colors.normalEm, |
|
431 | 456 | Colors.Normal) |
@@ -465,10 +490,11 b' class ListTB(TBTools):' | |||
|
465 | 490 | else: |
|
466 | 491 | lineno = 'unknown' |
|
467 | 492 | textline = '' |
|
468 |
list.append('%s |
|
|
493 | list.append('%s %s, line %s%s%s\n' % | |
|
469 | 494 | (Colors.normalEm, |
|
470 |
|
|
|
471 |
Colors.linenoEm, lineno, Colors.Normal |
|
|
495 | _format_filename(value.filename, Colors, Colors.normalEm), | |
|
496 | Colors.linenoEm, lineno, Colors.Normal | |
|
497 | )) | |
|
472 | 498 | if textline == '': |
|
473 | 499 | textline = py3compat.cast_unicode(value.text, "utf-8") |
|
474 | 500 | |
@@ -585,18 +611,6 b' class VerboseTB(TBTools):' | |||
|
585 | 611 | return ' %s[... skipping similar frames: %s]%s\n' % ( |
|
586 | 612 | Colors.excName, frame_info.description, ColorsNormal) |
|
587 | 613 | |
|
588 | file = frame_info.filename | |
|
589 | ||
|
590 | ipinst = get_ipython() | |
|
591 | if ipinst is not None and file in ipinst.compile._filename_map: | |
|
592 | file = "[%s]" % ipinst.compile._filename_map[file] | |
|
593 | tpl_link = "In %s%%s%s," % (Colors.filenameEm, ColorsNormal) | |
|
594 | else: | |
|
595 | file = util_path.compress_user( | |
|
596 | py3compat.cast_unicode(file, util_path.fs_encoding) | |
|
597 | ) | |
|
598 | tpl_link = "File %s%%s%s," % (Colors.filenameEm, ColorsNormal) | |
|
599 | ||
|
600 | 614 | indent = ' ' * INDENT_SIZE |
|
601 | 615 | em_normal = '%s\n%s%s' % (Colors.valEm, indent, ColorsNormal) |
|
602 | 616 | tpl_call = 'in %s%%s%s%%s%s' % (Colors.vName, Colors.valEm, |
@@ -605,7 +619,7 b' class VerboseTB(TBTools):' | |||
|
605 | 619 | (Colors.vName, Colors.valEm, ColorsNormal) |
|
606 | 620 | tpl_name_val = '%%s %s= %%s%s' % (Colors.valEm, ColorsNormal) |
|
607 | 621 | |
|
608 | link = tpl_link % file | |
|
622 | link = _format_filename(frame_info.filename, Colors, ColorsNormal) | |
|
609 | 623 | args, varargs, varkw, locals_ = inspect.getargvalues(frame_info.frame) |
|
610 | 624 | |
|
611 | 625 | func = frame_info.executing.code_qualname() |
@@ -645,7 +659,7 b' class VerboseTB(TBTools):' | |||
|
645 | 659 | if lvals_list: |
|
646 | 660 | lvals = '%s%s' % (indent, em_normal.join(lvals_list)) |
|
647 | 661 | |
|
648 | result = '%s %s\n' % (link, call) | |
|
662 | result = '%s, %s\n' % (link, call) | |
|
649 | 663 | |
|
650 | 664 | result += ''.join(_format_traceback_lines(frame_info.lines, Colors, self.has_colors, lvals)) |
|
651 | 665 | return result |
General Comments 0
You need to be logged in to leave comments.
Login now