Mercurial > hg-stable
changeset 31263: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 | e7a35f18d91f |
children | 2140e12d3258 |
files | mercurial/pycompat.py mercurial/store.py mercurial/ui.py |
diffstat | 3 files changed, 9 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/pycompat.py Thu Mar 02 13:34:01 2017 +0100 +++ b/mercurial/pycompat.py Wed Mar 08 22:30:12 2017 +0900 @@ -71,6 +71,9 @@ # workaround to simulate the Python 2 (i.e. ANSI Win32 API) behavior. sysargv = list(map(os.fsencode, sys.argv)) + def bytechr(i): + return bytes([i]) + def sysstr(s): """Return a keyword str to be passed to Python functions such as getattr() and str.encode() @@ -134,6 +137,8 @@ return [a.encode('latin-1') for a in ret] else: + bytechr = chr + def sysstr(s): return s
--- a/mercurial/store.py Thu Mar 02 13:34:01 2017 +0100 +++ b/mercurial/store.py Wed Mar 08 22:30:12 2017 +0900 @@ -99,12 +99,8 @@ 'the\\x07quick\\xadshot' ''' e = '_' - if pycompat.ispy3: - xchr = lambda x: bytes([x]) - asciistr = [bytes([a]) for a in range(127)] - else: - xchr = chr - asciistr = map(chr, xrange(127)) + xchr = pycompat.bytechr + asciistr = list(map(xchr, range(127))) capitals = list(range(ord("A"), ord("Z") + 1)) cmap = dict((x, x) for x in asciistr)
--- a/mercurial/ui.py Thu Mar 02 13:34:01 2017 +0100 +++ b/mercurial/ui.py Wed Mar 08 22:30:12 2017 +0900 @@ -40,12 +40,8 @@ urlreq = util.urlreq # for use with str.translate(None, _keepalnum), to keep just alphanumerics -if pycompat.ispy3: - _bytes = [bytes([c]) for c in range(256)] - _notalnum = [s for s in _bytes if not s.isalnum()] -else: - _notalnum = [c for c in map(chr, range(256)) if not c.isalnum()] -_keepalnum = ''.join(_notalnum) +_keepalnum = ''.join(c for c in map(pycompat.bytechr, range(256)) + if not c.isalnum()) samplehgrcs = { 'user':