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)
pywikibot-commits@lists.wikimedia.org