Returns modified text from an editor, or the original text if editor exited with non-zero
(self, text: str)
| 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) |
no test coverage detected