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

Method send_to_external_editor

bpython/repl.py:1196–1211  ·  view source on GitHub ↗

Returns modified text from an editor, or the original text if editor exited with non-zero

(self, text: str)

Source from the content-addressed store, hash-verified

1194 It prevents autoindentation from occurring after a traceback."""
1195
1196 def send_to_external_editor(self, text: str) -> str:
1197 """Returns modified text from an editor, or the original text if editor
1198 exited with non-zero"""
1199
1200 encoding = getpreferredencoding()
1201 editor_args = shlex.split(self.config.editor)
1202 with tempfile.NamedTemporaryFile(suffix=".py") as temp:
1203 temp.write(text.encode(encoding))
1204 temp.flush()
1205
1206 args = editor_args + [temp.name]
1207 if subprocess.call(args) == 0:
1208 with open(temp.name) as f:
1209 return f.read()
1210 else:
1211 return text
1212
1213 def open_in_external_editor(self, filename):
1214 editor_args = shlex.split(self.config.editor)

Calls 4

getpreferredencodingFunction · 0.85
callMethod · 0.80
writeMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected