| 649 | |
| 650 | |
| 651 | class _ExceptionPrintContext: |
| 652 | def __init__(self): |
| 653 | self.seen = set() |
| 654 | self.exception_group_depth = 0 |
| 655 | self.need_close = False |
| 656 | |
| 657 | def indent(self): |
| 658 | return ' ' * (2 * self.exception_group_depth) |
| 659 | |
| 660 | def emit(self, text_gen, margin_char=None): |
| 661 | if margin_char is None: |
| 662 | margin_char = '|' |
| 663 | indent_str = self.indent() |
| 664 | if self.exception_group_depth: |
| 665 | indent_str += margin_char + ' ' |
| 666 | |
| 667 | if isinstance(text_gen, str): |
| 668 | yield textwrap.indent(text_gen, indent_str, lambda line: True) |
| 669 | else: |
| 670 | for text in text_gen: |
| 671 | yield textwrap.indent(text, indent_str, lambda line: True) |
| 672 | |
| 673 | |
| 674 | class TracebackException: |