Mercurial > hg
changeset 31484:afb335353d28
util: wrap s.decode('string_escape') calls for future py3 compatibility
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Fri, 17 Mar 2017 23:42:46 +0900 |
parents | 291951ad070b |
children | cad95575dc46 |
files | mercurial/changelog.py mercurial/parser.py mercurial/util.py |
diffstat | 3 files changed, 10 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/changelog.py Sat Mar 18 12:27:52 2017 -0400 +++ b/mercurial/changelog.py Fri Mar 17 23:42:46 2017 +0900 @@ -32,7 +32,7 @@ >>> s 'ab\\ncd\\\\\\\\n\\x00ab\\rcd\\\\\\n' >>> res = _string_escape(s) - >>> s == res.decode('string_escape') + >>> s == util.unescapestr(res) True """ # subset of the string_escape codec @@ -57,7 +57,7 @@ l = l.replace('\\\\', '\\\\\n') l = l.replace('\\0', '\0') l = l.replace('\n', '') - k, v = l.decode('string_escape').split(':', 1) + k, v = util.unescapestr(l).split(':', 1) extra[k] = v return extra
--- a/mercurial/parser.py Sat Mar 18 12:27:52 2017 -0400 +++ b/mercurial/parser.py Fri Mar 17 23:42:46 2017 +0900 @@ -19,7 +19,10 @@ from __future__ import absolute_import from .i18n import _ -from . import error +from . import ( + error, + util, +) class parser(object): def __init__(self, elements, methods=None): @@ -164,7 +167,7 @@ def unescapestr(s): try: - return s.decode("string_escape") + return util.unescapestr(s) except ValueError as e: # mangle Python's exception into our format raise error.ParseError(str(e).lower())
--- a/mercurial/util.py Sat Mar 18 12:27:52 2017 -0400 +++ b/mercurial/util.py Fri Mar 17 23:42:46 2017 +0900 @@ -2137,6 +2137,9 @@ # Python 3 compatibility return codecs.escape_encode(s)[0] +def unescapestr(s): + return s.decode('string_escape') + def uirepr(s): # Avoid double backslash in Windows path repr() return repr(s).replace('\\\\', '\\')