Mercurial > public > mercurial-scm > hg-stable
diff mercurial/utils/stringutil.py @ 37322:a67fd1fe5109
stringutil: drop escapedata() in favor of escapestr()
They are quite similar. Let's choose one that uses standard Python escape.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Wed, 04 Apr 2018 23:26:49 +0900 |
parents | 2f859ad7ed8c |
children | e9dea82ea1f3 |
line wrap: on
line diff
--- a/mercurial/utils/stringutil.py Fri Mar 30 18:57:13 2018 -0700 +++ b/mercurial/utils/stringutil.py Wed Apr 04 23:26:49 2018 +0900 @@ -23,24 +23,10 @@ pycompat, ) -_DATA_ESCAPE_MAP = {pycompat.bytechr(i): br'\x%02x' % i for i in range(256)} -_DATA_ESCAPE_MAP.update({ - b'\\': b'\\\\', - b'\r': br'\r', - b'\n': br'\n', -}) -_DATA_ESCAPE_RE = remod.compile(br'[\x00-\x08\x0a-\x1f\\\x7f-\xff]') - -def escapedata(s): - if isinstance(s, bytearray): - s = bytes(s) - - return _DATA_ESCAPE_RE.sub(lambda m: _DATA_ESCAPE_MAP[m.group(0)], s) - def pprint(o): """Pretty print an object.""" if isinstance(o, (bytes, bytearray)): - return "b'%s'" % escapedata(o) + return "b'%s'" % escapestr(o) elif isinstance(o, list): return '[%s]' % (b', '.join(pprint(a) for a in o)) elif isinstance(o, dict):