Only return unicode params from get_os_args if unchanged.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parent ed978a6 · Browse files · 2 files·+28 added−20 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+28 added−20 removed
- other:+28 added−20 removed
Provenance
- Commit
0859d19- Tree
f8d63f5- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
ed978a6
2 files changed+28 added−20 removed
modified:click/_winconsole.py+23 added-18 removed
8 unmodified lines9 # echo and prmopt.10 11 import io12 import sys13+import zlib14 import ctypes15 from click._compat import _NonClosingTextIOWrapper, text_type, PY216 from ctypes import byref, POINTER, pythonapi, c_int, c_char, c_char_p, \17 c_void_p, py_object, c_ssize_t, c_ulong, windll, WINFUNCTYPE18 from ctypes.wintypes import LPWSTR, LPCWSTR19 20 20-PY2 = sys.version_info[0] == 221-21 c_ssize_p = POINTER(c_ssize_t)22 23 PyObject_GetBuffer = pythonapi.PyObject_GetBuffer24 PyBuffer_Release = pythonapi.PyBuffer_Release185 unmodified lines210 'utf-16-le', 'strict', line_buffering=True)211 return ConsoleStream(text_stream, buffer_stream)212 213 215-def _get_windows_argv():216- argc = c_int(0)217- argv_unicode = CommandLineToArgvW(GetCommandLineW(), byref(argc))218- argv = [argv_unicode[i] for i in range(0, argc.value)]214+if PY2:215+ def _hash_py_argv():216+ return zlib.crc32('\x00'.join(sys.argv[1:]))217 220- if not hasattr(sys, 'frozen'):221- argv = argv[1:]222- while len(argv) > 0:223- arg = argv[0]224- if not arg.startswith('-') or arg == '-':225- break218+ _initial_argv_hash = _hash_py_argv()219+220+ def _get_windows_argv():221+ argc = c_int(0)222+ argv_unicode = CommandLineToArgvW(GetCommandLineW(), byref(argc))223+ argv = [argv_unicode[i] for i in range(0, argc.value)]224+225+ if not hasattr(sys, 'frozen'):226 argv = argv[1:]227+ while len(argv) > 0:228+ arg = argv[0]229+ if not arg.startswith('-') or arg == '-':230+ break231+ argv = argv[1:]227- if arg == '-m':228- break229- if arg == '-c':230- argv[0] = u'-c'231- break232+ if arg == '-m':233+ break234+ if arg == '-c':235+ argv[0] = u'-c'236+ break237 233- return argv238+ return argv239 240 241 _stream_factories = {242 0: _get_text_stdin,16 unmodified linesmodified:click/utils.py+5 added-2 removed
10 unmodified lines11 12 if not PY2:13 from ._compat import _find_binary_writer14 elif WIN:15- from ._winconsole import _get_windows_argv15+ from ._winconsole import _get_windows_argv, \16+ _hash_py_argv, _initial_argv_hash17 18 19 echo_native_types = string_types + (bytes, bytearray)20 383 unmodified lines404 carry all possible values that sys.argv can have.405 406 .. versionadded:: 6.0407 """407- if PY2 and WIN:408+ # We can only extract the unicode argv if sys.argv has not been409+ # changed since the startup of the application.410+ if PY2 and WIN and _initial_argv_hash == _hash_py_argv():411 return _get_windows_argv()412 return sys.argv[1:]413 414 66 unmodified lines