Mercurial > hg
comparison mercurial/pycompat.py @ 30334: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 | a2f2f694dce9 |
children | 277f4fe6d01a |
comparison
equal
deleted
inserted
replaced
30333:776a6d29b2cc | 30334:19d8e19fde5b |
---|---|
41 fsdecode = os.fsdecode | 41 fsdecode = os.fsdecode |
42 # A bytes version of os.name. | 42 # A bytes version of os.name. |
43 osname = os.name.encode('ascii') | 43 osname = os.name.encode('ascii') |
44 ospathsep = os.pathsep.encode('ascii') | 44 ospathsep = os.pathsep.encode('ascii') |
45 ossep = os.sep.encode('ascii') | 45 ossep = os.sep.encode('ascii') |
46 | |
47 # Since Python 3 converts argv to wchar_t type by Py_DecodeLocale() on Unix, | |
48 # we can use os.fsencode() to get back bytes argv. | |
49 # | |
50 # https://hg.python.org/cpython/file/v3.5.1/Programs/python.c#l55 | |
51 # | |
52 # TODO: On Windows, the native argv is wchar_t, so we'll need a different | |
53 # workaround to simulate the Python 2 (i.e. ANSI Win32 API) behavior. | |
46 sysargv = list(map(os.fsencode, sys.argv)) | 54 sysargv = list(map(os.fsencode, sys.argv)) |
47 | 55 |
48 def sysstr(s): | 56 def sysstr(s): |
49 """Return a keyword str to be passed to Python functions such as | 57 """Return a keyword str to be passed to Python functions such as |
50 getattr() and str.encode() | 58 getattr() and str.encode() |