# Print tracebacks, with a dump of local variables.
# Also an interactive stack trace browser.
# Note -- this module is obsolete -- use pdb.pm() instead.
def br(): browser(sys
.last_traceback
)
def tb(): printtb(sys
.last_traceback
)
except KeyboardInterrupt:
if ptr
-1 >= 0: ptr
= ptr
-1
else: print 'Bottom of stack.'
if ptr
+1 < len(tblist
): ptr
= ptr
+1
else: print 'Top of stack.'
printsymbols(tb
.tb_frame
.f_locals
)
printsymbols(tb
.tb_frame
.f_globals
)
elif cmd
in ('?', 'help'):
filename
= tb
.tb_frame
.f_code
.co_filename
for i
in range(first
, last
+1):
if i
== lineno
: prefix
= '***' + `i`
.rjust(4) + ':'
else: prefix
= `i`
.rjust(7) + ':'
line
= linecache
.getline(filename
, i
)
if line
[-1:] == '\n': line
= line
[:-1]
def browserexec(tb
, cmd
):
locals = tb
.tb_frame
.f_locals
globals = tb
.tb_frame
.f_globals
exec cmd
+'\n' in globals, locals
t
, v
= sys
.exc_info()[:2]
print 'Type help to get help.'
print ' This is the traceback browser. Commands are:'
print ' up : move one level up in the call stack'
print ' down : move one level down in the call stack'
print ' locals : print all local variables at this level'
print ' globals : print all global variables at this level'
print ' list : list source code around the failure'
print ' help : print help (what you are reading now)'
print ' quit : back to command interpreter'
print ' Typing any other 1-line statement will execute it'
print ' using the current level\'s symbol tables'
if tb
.tb_frame
.f_locals
is not tb
.tb_frame
.f_globals
:
printsymbols(tb
.tb_frame
.f_locals
)
filename
= tb
.tb_frame
.f_code
.co_filename
info
= '"' + filename
+ '"(' + `lineno`
+ ')'
line
= linecache
.getline(filename
, lineno
)
info
= info
+ ': ' + line
.strip()
print ' ' + name
.ljust(12) + ':',
def printobject(v
, maxlevel
):
elif type(v
) in (type(0), type(0.0)):
elif type(v
) is type(''):
elif type(v
) is type(()):
elif type(v
) is type([]):
elif type(v
) is type({}):
def printlist(v
, maxlevel
):
for i
in range(min(6, n
)):
printobject(v
[i
], maxlevel
-1)
def printdict(v
, maxlevel
):
for i
in range(min(6, n
)):
printobject(v
[key
], maxlevel
-1)