Show More
@@ -169,6 +169,31 b' def _format_traceback_lines(lines, Colors, has_colors, lvals):' | |||||
169 | return res |
|
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 | # Module classes |
|
198 | # Module classes | |
174 | class TBTools(colorable.Colorable): |
|
199 | class TBTools(colorable.Colorable): | |
@@ -414,8 +439,8 b' class ListTB(TBTools):' | |||||
414 | Colors = self.Colors |
|
439 | Colors = self.Colors | |
415 | list = [] |
|
440 | list = [] | |
416 | for filename, lineno, name, line in extracted_list[:-1]: |
|
441 | for filename, lineno, name, line in extracted_list[:-1]: | |
417 |
item = ' |
|
442 | item = ' %s, line %s%d%s, in %s%s%s\n' % \ | |
418 |
( |
|
443 | (_format_filename(filename, Colors, Colors.normalEm), | |
419 | Colors.lineno, lineno, Colors.Normal, |
|
444 | Colors.lineno, lineno, Colors.Normal, | |
420 | Colors.name, name, Colors.Normal) |
|
445 | Colors.name, name, Colors.Normal) | |
421 | if line: |
|
446 | if line: | |
@@ -423,9 +448,9 b' class ListTB(TBTools):' | |||||
423 | list.append(item) |
|
448 | list.append(item) | |
424 | # Emphasize the last entry |
|
449 | # Emphasize the last entry | |
425 | filename, lineno, name, line = extracted_list[-1] |
|
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 | (Colors.normalEm, |
|
452 | (Colors.normalEm, | |
428 |
|
|
453 | _format_filename(filename, Colors, Colors.normalEm), | |
429 | Colors.linenoEm, lineno, Colors.normalEm, |
|
454 | Colors.linenoEm, lineno, Colors.normalEm, | |
430 | Colors.nameEm, name, Colors.normalEm, |
|
455 | Colors.nameEm, name, Colors.normalEm, | |
431 | Colors.Normal) |
|
456 | Colors.Normal) | |
@@ -465,10 +490,11 b' class ListTB(TBTools):' | |||||
465 | else: |
|
490 | else: | |
466 | lineno = 'unknown' |
|
491 | lineno = 'unknown' | |
467 | textline = '' |
|
492 | textline = '' | |
468 |
list.append('%s |
|
493 | list.append('%s %s, line %s%s%s\n' % | |
469 | (Colors.normalEm, |
|
494 | (Colors.normalEm, | |
470 |
|
|
495 | _format_filename(value.filename, Colors, Colors.normalEm), | |
471 |
Colors.linenoEm, lineno, Colors.Normal |
|
496 | Colors.linenoEm, lineno, Colors.Normal | |
|
497 | )) | |||
472 | if textline == '': |
|
498 | if textline == '': | |
473 | textline = py3compat.cast_unicode(value.text, "utf-8") |
|
499 | textline = py3compat.cast_unicode(value.text, "utf-8") | |
474 |
|
500 | |||
@@ -585,18 +611,6 b' class VerboseTB(TBTools):' | |||||
585 | return ' %s[... skipping similar frames: %s]%s\n' % ( |
|
611 | return ' %s[... skipping similar frames: %s]%s\n' % ( | |
586 | Colors.excName, frame_info.description, ColorsNormal) |
|
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 | indent = ' ' * INDENT_SIZE |
|
614 | indent = ' ' * INDENT_SIZE | |
601 | em_normal = '%s\n%s%s' % (Colors.valEm, indent, ColorsNormal) |
|
615 | em_normal = '%s\n%s%s' % (Colors.valEm, indent, ColorsNormal) | |
602 | tpl_call = 'in %s%%s%s%%s%s' % (Colors.vName, Colors.valEm, |
|
616 | tpl_call = 'in %s%%s%s%%s%s' % (Colors.vName, Colors.valEm, | |
@@ -605,7 +619,7 b' class VerboseTB(TBTools):' | |||||
605 | (Colors.vName, Colors.valEm, ColorsNormal) |
|
619 | (Colors.vName, Colors.valEm, ColorsNormal) | |
606 | tpl_name_val = '%%s %s= %%s%s' % (Colors.valEm, ColorsNormal) |
|
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 | args, varargs, varkw, locals_ = inspect.getargvalues(frame_info.frame) |
|
623 | args, varargs, varkw, locals_ = inspect.getargvalues(frame_info.frame) | |
610 |
|
624 | |||
611 | func = frame_info.executing.code_qualname() |
|
625 | func = frame_info.executing.code_qualname() | |
@@ -645,7 +659,7 b' class VerboseTB(TBTools):' | |||||
645 | if lvals_list: |
|
659 | if lvals_list: | |
646 | lvals = '%s%s' % (indent, em_normal.join(lvals_list)) |
|
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 | result += ''.join(_format_traceback_lines(frame_info.lines, Colors, self.has_colors, lvals)) |
|
664 | result += ''.join(_format_traceback_lines(frame_info.lines, Colors, self.has_colors, lvals)) | |
651 | return result |
|
665 | return result |
General Comments 0
You need to be logged in to leave comments.
Login now