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, ColorFilename, 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 | ColorFilename | |
|
180 | ColorScheme's filename coloring to be used. | |
|
181 | ColorNormal | |
|
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" % (ColorFilename, 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" % (ColorFilename, ColorNormal) | |
|
194 | ||
|
195 | return tpl_link % file | |
|
196 | ||
|
172 | 197 | #--------------------------------------------------------------------------- |
|
173 | 198 | # Module classes |
|
174 | 199 | class TBTools(colorable.Colorable): |
@@ -414,21 +439,31 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 |
|
|
|
419 |
|
|
|
420 | Colors.name, name, Colors.Normal) | |
|
442 | item = " %s, line %s%d%s, in %s%s%s\n" % ( | |
|
443 | _format_filename(filename, Colors.filename, Colors.Normal), | |
|
444 | Colors.lineno, | |
|
445 | lineno, | |
|
446 | Colors.Normal, | |
|
447 | Colors.name, | |
|
448 | name, | |
|
449 | Colors.Normal, | |
|
450 | ) | |
|
421 | 451 | if line: |
|
422 | 452 | item += ' %s\n' % line.strip() |
|
423 | 453 | list.append(item) |
|
424 | 454 | # Emphasize the last entry |
|
425 | 455 | filename, lineno, name, line = extracted_list[-1] |
|
426 |
item = |
|
|
427 |
|
|
|
428 |
|
|
|
429 |
|
|
|
430 | Colors.nameEm, name, Colors.normalEm, | |
|
431 |
|
|
|
456 | item = "%s %s, line %s%d%s, in %s%s%s%s\n" % ( | |
|
457 | Colors.normalEm, | |
|
458 | _format_filename(filename, Colors.filenameEm, Colors.normalEm), | |
|
459 | Colors.linenoEm, | |
|
460 | lineno, | |
|
461 | Colors.normalEm, | |
|
462 | Colors.nameEm, | |
|
463 | name, | |
|
464 | Colors.normalEm, | |
|
465 | Colors.Normal, | |
|
466 | ) | |
|
432 | 467 | if line: |
|
433 | 468 | item += '%s %s%s\n' % (Colors.line, line.strip(), |
|
434 | 469 | Colors.Normal) |
@@ -463,13 +498,21 b' class ListTB(TBTools):' | |||
|
463 | 498 | lineno = value.lineno |
|
464 | 499 | textline = linecache.getline(value.filename, value.lineno) |
|
465 | 500 | else: |
|
466 |
lineno = |
|
|
467 |
textline = |
|
|
468 | list.append('%s File %s"%s"%s, line %s%s%s\n' % \ | |
|
469 | (Colors.normalEm, | |
|
470 | Colors.filenameEm, py3compat.cast_unicode(value.filename), Colors.normalEm, | |
|
471 |
|
|
|
472 | if textline == '': | |
|
501 | lineno = "unknown" | |
|
502 | textline = "" | |
|
503 | list.append( | |
|
504 | "%s %s, line %s%s%s\n" | |
|
505 | % ( | |
|
506 | Colors.normalEm, | |
|
507 | _format_filename( | |
|
508 | value.filename, Colors.filenameEm, Colors.normalEm | |
|
509 | ), | |
|
510 | Colors.linenoEm, | |
|
511 | lineno, | |
|
512 | Colors.Normal, | |
|
513 | ) | |
|
514 | ) | |
|
515 | if textline == "": | |
|
473 | 516 | textline = py3compat.cast_unicode(value.text, "utf-8") |
|
474 | 517 | |
|
475 | 518 | if textline is not None: |
@@ -585,18 +628,6 b' class VerboseTB(TBTools):' | |||
|
585 | 628 | return ' %s[... skipping similar frames: %s]%s\n' % ( |
|
586 | 629 | Colors.excName, frame_info.description, ColorsNormal) |
|
587 | 630 | |
|
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 | 631 | indent = ' ' * INDENT_SIZE |
|
601 | 632 | em_normal = '%s\n%s%s' % (Colors.valEm, indent, ColorsNormal) |
|
602 | 633 | tpl_call = 'in %s%%s%s%%s%s' % (Colors.vName, Colors.valEm, |
@@ -605,7 +636,7 b' class VerboseTB(TBTools):' | |||
|
605 | 636 | (Colors.vName, Colors.valEm, ColorsNormal) |
|
606 | 637 | tpl_name_val = '%%s %s= %%s%s' % (Colors.valEm, ColorsNormal) |
|
607 | 638 | |
|
608 | link = tpl_link % file | |
|
639 | link = _format_filename(frame_info.filename, Colors.filenameEm, ColorsNormal) | |
|
609 | 640 | args, varargs, varkw, locals_ = inspect.getargvalues(frame_info.frame) |
|
610 | 641 | |
|
611 | 642 | func = frame_info.executing.code_qualname() |
@@ -645,7 +676,7 b' class VerboseTB(TBTools):' | |||
|
645 | 676 | if lvals_list: |
|
646 | 677 | lvals = '%s%s' % (indent, em_normal.join(lvals_list)) |
|
647 | 678 | |
|
648 |
result = |
|
|
679 | result = "%s, %s\n" % (link, call) | |
|
649 | 680 | |
|
650 | 681 | result += ''.join(_format_traceback_lines(frame_info.lines, Colors, self.has_colors, lvals)) |
|
651 | 682 | return result |
General Comments 0
You need to be logged in to leave comments.
Login now