|
45 | 45 | from pygments.token import Token |
46 | 46 |
|
47 | 47 | from bpython import inspection |
48 | | -from bpython._py3compat import PythonLexer, py3 |
| 48 | +from bpython._py3compat import PythonLexer, py3, prepare_for_exec |
49 | 49 | from bpython.formatter import Parenthesis |
50 | 50 | from bpython.translations import _, ngettext |
51 | 51 | from bpython.clipboard import get_clipboard, CopyFailed |
@@ -1029,22 +1029,30 @@ def clear_current_line(self): |
1029 | 1029 | def send_to_external_editor(self, text, filename=None): |
1030 | 1030 | """Returns modified text from an editor, or the oriignal text if editor |
1031 | 1031 | exited with non-zero""" |
1032 | | - editor_args = shlex.split(self.config.editor) |
| 1032 | + |
| 1033 | + encoding = getpreferredencoding() |
| 1034 | + editor_args = shlex.split(prepare_for_exec(self.config.editor, |
| 1035 | + encoding)) |
1033 | 1036 | with tempfile.NamedTemporaryFile(suffix='.py') as temp: |
1034 | | - temp.write(text.encode(getpreferredencoding())) |
| 1037 | + temp.write(text.encode(encoding)) |
1035 | 1038 | temp.flush() |
1036 | | - if subprocess.call(editor_args + [temp.name]) == 0: |
| 1039 | + |
| 1040 | + args = editor_args + [prepare_for_exec(temp.name, encoding)] |
| 1041 | + if subprocess.call(args) == 0: |
1037 | 1042 | with open(temp.name) as f: |
1038 | 1043 | if py3: |
1039 | 1044 | return f.read() |
1040 | 1045 | else: |
1041 | | - return f.read().decode(getpreferredencoding()) |
| 1046 | + return f.read().decode(encoding) |
1042 | 1047 | else: |
1043 | 1048 | return text |
1044 | 1049 |
|
1045 | 1050 | def open_in_external_editor(self, filename): |
1046 | | - editor_args = shlex.split(self.config.editor) |
1047 | | - if subprocess.call(editor_args + [filename]) == 0: |
| 1051 | + encoding = getpreferredencoding() |
| 1052 | + editor_args = shlex.split(prepare_for_exec(self.config.editor, |
| 1053 | + encoding)) |
| 1054 | + args = editor_args + [prepare_for_exec(filename, encoding)] |
| 1055 | + if subprocess.call(args) == 0: |
1048 | 1056 | return True |
1049 | 1057 | return False |
1050 | 1058 |
|
|
0 commit comments