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

Change subject: [4.0] remove Python 2 code parts of win32_unicode.py
......................................................................

[4.0] remove Python 2 code parts of win32_unicode.py

Change-Id: I71b98a5ec6d49f72badd469b8007ed64205bf6eb
---
M pywikibot/userinterfaces/win32_unicode.py
1 file changed, 7 insertions(+), 57 deletions(-)

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



diff --git a/pywikibot/userinterfaces/win32_unicode.py 
b/pywikibot/userinterfaces/win32_unicode.py
index bdada00..e03d861 100755
--- a/pywikibot/userinterfaces/win32_unicode.py
+++ b/pywikibot/userinterfaces/win32_unicode.py
@@ -22,18 +22,14 @@
 # Licensed under both CC-BY-SA and the MIT license.
 #
 ################################################
-from __future__ import (absolute_import, division,
-                        print_function, unicode_literals)
-
 import codecs
 import sys

-from ctypes import Structure, byref, c_int, create_unicode_buffer, sizeof
+from contextlib import suppress
+from ctypes import Structure, byref, create_unicode_buffer, sizeof
 from ctypes import c_void_p as LPVOID
 from io import IOBase, UnsupportedOperation

-from pywikibot.tools import PY2, UnicodeType
-
 OSWIN32 = (sys.platform == 'win32')

 stdin = sys.stdin
@@ -45,7 +41,7 @@

 if OSWIN32:
     from ctypes import WINFUNCTYPE, windll, POINTER, WinError
-    from ctypes.wintypes import (BOOL, DWORD, HANDLE, LPCWSTR, LPWSTR,
+    from ctypes.wintypes import (BOOL, DWORD, HANDLE, LPWSTR,
                                  SHORT, ULONG, UINT, WCHAR)

 try:
@@ -77,11 +73,7 @@
                               byref(numrecv), None)
         if not result:
             raise Exception('stdin failure')
-        data = self.buffer.value[:numrecv.value]
-        if PY2:
-            return data.encode(self.encoding)
-        else:
-            return data
+        return self.buffer.value[:numrecv.value]


 class UnicodeOutput(IOBase):
@@ -117,11 +109,9 @@
         """Write the text to the output."""
         try:
             if self._hConsole is None:
-                if PY2 and isinstance(text, UnicodeType):
-                    text = text.encode('utf-8')
                 self._stream.write(text)
             else:
-                if not isinstance(text, UnicodeType):
+                if not isinstance(text, str):
                     text = bytes(text).decode('utf-8')
                 remaining = len(text)
                 while remaining > 0:
@@ -159,10 +149,9 @@
     # handle those like std streams which don't have fileno at all
     std = getattr(sys, 'std{0}'.format(std_name))
     if hasattr(std, 'fileno'):
-        try:
+        with suppress(UnsupportedOperation):
             return std.fileno()
-        except UnsupportedOperation:
-            pass
+    return None


 # If any exception occurs in this code, try to print it on stderr,
@@ -332,45 +321,6 @@
         _complain('exception {!r} while fixing up sys.stdout and sys.stderr'
                   .format(e))

-    if not PY2:
-        # no need to work around issue2128 since it's a Python 2 only issue
-        return stdin, stdout, stderr, argv
-
-    # While we're at it, let's unmangle the command-line arguments:
-
-    # This works around <http://bugs.python.org/issue2128>.
-    GetCommandLineW = WINFUNCTYPE(LPWSTR)(('GetCommandLineW', windll.kernel32))
-    CommandLineToArgvW = (WINFUNCTYPE(POINTER(LPWSTR), LPCWSTR, POINTER(c_int))
-                          (('CommandLineToArgvW', windll.shell32)))
-
-    argc = c_int(0)
-    argv_unicode = CommandLineToArgvW(GetCommandLineW(), byref(argc))
-
-    argv = [argv_unicode[i].encode('utf-8') for i in range(0, argc.value)]
-
-    if not hasattr(sys, 'frozen'):
-        # If this is an executable produced by py2exe or bbfreeze, then it will
-        # have been invoked directly. Otherwise, unicode_argv[0] is the Python
-        # interpreter, so skip that.
-        argv = argv[1:]
-
-        # Also skip option arguments to the Python interpreter.
-        while len(argv) > 0:
-            arg = argv[0]
-            if not arg.startswith(b'-') or arg == '-':
-                break
-            argv = argv[1:]
-            if arg == '-m':
-                # sys.argv[0] should really be the absolute path of the module
-                # source, but never mind
-                break
-            if arg == '-c':
-                argv[0] = '-c'
-                break
-
-    if argv == []:
-        argv = ['']
-
     return stdin, stdout, stderr, argv



--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/612604
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: I71b98a5ec6d49f72badd469b8007ed64205bf6eb
Gerrit-Change-Number: 612604
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Huji <[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