jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/616213 )

Change subject: [4.0] remove UnicodeType and Python 2 related code
......................................................................

[4.0] remove UnicodeType and Python 2 related code

Also use tempfile.mkstemp instead of tempfile.mktemp which is
deprecated since Python 2.3

Change-Id: Ib32e2069f0ca914d2e104282186825488ac95a93
---
M scripts/piper.py
1 file changed, 9 insertions(+), 16 deletions(-)

Approvals:
  D3r1ck01: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/scripts/piper.py b/scripts/piper.py
index 726e9f7..f89bc98 100755
--- a/scripts/piper.py
+++ b/scripts/piper.py
@@ -31,12 +31,10 @@
 &params;
 """
 #
-# (C) Pywikibot team, 2008-2019
+# (C) Pywikibot team, 2008-2020
 #
 # Distributed under the terms of the MIT license.
 #
-from __future__ import absolute_import, division, unicode_literals
-
 import os
 import pipes
 import tempfile
@@ -46,7 +44,6 @@
 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.
@@ -71,38 +68,34 @@
         self.availableOptions.update({
             'filters': [],
         })
-        super(PiperBot, self).__init__(generator=generator, **kwargs)
+        super().__init__(generator=generator, **kwargs)

     @property
-    def summary_parameters(self):
+    def summary_parameters(self) -> dict:
         """Return the filter parameter."""
         return {'filters': ', '.join(self.getOption('filters'))}

-    def pipe(self, program, text):
+    def pipe(self, program: str, text: str) -> str:
         """Pipe a given text through a given program.

         @return: processed text after piping
-        @rtype: str
         """
-        if not isinstance(text, str):  # py2-py3 compatibility
-            text = text.encode('utf-8')
         pipe = pipes.Template()
-        pipe.append(str(program), '--')  # py2-py3 compatibility
+        pipe.append(program, '--')

         # Create a temporary filename to save the piped stuff to
-        temp_filename = '%s.%s' % (tempfile.mktemp(), 'txt')
+        file, temp_filename = tempfile.mkstemp(suffix='.txt')
+        file.close()
         with pipe.open(temp_filename, 'w') as file:
             file.write(text)

         # Now retrieve the munged text
         with open(temp_filename, 'r') as file:
-            unicode_text = file.read()
-        if not isinstance(unicode_text, UnicodeType):  # py2-py3 compatibility
-            unicode_text = unicode_text.decode('utf-8')
+            text = file.read()

         # clean up
         os.unlink(temp_filename)
-        return unicode_text
+        return text

     def treat_page(self):
         """Load the given page, do some changes, and save it."""

--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/616213
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ib32e2069f0ca914d2e104282186825488ac95a93
Gerrit-Change-Number: 616213
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: D3r1ck01 <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to