jenkins-bot has submitted this change and it was merged.
Change subject: Make editor.py python3-compatible ......................................................................
Make editor.py python3-compatible
Write/read tempfile in binary mode to prevent errors when writing bytes in py3, after encoding.
Also fixed pep257 doc-strings.
Change-Id: Id88e449dd48bd503adbd731746ddec8fd5476a42 --- M pywikibot/editor.py 1 file changed, 5 insertions(+), 2 deletions(-)
Approvals: XZise: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/editor.py b/pywikibot/editor.py index 6cdcf52..572d174 100644 --- a/pywikibot/editor.py +++ b/pywikibot/editor.py @@ -23,6 +23,7 @@ """Text editor."""
def command(self, tempFilename, text, jumpIndex=None): + """Return editor selected in user-config.py.""" command = config.editor if jumpIndex: # Some editors make it possible to mark occurences of substrings, @@ -56,12 +57,14 @@ return command
def convertLinebreaks(self, text): + """Convert line-breaks.""" if sys.platform == 'win32': return text.replace('\r\n', '\n') # TODO: Mac OS handling return text
def restoreLinebreaks(self, text): + """Restore line-breaks.""" if text is None: return if sys.platform == 'win32': @@ -87,7 +90,7 @@ if config.editor: tempFilename = '%s.%s' % (tempfile.mktemp(), config.editor_filename_extension) - tempFile = open(tempFilename, 'w') + tempFile = open(tempFilename, 'wb') tempFile.write(text.encode(config.editor_encoding)) tempFile.close() creationDate = os.stat(tempFilename).st_mtime @@ -98,7 +101,7 @@ # Nothing changed return None else: - newcontent = open(tempFilename).read().decode(config.editor_encoding) + newcontent = open(tempFilename, 'rb').read().decode(config.editor_encoding) os.unlink(tempFilename) return self.restoreLinebreaks(newcontent) else:
pywikibot-commits@lists.wikimedia.org