Пример #1
0
 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 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
Пример #3
0
    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
Пример #4
0
    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