jenkins-bot has submitted this change and it was merged.
Change subject: [IMPROV] Use codecs.open() ......................................................................
[IMPROV] Use codecs.open()
Instead of open the temporary file in binary mode it uses codecs.open to decode and encode automatically.
Change-Id: If586791174d273d26e33cb1a342f6f27319822ee --- M pywikibot/editor.py 1 file changed, 7 insertions(+), 4 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/editor.py b/pywikibot/editor.py index 572d174..e795928 100644 --- a/pywikibot/editor.py +++ b/pywikibot/editor.py @@ -14,6 +14,7 @@ import sys import os import tempfile +import codecs import pywikibot from pywikibot import config
@@ -90,9 +91,9 @@ if config.editor: tempFilename = '%s.%s' % (tempfile.mktemp(), config.editor_filename_extension) - tempFile = open(tempFilename, 'wb') - tempFile.write(text.encode(config.editor_encoding)) - tempFile.close() + with codecs.open(tempFilename, 'w', + encoding=config.editor_encoding) as tempFile: + tempFile.write(text) creationDate = os.stat(tempFilename).st_mtime command = self.command(tempFilename, text, jumpIndex) os.system(command) @@ -101,7 +102,9 @@ # Nothing changed return None else: - newcontent = open(tempFilename, 'rb').read().decode(config.editor_encoding) + with codecs.open(tempFilename, 'r', + encoding=config.editor_encoding) as temp_file: + newcontent = temp_file.read() os.unlink(tempFilename) return self.restoreLinebreaks(newcontent) else:
pywikibot-commits@lists.wikimedia.org