comparison mercurial/pycompat.py @ 36265:b44fac3a49fb

py3: factor out byterepr() which returns an asciified value on py3
author Yuya Nishihara <yuya@tcha.org>
date Sat, 17 Feb 2018 18:09:56 +0900
parents 646002338365
children 4cd2d1cc2a31
comparison
equal deleted inserted replaced
36264:18e29c65bc5c 36265:b44fac3a49fb
83 # workaround to simulate the Python 2 (i.e. ANSI Win32 API) behavior. 83 # workaround to simulate the Python 2 (i.e. ANSI Win32 API) behavior.
84 if getattr(sys, 'argv', None) is not None: 84 if getattr(sys, 'argv', None) is not None:
85 sysargv = list(map(os.fsencode, sys.argv)) 85 sysargv = list(map(os.fsencode, sys.argv))
86 86
87 bytechr = struct.Struct('>B').pack 87 bytechr = struct.Struct('>B').pack
88 byterepr = b'%r'.__mod__
88 89
89 class bytestr(bytes): 90 class bytestr(bytes):
90 """A bytes which mostly acts as a Python 2 str 91 """A bytes which mostly acts as a Python 2 str
91 92
92 >>> bytestr(), bytestr(bytearray(b'foo')), bytestr(u'ascii'), bytestr(1) 93 >>> bytestr(), bytestr(bytearray(b'foo')), bytestr(u'ascii'), bytestr(1)
275 276
276 else: 277 else:
277 import cStringIO 278 import cStringIO
278 279
279 bytechr = chr 280 bytechr = chr
281 byterepr = repr
280 bytestr = str 282 bytestr = str
281 iterbytestr = iter 283 iterbytestr = iter
282 maybebytestr = identity 284 maybebytestr = identity
283 sysbytes = identity 285 sysbytes = identity
284 sysstr = identity 286 sysstr = identity