Xqt has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/337224
)
Change subject: piper.py: fix bytes/str handling in python3
......................................................................
piper.py: fix bytes/str handling in python3
Avoid to convert to bytes in python3.
Bug: T157215
Change-Id: I2c3d7611b5aca32b4b51339c4a162851e13bacf7
---
M scripts/piper.py
1 file changed, 8 insertions(+), 4 deletions(-)
Approvals:
jenkins-bot: Verified
Merlijn van Deen: Looks good to me, approved
diff --git a/scripts/piper.py b/scripts/piper.py
index d15e4c8..4a373ec 100755
--- a/scripts/piper.py
+++ b/scripts/piper.py
@@ -47,6 +47,7 @@
from pywikibot import pagegenerators
from pywikibot.bot import (MultipleSitesBot, ExistingPageBot,
NoRedirectPageBot, AutomaticTWSummaryBot)
+from pywikibot.tools import UnicodeType
# This is required for the text that is shown when you run this script
# with the parameter -help.
@@ -86,9 +87,10 @@
@return: processed text after piping
@rtype: unicode
"""
- text = text.encode('utf-8')
+ if not isinstance(text, str): # py2-py3 compatibility
+ text = text.encode('utf-8')
pipe = pipes.Template()
- pipe.append(program.encode('ascii'), '--')
+ pipe.append(str(program), '--') # py2-py3 compatibility
# Create a temporary filename to save the piped stuff to
tempFilename = '%s.%s' % (tempfile.mktemp(), 'txt')
@@ -96,8 +98,10 @@
file.write(text)
# Now retrieve the munged text
- with open(tempFilename, 'r') as mungedText:
- unicode_text = mungedText.read().decode('utf-8')
+ with open(tempFilename, 'r') as file:
+ unicode_text = file.read()
+ if not isinstance(unicode_text, UnicodeType): # py2-py3 compatibility
+ unicode_text = unicode_text.decode('utf-8')
# clean up
os.unlink(tempFilename)
--
To view, visit
https://gerrit.wikimedia.org/r/337224
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I2c3d7611b5aca32b4b51339c4a162851e13bacf7
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>