Show More
@@ -39,7 +39,7 b" Give it a shot--you'll love it or you'll hate it." | |||||
39 | Verbose). |
|
39 | Verbose). | |
40 |
|
40 | |||
41 |
|
41 | |||
42 |
Installation instructions for |
|
42 | Installation instructions for VerboseTB:: | |
43 |
|
43 | |||
44 | import sys,ultratb |
|
44 | import sys,ultratb | |
45 | sys.excepthook = ultratb.VerboseTB() |
|
45 | sys.excepthook = ultratb.VerboseTB() | |
@@ -141,6 +141,7 b' def inspect_error():' | |||||
141 | error('Internal Python error in the inspect module.\n' |
|
141 | error('Internal Python error in the inspect module.\n' | |
142 | 'Below is the traceback from this internal error.\n') |
|
142 | 'Below is the traceback from this internal error.\n') | |
143 |
|
143 | |||
|
144 | ||||
144 | # This function is a monkeypatch we apply to the Python inspect module. We have |
|
145 | # This function is a monkeypatch we apply to the Python inspect module. We have | |
145 | # now found when it's needed (see discussion on issue gh-1456), and we have a |
|
146 | # now found when it's needed (see discussion on issue gh-1456), and we have a | |
146 | # test case (IPython.core.tests.test_ultratb.ChangedPyFileTest) that fails if |
|
147 | # test case (IPython.core.tests.test_ultratb.ChangedPyFileTest) that fails if | |
@@ -220,9 +221,11 b' def findsource(object):' | |||||
220 | return lines, lnum |
|
221 | return lines, lnum | |
221 | raise IOError('could not find code object') |
|
222 | raise IOError('could not find code object') | |
222 |
|
223 | |||
|
224 | ||||
223 | # Monkeypatch inspect to apply our bugfix. |
|
225 | # Monkeypatch inspect to apply our bugfix. | |
224 | def with_patch_inspect(f): |
|
226 | def with_patch_inspect(f): | |
225 | """decorator for monkeypatching inspect.findsource""" |
|
227 | """decorator for monkeypatching inspect.findsource""" | |
|
228 | ||||
226 | def wrapped(*args, **kwargs): |
|
229 | def wrapped(*args, **kwargs): | |
227 | save_findsource = inspect.findsource |
|
230 | save_findsource = inspect.findsource | |
228 | inspect.findsource = findsource |
|
231 | inspect.findsource = findsource | |
@@ -230,8 +233,10 b' def with_patch_inspect(f):' | |||||
230 | return f(*args, **kwargs) |
|
233 | return f(*args, **kwargs) | |
231 | finally: |
|
234 | finally: | |
232 | inspect.findsource = save_findsource |
|
235 | inspect.findsource = save_findsource | |
|
236 | ||||
233 | return wrapped |
|
237 | return wrapped | |
234 |
|
238 | |||
|
239 | ||||
235 | def fix_frame_records_filenames(records): |
|
240 | def fix_frame_records_filenames(records): | |
236 | """Try to fix the filenames in each record from inspect.getinnerframes(). |
|
241 | """Try to fix the filenames in each record from inspect.getinnerframes(). | |
237 |
|
242 | |||
@@ -290,6 +295,7 b' def _fixed_getinnerframes(etb, context=1,tb_offset=0):' | |||||
290 |
|
295 | |||
291 | _parser = PyColorize.Parser() |
|
296 | _parser = PyColorize.Parser() | |
292 |
|
297 | |||
|
298 | ||||
293 | def _format_traceback_lines(lnum, index, lines, Colors, lvals=None,scheme=None): |
|
299 | def _format_traceback_lines(lnum, index, lines, Colors, lvals=None, scheme=None): | |
294 | numbers_width = INDENT_SIZE - 1 |
|
300 | numbers_width = INDENT_SIZE - 1 | |
295 | res = [] |
|
301 | res = [] | |
@@ -636,7 +642,6 b' class ListTB(TBTools):' | |||||
636 | """ |
|
642 | """ | |
637 | return ListTB.structured_traceback(self, etype, value, []) |
|
643 | return ListTB.structured_traceback(self, etype, value, []) | |
638 |
|
644 | |||
639 |
|
||||
640 | def show_exception_only(self, etype, evalue): |
|
645 | def show_exception_only(self, etype, evalue): | |
641 | """Only print the exception type and message, without a traceback. |
|
646 | """Only print the exception type and message, without a traceback. | |
642 |
|
647 | |||
@@ -659,6 +664,7 b' class ListTB(TBTools):' | |||||
659 | except: |
|
664 | except: | |
660 | return '<unprintable %s object>' % type(value).__name__ |
|
665 | return '<unprintable %s object>' % type(value).__name__ | |
661 |
|
666 | |||
|
667 | ||||
662 | #---------------------------------------------------------------------------- |
|
668 | #---------------------------------------------------------------------------- | |
663 | class VerboseTB(TBTools): |
|
669 | class VerboseTB(TBTools): | |
664 | """A port of Ka-Ping Yee's cgitb.py module that outputs color text instead |
|
670 | """A port of Ka-Ping Yee's cgitb.py module that outputs color text instead | |
@@ -738,8 +744,12 b' class VerboseTB(TBTools):' | |||||
738 | raise |
|
744 | raise | |
739 | except: |
|
745 | except: | |
740 | return 'UNRECOVERABLE REPR FAILURE' |
|
746 | return 'UNRECOVERABLE REPR FAILURE' | |
741 | def eqrepr(value, repr=text_repr): return '=%s' % repr(value) |
|
747 | ||
742 |
def |
|
748 | def eqrepr(value, repr=text_repr): | |
|
749 | return '=%s' % repr(value) | |||
|
750 | ||||
|
751 | def nullrepr(value, repr=text_repr): | |||
|
752 | return '' | |||
743 |
|
753 | |||
744 | # meat of the code begins |
|
754 | # meat of the code begins | |
745 | try: |
|
755 | try: | |
@@ -1050,6 +1060,7 b' class VerboseTB(TBTools):' | |||||
1050 | except KeyboardInterrupt: |
|
1060 | except KeyboardInterrupt: | |
1051 | print("\nKeyboardInterrupt") |
|
1061 | print("\nKeyboardInterrupt") | |
1052 |
|
1062 | |||
|
1063 | ||||
1053 | #---------------------------------------------------------------------------- |
|
1064 | #---------------------------------------------------------------------------- | |
1054 | class FormattedTB(VerboseTB, ListTB): |
|
1065 | class FormattedTB(VerboseTB, ListTB): | |
1055 | """Subclass ListTB but allow calling with a traceback. |
|
1066 | """Subclass ListTB but allow calling with a traceback. | |
@@ -1131,7 +1142,7 b' class FormattedTB(VerboseTB, ListTB):' | |||||
1131 | # Set the join character for generating text tracebacks |
|
1142 | # Set the join character for generating text tracebacks | |
1132 | self.tb_join_char = self._join_chars[self.mode] |
|
1143 | self.tb_join_char = self._join_chars[self.mode] | |
1133 |
|
1144 | |||
1134 | # some convenient shorcuts |
|
1145 | # some convenient shortcuts | |
1135 | def plain(self): |
|
1146 | def plain(self): | |
1136 | self.set_mode(self.valid_modes[0]) |
|
1147 | self.set_mode(self.valid_modes[0]) | |
1137 |
|
1148 | |||
@@ -1141,6 +1152,7 b' class FormattedTB(VerboseTB, ListTB):' | |||||
1141 | def verbose(self): |
|
1152 | def verbose(self): | |
1142 | self.set_mode(self.valid_modes[2]) |
|
1153 | self.set_mode(self.valid_modes[2]) | |
1143 |
|
1154 | |||
|
1155 | ||||
1144 | #---------------------------------------------------------------------------- |
|
1156 | #---------------------------------------------------------------------------- | |
1145 | class AutoFormattedTB(FormattedTB): |
|
1157 | class AutoFormattedTB(FormattedTB): | |
1146 | """A traceback printer which can be called on the fly. |
|
1158 | """A traceback printer which can be called on the fly. | |
@@ -1167,7 +1179,6 b' class AutoFormattedTB(FormattedTB):' | |||||
1167 | per-call basis (this overrides temporarily the instance's tb_offset |
|
1179 | per-call basis (this overrides temporarily the instance's tb_offset | |
1168 | given at initialization time. """ |
|
1180 | given at initialization time. """ | |
1169 |
|
1181 | |||
1170 |
|
||||
1171 | if out is None: |
|
1182 | if out is None: | |
1172 | out = self.ostream |
|
1183 | out = self.ostream | |
1173 | out.flush() |
|
1184 | out.flush() | |
@@ -1189,11 +1200,13 b' class AutoFormattedTB(FormattedTB):' | |||||
1189 | return FormattedTB.structured_traceback( |
|
1200 | return FormattedTB.structured_traceback( | |
1190 | self, etype, value, tb, tb_offset, context) |
|
1201 | self, etype, value, tb, tb_offset, context) | |
1191 |
|
1202 | |||
|
1203 | ||||
1192 | #--------------------------------------------------------------------------- |
|
1204 | #--------------------------------------------------------------------------- | |
1193 |
|
1205 | |||
1194 | # A simple class to preserve Nathan's original functionality. |
|
1206 | # A simple class to preserve Nathan's original functionality. | |
1195 | class ColorTB(FormattedTB): |
|
1207 | class ColorTB(FormattedTB): | |
1196 | """Shorthand to initialize a FormattedTB in Linux colors mode.""" |
|
1208 | """Shorthand to initialize a FormattedTB in Linux colors mode.""" | |
|
1209 | ||||
1197 | def __init__(self,color_scheme='Linux',call_pdb=0): |
|
1210 | def __init__(self, color_scheme='Linux', call_pdb=0): | |
1198 | FormattedTB.__init__(self,color_scheme=color_scheme, |
|
1211 | FormattedTB.__init__(self, color_scheme=color_scheme, | |
1199 | call_pdb=call_pdb) |
|
1212 | call_pdb=call_pdb) |
General Comments 0
You need to be logged in to leave comments.
Login now