diff options
Diffstat (limited to 'editor.py')
| -rw-r--r-- | editor.py | 17 |
1 files changed, 10 insertions, 7 deletions
| @@ -68,11 +68,14 @@ least one of these before using this command.""", file=sys.stderr) | |||
| 68 | def EditString(cls, data): | 68 | def EditString(cls, data): |
| 69 | """Opens an editor to edit the given content. | 69 | """Opens an editor to edit the given content. |
| 70 | 70 | ||
| 71 | Args: | 71 | Args: |
| 72 | data : the text to edit | 72 | data: The text to edit. |
| 73 | 73 | ||
| 74 | Returns: | 74 | Returns: |
| 75 | new value of edited text; None if editing did not succeed | 75 | New value of edited text. |
| 76 | |||
| 77 | Raises: | ||
| 78 | EditorError: The editor failed to run. | ||
| 76 | """ | 79 | """ |
| 77 | editor = cls._GetEditor() | 80 | editor = cls._GetEditor() |
| 78 | if editor == ':': | 81 | if editor == ':': |
| @@ -80,7 +83,7 @@ least one of these before using this command.""", file=sys.stderr) | |||
| 80 | 83 | ||
| 81 | fd, path = tempfile.mkstemp() | 84 | fd, path = tempfile.mkstemp() |
| 82 | try: | 85 | try: |
| 83 | os.write(fd, data) | 86 | os.write(fd, data.encode('utf-8')) |
| 84 | os.close(fd) | 87 | os.close(fd) |
| 85 | fd = None | 88 | fd = None |
| 86 | 89 | ||
| @@ -106,8 +109,8 @@ least one of these before using this command.""", file=sys.stderr) | |||
| 106 | raise EditorError('editor failed with exit status %d: %s %s' | 109 | raise EditorError('editor failed with exit status %d: %s %s' |
| 107 | % (rc, editor, path)) | 110 | % (rc, editor, path)) |
| 108 | 111 | ||
| 109 | with open(path) as fd2: | 112 | with open(path, mode='rb') as fd2: |
| 110 | return fd2.read() | 113 | return fd2.read().decode('utf-8') |
| 111 | finally: | 114 | finally: |
| 112 | if fd: | 115 | if fd: |
| 113 | os.close(fd) | 116 | os.close(fd) |
