| 979 | |
| 980 | |
| 981 | class _ExceptionPrintContext: |
| 982 | def __init__(self): |
| 983 | self.seen = set() |
| 984 | self.exception_group_depth = 0 |
| 985 | self.need_close = False |
| 986 | |
| 987 | def indent(self): |
| 988 | return ' ' * (2 * self.exception_group_depth) |
| 989 | |
| 990 | def emit(self, text_gen, margin_char=None): |
| 991 | if margin_char is None: |
| 992 | margin_char = '|' |
| 993 | indent_str = self.indent() |
| 994 | if self.exception_group_depth: |
| 995 | indent_str += margin_char + ' ' |
| 996 | |
| 997 | if isinstance(text_gen, str): |
| 998 | yield textwrap.indent(text_gen, indent_str, lambda line: True) |
| 999 | else: |
| 1000 | for text in text_gen: |
| 1001 | yield textwrap.indent(text, indent_str, lambda line: True) |
| 1002 | |
| 1003 | |
| 1004 | class TracebackException: |