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
(self)
| 518 | return ''.join(row) |
| 519 | |
| 520 | def format(self): |
| 521 | """Format the stack ready for printing. |
| 522 | |
| 523 | Returns a list of strings ready for printing. Each string in the |
| 524 | resulting list corresponds to a single frame from the stack. |
| 525 | Each string ends in a newline; the strings may contain internal |
| 526 | newlines as well, for those items with source text lines. |
| 527 | |
| 528 | For long sequences of the same frame and line, the first few |
| 529 | repetitions are shown, followed by a summary line stating the exact |
| 530 | number of further repetitions. |
| 531 | """ |
| 532 | result = [] |
| 533 | last_file = None |
| 534 | last_line = None |
| 535 | last_name = None |
| 536 | count = 0 |
| 537 | for frame_summary in self: |
| 538 | formatted_frame = self.format_frame_summary(frame_summary) |
| 539 | if formatted_frame is None: |
| 540 | continue |
| 541 | if (last_file is None or last_file != frame_summary.filename or |
| 542 | last_line is None or last_line != frame_summary.lineno or |
| 543 | last_name is None or last_name != frame_summary.name): |
| 544 | if count > _RECURSIVE_CUTOFF: |
| 545 | count -= _RECURSIVE_CUTOFF |
| 546 | result.append( |
| 547 | f' [Previous line repeated {count} more ' |
| 548 | f'time{"s" if count > 1 else ""}]\n' |
| 549 | ) |
| 550 | last_file = frame_summary.filename |
| 551 | last_line = frame_summary.lineno |
| 552 | last_name = frame_summary.name |
| 553 | count = 0 |
| 554 | count += 1 |
| 555 | if count > _RECURSIVE_CUTOFF: |
| 556 | continue |
| 557 | result.append(formatted_frame) |
| 558 | |
| 559 | if count > _RECURSIVE_CUTOFF: |
| 560 | count -= _RECURSIVE_CUTOFF |
| 561 | result.append( |
| 562 | f' [Previous line repeated {count} more ' |
| 563 | f'time{"s" if count > 1 else ""}]\n' |
| 564 | ) |
| 565 | return result |
| 566 | |
| 567 | |
| 568 | def _byte_offset_to_character_offset(str, offset): |
no test coverage detected