def open_in_external_editor(self, filename): encoding = getpreferredencoding() editor_args = shlex.split(prepare_for_exec(self.config.editor, encoding)) args = editor_args + [prepare_for_exec(filename, encoding)] if subprocess.call(args) == 0: return True return False
def send_to_external_editor(self, text, filename=None): """Returns modified text from an editor, or the oriignal text if editor exited with non-zero""" encoding = getpreferredencoding() editor_args = shlex.split(prepare_for_exec(self.config.editor, encoding)) with tempfile.NamedTemporaryFile(suffix='.py') as temp: temp.write(text.encode(encoding)) temp.flush() args = editor_args + [prepare_for_exec(temp.name, encoding)] if subprocess.call(args) == 0: with open(temp.name) as f: if py3: return f.read() else: return f.read().decode(encoding) else: return text