Format the stack ready for printing. Returns a list of strings ready for printing. Each string in the resulting list corresponds to a single frame from the stack. Each string ends in a newline; the strings may contain internal newlines as well, for those items with
(self, **kwargs)
| 759 | return False |
| 760 | |
| 761 | def format(self, **kwargs): |
| 762 | """Format the stack ready for printing. |
| 763 | |
| 764 | Returns a list of strings ready for printing. Each string in the |
| 765 | resulting list corresponds to a single frame from the stack. |
| 766 | Each string ends in a newline; the strings may contain internal |
| 767 | newlines as well, for those items with source text lines. |
| 768 | |
| 769 | For long sequences of the same frame and line, the first few |
| 770 | repetitions are shown, followed by a summary line stating the exact |
| 771 | number of further repetitions. |
| 772 | """ |
| 773 | colorize = kwargs.get("colorize", False) |
| 774 | result = [] |
| 775 | last_file = None |
| 776 | last_line = None |
| 777 | last_name = None |
| 778 | count = 0 |
| 779 | for frame_summary in self: |
| 780 | formatted_frame = self.format_frame_summary(frame_summary, colorize=colorize) |
| 781 | if formatted_frame is None: |
| 782 | continue |
| 783 | if (last_file is None or last_file != frame_summary.filename or |
| 784 | last_line is None or last_line != frame_summary.lineno or |
| 785 | last_name is None or last_name != frame_summary.name): |
| 786 | if count > _RECURSIVE_CUTOFF: |
| 787 | count -= _RECURSIVE_CUTOFF |
| 788 | result.append( |
| 789 | f' [Previous line repeated {count} more ' |
| 790 | f'time{"s" if count > 1 else ""}]\n' |
| 791 | ) |
| 792 | last_file = frame_summary.filename |
| 793 | last_line = frame_summary.lineno |
| 794 | last_name = frame_summary.name |
| 795 | count = 0 |
| 796 | count += 1 |
| 797 | if count > _RECURSIVE_CUTOFF: |
| 798 | continue |
| 799 | result.append(formatted_frame) |
| 800 | |
| 801 | if count > _RECURSIVE_CUTOFF: |
| 802 | count -= _RECURSIVE_CUTOFF |
| 803 | result.append( |
| 804 | f' [Previous line repeated {count} more ' |
| 805 | f'time{"s" if count > 1 else ""}]\n' |
| 806 | ) |
| 807 | return result |
| 808 | |
| 809 | |
| 810 | def _byte_offset_to_character_offset(str, offset): |
no test coverage detected