Simple traceback introspection. Used to add additional information to AssertionErrors in tests, so that failure messages may be more informative.
Find lines in home that are inspectable.
Walk back from the err line up to 3 lines, but don’t walk back over changes in indent level.
Walk forward up to 3 lines, counting separated lines as 1. Don’t walk over changes in indent level (unless part of an extended line)
Get source from a traceback object.
A tuple of two things is returned: a list of lines of context from the source code, and the index of the current line within that list. The optional second argument specifies the number of lines of context to return, which are centered around the current line.
Note
This is adapted from inspect.py in the python 2.4 standard library, since a bug in the 2.3 version of inspect prevents it from correctly locating source lines in a traceback frame.