|
33 | 33 | import textwrap |
34 | 34 | import time |
35 | 35 | import traceback |
36 | | -from enum import Enum |
37 | 36 | from itertools import takewhile |
38 | 37 | from pathlib import Path |
39 | 38 | from pygments.lexers import Python3Lexer |
@@ -355,14 +354,6 @@ class SourceNotFound(Exception): |
355 | 354 | """Exception raised when the requested source could not be found.""" |
356 | 355 |
|
357 | 356 |
|
358 | | -class LineTypeTranslator(Enum): |
359 | | - """Used when adding a tuple to all_logical_lines, to get input / output values |
360 | | - having to actually type/know the strings""" |
361 | | - |
362 | | - INPUT = "input" |
363 | | - OUTPUT = "output" |
364 | | - |
365 | | - |
366 | 357 | class Repl: |
367 | 358 | """Implements the necessary guff for a Python-repl-alike interface |
368 | 359 |
|
@@ -778,37 +769,23 @@ def line_is_empty(line): |
778 | 769 | indentation = 0 |
779 | 770 | return indentation |
780 | 771 |
|
781 | | - def get_session_formatted_for_file(self): |
| 772 | + def get_session_formatted_for_file(self) -> str: |
782 | 773 | """Format the stdout buffer to something suitable for writing to disk, |
783 | 774 | i.e. without >>> and ... at input lines and with "# OUT: " prepended to |
784 | 775 | output lines and "### " prepended to current line""" |
785 | 776 |
|
786 | | - if hasattr(self, "all_logical_lines"): |
787 | | - # Curtsies |
788 | | - |
789 | | - def process(): |
790 | | - for line, lineType in self.all_logical_lines: |
791 | | - if lineType == LineTypeTranslator.INPUT: |
792 | | - yield line |
793 | | - elif line.rstrip(): |
794 | | - yield "# OUT: %s" % line |
795 | | - yield "### %s" % self.current_line |
796 | | - |
797 | | - return "\n".join(process()) |
798 | | - |
799 | | - else: # cli and Urwid |
800 | | - session_output = self.getstdout() |
| 777 | + session_output = self.getstdout() |
801 | 778 |
|
802 | | - def process(): |
803 | | - for line in session_output.split("\n"): |
804 | | - if line.startswith(self.ps1): |
805 | | - yield line[len(self.ps1) :] |
806 | | - elif line.startswith(self.ps2): |
807 | | - yield line[len(self.ps2) :] |
808 | | - elif line.rstrip(): |
809 | | - yield f"# OUT: {line}" |
| 779 | + def process(): |
| 780 | + for line in session_output.split("\n"): |
| 781 | + if line.startswith(self.ps1): |
| 782 | + yield line[len(self.ps1) :] |
| 783 | + elif line.startswith(self.ps2): |
| 784 | + yield line[len(self.ps2) :] |
| 785 | + elif line.rstrip(): |
| 786 | + yield f"# OUT: {line}" |
810 | 787 |
|
811 | | - return "\n".join(process()) |
| 788 | + return "\n".join(process()) |
812 | 789 |
|
813 | 790 | def write2file(self): |
814 | 791 | """Prompt for a filename and write the current contents of the stdout |
|
0 commit comments