1 # Format and print Python stack traces
7 def print_tb(tb
, limit
= None):
9 if hasattr(sys
, 'tracebacklimit'):
10 limit
= sys
.tracebacklimit
12 while tb
is not None and (limit
is None or n
< limit
):
16 filename
= co
.co_filename
18 print ' File "%s", line %d, in %s' % (filename
, lineno
, name
)
19 line
= linecache
.getline(filename
, lineno
)
20 if line
: print ' ' + string
.strip(line
)
24 def extract_tb(tb
, limit
= None):
26 if hasattr(sys
, 'tracebacklimit'):
27 limit
= sys
.tracebacklimit
30 while tb
is not None and (limit
is None or n
< limit
):
34 filename
= co
.co_filename
36 line
= linecache
.getline(filename
, lineno
)
37 if line
: line
= string
.strip(line
)
39 list.append(filename
, lineno
, name
, line
)
44 def print_exception(type, value
, tb
, limit
= None):
46 print 'Traceback (innermost last):'
51 if type is SyntaxError:
53 msg
, (filename
, lineno
, offset
, line
) = value
57 if not filename
: filename
= "<string>"
58 print ' File "%s", line %d' % (filename
, lineno
)
60 while i
< len(line
) and line
[i
] in string
.whitespace
:
63 print s
+ string
.strip(line
)
64 for c
in line
[i
:offset
-1]:
65 if c
in string
.whitespace
:
71 print '%s: %s' % (type, value
)
73 def print_exc(limit
= None):
74 print_exception(sys
.exc_type
, sys
.exc_value
, sys
.exc_traceback
,
77 def print_last(limit
= None):
78 print_exception(sys
.last_type
, sys
.last_value
, sys
.last_traceback
,