Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2369)

Side by Side Diff: Lib/traceback.py

Issue 6210: Exception Chaining missing method for suppressing context
Patch Set: Created 1 year, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_traceback.py ('k') | Misc/ACKS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Extract, format and print information about Python stack traces.""" 1 """Extract, format and print information about Python stack traces."""
2 2
3 import linecache 3 import linecache
4 import sys 4 import sys
5 5
6 __all__ = ['extract_stack', 'extract_tb', 'format_exception', 6 __all__ = ['extract_stack', 'extract_tb', 'format_exception',
7 'format_exception_only', 'format_list', 'format_stack', 7 'format_exception_only', 'format_list', 'format_stack',
8 'format_tb', 'print_exc', 'format_exc', 'print_exception', 8 'format_tb', 'print_exc', 'format_exc', 'print_exception',
9 'print_last', 'print_stack', 'print_tb'] 9 'print_last', 'print_stack', 'print_tb']
10 10
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 _context_message = ( 113 _context_message = (
114 "\nDuring handling of the above exception, " 114 "\nDuring handling of the above exception, "
115 "another exception occurred:\n") 115 "another exception occurred:\n")
116 116
117 def _iter_chain(exc, custom_tb=None, seen=None): 117 def _iter_chain(exc, custom_tb=None, seen=None):
118 if seen is None: 118 if seen is None:
119 seen = set() 119 seen = set()
120 seen.add(exc) 120 seen.add(exc)
121 its = [] 121 its = []
122 cause = exc.__cause__ 122 cause = exc.__cause__
123 if cause is not None and cause not in seen: 123 if cause is Ellipsis:
124 its.append(_iter_chain(cause, None, seen))
125 its.append([(_cause_message, None)])
126 else:
127 context = exc.__context__ 124 context = exc.__context__
128 if context is not None and context not in seen: 125 if context is not None and context not in seen:
129 its.append(_iter_chain(context, None, seen)) 126 its.append(_iter_chain(context, None, seen))
130 its.append([(_context_message, None)]) 127 its.append([(_context_message, None)])
128 elif cause is not None and cause not in seen:
129 its.append(_iter_chain(cause, False, seen))
130 its.append([(_cause_message, None)])
131 its.append([(exc, custom_tb or exc.__traceback__)]) 131 its.append([(exc, custom_tb or exc.__traceback__)])
132 # itertools.chain is in an extension module and may be unavailable 132 # itertools.chain is in an extension module and may be unavailable
133 for it in its: 133 for it in its:
134 for x in it: 134 for x in it:
135 yield x 135 yield x
136 136
137 137
138 def print_exception(etype, value, tb, limit=None, file=None, chain=True): 138 def print_exception(etype, value, tb, limit=None, file=None, chain=True):
139 """Print exception up to 'limit' stack trace entries from 'tb' to 'file'. 139 """Print exception up to 'limit' stack trace entries from 'tb' to 'file'.
140 140
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 name = co.co_name 331 name = co.co_name
332 linecache.checkcache(filename) 332 linecache.checkcache(filename)
333 line = linecache.getline(filename, lineno, f.f_globals) 333 line = linecache.getline(filename, lineno, f.f_globals)
334 if line: line = line.strip() 334 if line: line = line.strip()
335 else: line = None 335 else: line = None
336 list.append((filename, lineno, name, line)) 336 list.append((filename, lineno, name, line))
337 f = f.f_back 337 f = f.f_back
338 n = n+1 338 n = n+1
339 list.reverse() 339 list.reverse()
340 return list 340 return list
OLDNEW
« no previous file with comments | « Lib/test/test_traceback.py ('k') | Misc/ACKS » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld cbc36f91f3f7