Show More
@@ -60,7 +60,7 b' You can implement other color schemes easily, the syntax is fairly' | |||||
60 | self-explanatory. Please send back new schemes you develop to the author for |
|
60 | self-explanatory. Please send back new schemes you develop to the author for | |
61 | possible inclusion in future releases. |
|
61 | possible inclusion in future releases. | |
62 |
|
62 | |||
63 |
$Id: ultraTB.py 288 |
|
63 | $Id: ultraTB.py 2884 2007-12-02 04:42:21Z rkern $""" | |
64 |
|
64 | |||
65 | #***************************************************************************** |
|
65 | #***************************************************************************** | |
66 | # Copyright (C) 2001 Nathaniel Gray <n8gray@caltech.edu> |
|
66 | # Copyright (C) 2001 Nathaniel Gray <n8gray@caltech.edu> | |
@@ -203,11 +203,31 b' def findsource(object):' | |||||
203 | if sys.version_info[:2] >= (2,5): |
|
203 | if sys.version_info[:2] >= (2,5): | |
204 | inspect.findsource = findsource |
|
204 | inspect.findsource = findsource | |
205 |
|
205 | |||
|
206 | def fix_frame_records_filenames(records): | |||
|
207 | """Try to fix the filenames in each record from inspect.getinnerframes(). | |||
|
208 | ||||
|
209 | Particularly, modules loaded from within zip files have useless filenames | |||
|
210 | attached to their code object, and inspect.getinnerframes() just uses it. | |||
|
211 | """ | |||
|
212 | fixed_records = [] | |||
|
213 | for frame, filename, line_no, func_name, lines, index in records: | |||
|
214 | # Look inside the frame's globals dictionary for __file__, which should | |||
|
215 | # be better. | |||
|
216 | better_fn = frame.f_globals.get('__file__', None) | |||
|
217 | if isinstance(better_fn, str): | |||
|
218 | # Check the type just in case someone did something weird with | |||
|
219 | # __file__. It might also be None if the error occurred during | |||
|
220 | # import. | |||
|
221 | filename = better_fn | |||
|
222 | fixed_records.append((frame, filename, line_no, func_name, lines, index)) | |||
|
223 | return fixed_records | |||
|
224 | ||||
|
225 | ||||
206 | def _fixed_getinnerframes(etb, context=1,tb_offset=0): |
|
226 | def _fixed_getinnerframes(etb, context=1,tb_offset=0): | |
207 | import linecache |
|
227 | import linecache | |
208 | LNUM_POS, LINES_POS, INDEX_POS = 2, 4, 5 |
|
228 | LNUM_POS, LINES_POS, INDEX_POS = 2, 4, 5 | |
209 |
|
229 | |||
210 | records = inspect.getinnerframes(etb, context) |
|
230 | records = fix_frame_records_filenames(inspect.getinnerframes(etb, context)) | |
211 |
|
231 | |||
212 | # If the error is at the console, don't build any context, since it would |
|
232 | # If the error is at the console, don't build any context, since it would | |
213 | # otherwise produce 5 blank lines printed out (there is no file at the |
|
233 | # otherwise produce 5 blank lines printed out (there is no file at the |
@@ -3,6 +3,10 b'' | |||||
3 | * IPython/ultraTB.py (findsource): Improve the monkeypatch to |
|
3 | * IPython/ultraTB.py (findsource): Improve the monkeypatch to | |
4 | inspect.findsource(). It can now find source lines inside zipped |
|
4 | inspect.findsource(). It can now find source lines inside zipped | |
5 | packages. |
|
5 | packages. | |
|
6 | ||||
|
7 | * IPython/ultraTB.py: When constructing tracebacks, try to use __file__ | |||
|
8 | in the frame's namespace before trusting the filename in the code object | |||
|
9 | which created the frame. | |||
6 |
|
10 | |||
7 | 2007-11-29 *** Released version 0.8.2 |
|
11 | 2007-11-29 *** Released version 0.8.2 | |
8 |
|
12 |
General Comments 0
You need to be logged in to leave comments.
Login now