Format the lines for a single FrameSummary. Returns a string representing one frame involved in the stack. This gets called for every frame to be printed in the stack summary.
(self, frame_summary, **kwargs)
| 542 | return result |
| 543 | |
| 544 | def format_frame_summary(self, frame_summary, **kwargs): |
| 545 | """Format the lines for a single FrameSummary. |
| 546 | |
| 547 | Returns a string representing one frame involved in the stack. This |
| 548 | gets called for every frame to be printed in the stack summary. |
| 549 | """ |
| 550 | colorize = kwargs.get("colorize", False) |
| 551 | row = [] |
| 552 | filename = frame_summary.filename |
| 553 | if frame_summary.filename.startswith("<stdin-") and frame_summary.filename.endswith('>'): |
| 554 | filename = "<stdin>" |
| 555 | if colorize: |
| 556 | theme = _colorize.get_theme(force_color=True).traceback |
| 557 | else: |
| 558 | theme = _colorize.get_theme(force_no_color=True).traceback |
| 559 | row.append( |
| 560 | ' File {}"{}"{}, line {}{}{}, in {}{}{}\n'.format( |
| 561 | theme.filename, |
| 562 | filename, |
| 563 | theme.reset, |
| 564 | theme.line_no, |
| 565 | frame_summary.lineno, |
| 566 | theme.reset, |
| 567 | theme.frame, |
| 568 | frame_summary.name, |
| 569 | theme.reset, |
| 570 | ) |
| 571 | ) |
| 572 | if frame_summary._dedented_lines and frame_summary._dedented_lines.strip(): |
| 573 | if ( |
| 574 | frame_summary.colno is None or |
| 575 | frame_summary.end_colno is None |
| 576 | ): |
| 577 | # only output first line if column information is missing |
| 578 | row.append(textwrap.indent(frame_summary.line, ' ') + "\n") |
| 579 | else: |
| 580 | # get first and last line |
| 581 | all_lines_original = frame_summary._original_lines.splitlines() |
| 582 | first_line = all_lines_original[0] |
| 583 | # assume all_lines_original has enough lines (since we constructed it) |
| 584 | last_line = all_lines_original[frame_summary.end_lineno - frame_summary.lineno] |
| 585 | |
| 586 | # character index of the start/end of the instruction |
| 587 | start_offset = _byte_offset_to_character_offset(first_line, frame_summary.colno) |
| 588 | end_offset = _byte_offset_to_character_offset(last_line, frame_summary.end_colno) |
| 589 | |
| 590 | all_lines = frame_summary._dedented_lines.splitlines()[ |
| 591 | :frame_summary.end_lineno - frame_summary.lineno + 1 |
| 592 | ] |
| 593 | |
| 594 | # adjust start/end offset based on dedent |
| 595 | dedent_characters = len(first_line) - len(all_lines[0]) |
| 596 | start_offset = max(0, start_offset - dedent_characters) |
| 597 | end_offset = max(0, end_offset - dedent_characters) |
| 598 | |
| 599 | # When showing this on a terminal, some of the non-ASCII characters |
| 600 | # might be rendered as double-width characters, so we need to take |
| 601 | # that into account when calculating the length of the line. |
no test coverage detected