comparison mercurial/pycompat.py @ 30330:a2f2f694dce9

py3: have bytes version of sys.argv sys.argv returns unicodes on Python 3. We need a bytes version for us. There was also a python bug/feature request which wanted then to implement one. They rejected and it is quoted in one of the comments that we can use fsencode() to get a bytes version of sys.argv. Though not sure about its correctness. Link to the comment: http://bugs.python.org/issue8776#msg217416 After this patch we will have pycompat.sysargv which will return us bytes version of sys.argv. If this patch goes in, i will like to make transformer rewrite sys.argv with pycompat.argv because there are lot of occurences.
author Pulkit Goyal <7895pulkit@gmail.com>
date Sun, 06 Nov 2016 04:36:26 +0530
parents e0d9b6aab4c5
children 19d8e19fde5b
comparison
equal deleted inserted replaced
30329:dadb00a0ec0f 30330:a2f2f694dce9
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 sysargv = list(map(os.fsencode, sys.argv))
46 47
47 def sysstr(s): 48 def sysstr(s):
48 """Return a keyword str to be passed to Python functions such as 49 """Return a keyword str to be passed to Python functions such as
49 getattr() and str.encode() 50 getattr() and str.encode()
50 51
89 return filename 90 return filename
90 91
91 osname = os.name 92 osname = os.name
92 ospathsep = os.pathsep 93 ospathsep = os.pathsep
93 ossep = os.sep 94 ossep = os.sep
95 sysargv = sys.argv
94 96
95 stringio = io.StringIO 97 stringio = io.StringIO
96 empty = _queue.Empty 98 empty = _queue.Empty
97 queue = _queue.Queue 99 queue = _queue.Queue
98 100