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