MCPcopy Index your code
hub / github.com/bpython/bpython / get_session_formatted_for_file

Method get_session_formatted_for_file

bpython/repl.py:868–884  ·  view source on GitHub ↗

Format the stdout buffer to something suitable for writing to disk, i.e. without >>> and ... at input lines and with "# OUT: " prepended to output lines and "### " prepended to current line

(self)

Source from the content-addressed store, hash-verified

866 raise NotImplementedError()
867
868 def get_session_formatted_for_file(self) -> str:
869 """Format the stdout buffer to something suitable for writing to disk,
870 i.e. without >>> and ... at input lines and with "# OUT: " prepended to
871 output lines and "### " prepended to current line"""
872
873 session_output = self.getstdout()
874
875 def process():
876 for line in session_output.split("\n"):
877 if line.startswith(self.ps1):
878 yield line[len(self.ps1) :]
879 elif line.startswith(self.ps2):
880 yield line[len(self.ps2) :]
881 elif line.rstrip():
882 yield f"# OUT: {line}"
883
884 return "\n".join(process())
885
886 def write2file(self) -> None:
887 """Prompt for a filename and write the current contents of the stdout

Callers 2

write2fileMethod · 0.95
copy2clipboardMethod · 0.95

Calls 1

getstdoutMethod · 0.95

Tested by

no test coverage detected