diff options
author | Guido van Rossum <guido@python.org> | 1996-08-26 18:33:32 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1996-08-26 18:33:32 (GMT) |
commit | a8763e54ff25a226e50b281671189382fd3c324c (patch) | |
tree | bea9ea9a9f5bb33cbdfef607b4a8ce5e6197e98b /Lib/dos_8x3/tracebac.py | |
parent | 52a42fe9e706fb51ec608571c2b60e7694a5d0a2 (diff) | |
download | cpython-a8763e54ff25a226e50b281671189382fd3c324c.zip cpython-a8763e54ff25a226e50b281671189382fd3c324c.tar.gz cpython-a8763e54ff25a226e50b281671189382fd3c324c.tar.bz2 |
Another batch of updates...
Diffstat (limited to 'Lib/dos_8x3/tracebac.py')
-rwxr-xr-x | Lib/dos_8x3/tracebac.py | 72 |
1 files changed, 65 insertions, 7 deletions
diff --git a/Lib/dos_8x3/tracebac.py b/Lib/dos_8x3/tracebac.py index 8d2dfdc..9823100 100755 --- a/Lib/dos_8x3/tracebac.py +++ b/Lib/dos_8x3/tracebac.py @@ -7,6 +7,25 @@ import types def _print(file, str='', terminator='\n'): file.write(str+terminator) + + +def print_list(extracted_list, file=None): + if not file: + file = sys.stderr + for filename, lineno, name, line in extracted_list: + _print(file, + ' File "%s", line %d, in %s' % (filename,lineno,name)) + if line: + _print(file, ' %s' % string.strip(line)) + +def format_list(extracted_list): + list = [] + for filename, lineno, name, line in extracted_list: + item = ' File "%s", line %d, in %s\n' % (filename,lineno,name) + if line: + item = item + ' %s\n' % string.strip(line) + list.append(item) + return list def print_tb(tb, limit=None, file=None): @@ -30,13 +49,7 @@ def print_tb(tb, limit=None, file=None): n = n+1 def format_tb(tb, limit = None): - list = [] - for filename, lineno, name, line in extract_tb(tb, limit): - item = ' File "%s", line %d, in %s\n' % (filename,lineno,name) - if line: - item = item + ' %s\n' % string.strip(line) - list.append(item) - return list + return format_list(extract_tb(tb, limit)) def extract_tb(tb, limit = None): if limit is None: @@ -123,3 +136,48 @@ def print_last(limit=None, file=None): file = sys.stderr print_exception(sys.last_type, sys.last_value, sys.last_traceback, limit, file) + + +def print_stack(f=None, limit=None, file=None): + if f is None: + try: + raise ZeroDivisionError + except ZeroDivisionError: + tb = sys.exc_traceback + f = tb.tb_frame.f_back + print_list(extract_stack(f, limit), file) + +def format_stack(f=None, limit=None): + if f is None: + try: + raise ZeroDivisionError + except ZeroDivisionError: + tb = sys.exc_traceback + f = tb.tb_frame.f_back + return format_list(extract_stack(t, limit)) + +def extract_stack(f=None, limit = None): + if f is None: + try: + raise ZeroDivisionError + except ZeroDivisionError: + tb = sys.exc_traceback + f = tb.tb_frame.f_back + if limit is None: + if hasattr(sys, 'tracebacklimit'): + limit = sys.tracebacklimit + list = [] + n = 0 + while f is not None and (limit is None or n < limit): + lineno = f.f_lineno + co = f.f_code + filename = co.co_filename + name = co.co_name + line = linecache.getline(filename, lineno) + if line: line = string.strip(line) + else: line = None + list.append(filename, lineno, name, line) + f = f.f_back + n = n+1 + list.reverse() + return list |