diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py --- a/mercurial/pycompat.py +++ b/mercurial/pycompat.py @@ -71,6 +71,9 @@ if ispy3: # 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 @@ if ispy3: return [a.encode('latin-1') for a in ret] else: + bytechr = chr + def sysstr(s): return s diff --git a/mercurial/store.py b/mercurial/store.py --- a/mercurial/store.py +++ b/mercurial/store.py @@ -99,12 +99,8 @@ def _buildencodefun(): '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) diff --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -40,12 +40,8 @@ from . import ( 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':