changeset 30344:19d8e19fde5b

py3: document why os.fsencode() can be used to get back bytes argv And a possible Windows issue. I'm sad we have to do such ugly hack, but that's the unicode on Python 3.
author Yuya Nishihara <yuya@tcha.org>
date Wed, 09 Nov 2016 22:06:09 +0900
parents 776a6d29b2cc
children 7d91a085ebe6
files mercurial/pycompat.py
diffstat 1 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/pycompat.py	Wed Nov 09 22:15:51 2016 +0900
+++ b/mercurial/pycompat.py	Wed Nov 09 22:06:09 2016 +0900
@@ -43,6 +43,14 @@
     osname = os.name.encode('ascii')
     ospathsep = os.pathsep.encode('ascii')
     ossep = os.sep.encode('ascii')
+
+    # Since Python 3 converts argv to wchar_t type by Py_DecodeLocale() on Unix,
+    # we can use os.fsencode() to get back bytes argv.
+    #
+    # https://hg.python.org/cpython/file/v3.5.1/Programs/python.c#l55
+    #
+    # TODO: On Windows, the native argv is wchar_t, so we'll need a different
+    # workaround to simulate the Python 2 (i.e. ANSI Win32 API) behavior.
     sysargv = list(map(os.fsencode, sys.argv))
 
     def sysstr(s):