comparison mercurial/pycompat.py @ 31253:64596338ba10

py3: factor out bytechr() function I also changed xrange(127) to range(127) as the number is relatively small.
author Yuya Nishihara <yuya@tcha.org>
date Wed, 08 Mar 2017 22:30:12 +0900
parents 76a64c1e5439
children 295625f1296b
comparison
equal deleted inserted replaced
31252:e7a35f18d91f 31253:64596338ba10
69 # 69 #
70 # TODO: On Windows, the native argv is wchar_t, so we'll need a different 70 # TODO: On Windows, the native argv is wchar_t, so we'll need a different
71 # workaround to simulate the Python 2 (i.e. ANSI Win32 API) behavior. 71 # workaround to simulate the Python 2 (i.e. ANSI Win32 API) behavior.
72 sysargv = list(map(os.fsencode, sys.argv)) 72 sysargv = list(map(os.fsencode, sys.argv))
73 73
74 def bytechr(i):
75 return bytes([i])
76
74 def sysstr(s): 77 def sysstr(s):
75 """Return a keyword str to be passed to Python functions such as 78 """Return a keyword str to be passed to Python functions such as
76 getattr() and str.encode() 79 getattr() and str.encode()
77 80
78 This never raises UnicodeDecodeError. Non-ascii characters are 81 This never raises UnicodeDecodeError. Non-ascii characters are
132 def shlexsplit(s): 135 def shlexsplit(s):
133 ret = shlex.split(s.decode('latin-1')) 136 ret = shlex.split(s.decode('latin-1'))
134 return [a.encode('latin-1') for a in ret] 137 return [a.encode('latin-1') for a in ret]
135 138
136 else: 139 else:
140 bytechr = chr
141
137 def sysstr(s): 142 def sysstr(s):
138 return s 143 return s
139 144
140 # Partial backport from os.py in Python 3, which only accepts bytes. 145 # Partial backport from os.py in Python 3, which only accepts bytes.
141 # In Python 2, our paths should only ever be bytes, a unicode path 146 # In Python 2, our paths should only ever be bytes, a unicode path