Return formatted and marked up source lines.
(
self,
source: Optional["Source"],
line_index: int = -1,
excinfo: Optional[ExceptionInfo[BaseException]] = None,
short: bool = False,
)
| 729 | return None |
| 730 | |
| 731 | def get_source( |
| 732 | self, |
| 733 | source: Optional["Source"], |
| 734 | line_index: int = -1, |
| 735 | excinfo: Optional[ExceptionInfo[BaseException]] = None, |
| 736 | short: bool = False, |
| 737 | ) -> List[str]: |
| 738 | """Return formatted and marked up source lines.""" |
| 739 | lines = [] |
| 740 | if source is None or line_index >= len(source.lines): |
| 741 | source = Source("???") |
| 742 | line_index = 0 |
| 743 | if line_index < 0: |
| 744 | line_index += len(source) |
| 745 | space_prefix = " " |
| 746 | if short: |
| 747 | lines.append(space_prefix + source.lines[line_index].strip()) |
| 748 | else: |
| 749 | for line in source.lines[:line_index]: |
| 750 | lines.append(space_prefix + line) |
| 751 | lines.append(self.flow_marker + " " + source.lines[line_index]) |
| 752 | for line in source.lines[line_index + 1 :]: |
| 753 | lines.append(space_prefix + line) |
| 754 | if excinfo is not None: |
| 755 | indent = 4 if short else self._getindent(source) |
| 756 | lines.extend(self.get_exconly(excinfo, indent=indent, markall=True)) |
| 757 | return lines |
| 758 | |
| 759 | def get_exconly( |
| 760 | self, |