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