Format the exception part of a traceback. The arguments are the exception type and value such as given by sys.exc_info()[:2]. The return value is a list of strings, each ending in a newline. Normally, the list contains a single string; however, for SyntaxError excep
(self, etype, value)
| 741 | return list |
| 742 | |
| 743 | def _format_exception_only(self, etype, value): |
| 744 | """Format the exception part of a traceback. |
| 745 | |
| 746 | The arguments are the exception type and value such as given by |
| 747 | sys.exc_info()[:2]. The return value is a list of strings, each ending |
| 748 | in a newline. Normally, the list contains a single string; however, |
| 749 | for SyntaxError exceptions, it contains several lines that (when |
| 750 | printed) display detailed information about where the syntax error |
| 751 | occurred. The message indicating which exception occurred is the |
| 752 | always last string in the list. |
| 753 | |
| 754 | Also lifted nearly verbatim from traceback.py |
| 755 | """ |
| 756 | have_filedata = False |
| 757 | Colors = self.Colors |
| 758 | list = [] |
| 759 | stype = py3compat.cast_unicode(Colors.excName + etype.__name__ + Colors.Normal) |
| 760 | if value is None: |
| 761 | # Not sure if this can still happen in Python 2.6 and above |
| 762 | list.append(stype + '\n') |
| 763 | else: |
| 764 | if issubclass(etype, SyntaxError): |
| 765 | have_filedata = True |
| 766 | if not value.filename: value.filename = "<string>" |
| 767 | if value.lineno: |
| 768 | lineno = value.lineno |
| 769 | textline = linecache.getline(value.filename, value.lineno) |
| 770 | else: |
| 771 | lineno = 'unknown' |
| 772 | textline = '' |
| 773 | list.append('%s File %s"%s"%s, line %s%s%s\n' % \ |
| 774 | (Colors.normalEm, |
| 775 | Colors.filenameEm, py3compat.cast_unicode(value.filename), Colors.normalEm, |
| 776 | Colors.linenoEm, lineno, Colors.Normal )) |
| 777 | if textline == '': |
| 778 | textline = py3compat.cast_unicode(value.text, "utf-8") |
| 779 | |
| 780 | if textline is not None: |
| 781 | i = 0 |
| 782 | while i < len(textline) and textline[i].isspace(): |
| 783 | i += 1 |
| 784 | list.append('%s %s%s\n' % (Colors.line, |
| 785 | textline.strip(), |
| 786 | Colors.Normal)) |
| 787 | if value.offset is not None: |
| 788 | s = ' ' |
| 789 | for c in textline[i:value.offset - 1]: |
| 790 | if c.isspace(): |
| 791 | s += c |
| 792 | else: |
| 793 | s += ' ' |
| 794 | list.append('%s%s^%s\n' % (Colors.caret, s, |
| 795 | Colors.Normal)) |
| 796 | |
| 797 | try: |
| 798 | s = value.msg |
| 799 | except Exception: |
| 800 | s = self._some_str(value) |
no test coverage detected