22 __all__ = [
'getCallerFrame',
'getStackFrame',
'StackFrame',
'getCallStack']
29 """Get the frame for the user's caller. 33 relative : `int`, optional 34 Number of frames (0 or more) above the caller to retrieve. Default is 0. 38 frame : `__builtin__.Frame` 43 This function is excluded from the frame. 45 frame = inspect.currentframe().f_back.f_back
46 for ii
in range(relative):
52 """Get the `StackFrame` for the user's caller. 56 relative : `int`, optional 57 Number of frames (0 or more) above the caller to retrieve. 62 Stack frame for the caller. 65 return StackFrame.fromFrame(frame)
69 """A single element of the stack trace. 71 This differs slightly from the standard system mechanisms for getting a 72 stack trace by the fact that it does not look up the source code until it 73 is absolutely necessary, reducing the I/O. 78 Name of file containing the code being executed. 80 Line number of file being executed. 82 Function name being executed. 83 content : `str`, optional 84 The actual content being executed. If not provided, it will be loaded 89 This differs slightly from the standard system mechanisms for getting a 90 stack trace by the fact that it does not look up the source code until it 91 is absolutely necessary, reducing the I/O. 98 _STRIP =
"/python/lsst/" 99 """String to strip from the ``filename`` in the constructor.""" 101 def __init__(self, filename, lineno, function, content=None):
102 loc = filename.rfind(self.
_STRIP)
104 filename = filename[loc + len(self.
_STRIP):]
112 """Content being executed (loaded on demand) (`str`). 120 """Construct from a Frame object. 125 Frame object to interpret, such as from `inspect.currentframe`. 129 stackFrame : `StackFrame` 130 A `StackFrame` instance. 134 `inspect.currentframe` provides a Frame object. This is a convenience 135 constructor to interpret that Frame object: 138 >>> stackFrame = StackFrame.fromFrame(inspect.currentframe()) 140 filename = frame.f_code.co_filename
141 lineno = frame.f_lineno
142 function = frame.f_code.co_name
143 return cls(filename, lineno, function)
149 """Format for printing. 153 full : `bool`, optional 154 If `True`, output includes the conentent (`StackFrame.content`) being executed. Default 164 result +=
"\n %s" % (self.
content,)
169 """Retrieve the call stack for the caller. 173 skip : `int`, non-negative 174 Number of stack frames above caller to skip. 178 output : `list` of `StackFrame` 179 The call stack. The `list` is ordered with the most recent frame to 184 This function is excluded from the call stack. 189 stack.append(StackFrame.fromFrame(frame))
191 return list(reversed(stack))
def format(self, full=False)
def __init__(self, filename, lineno, function, content=None)
def getStackFrame(relative=0)
def getCallerFrame(relative=0)
def fromFrame(cls, frame)