diff --git a/mercurial/changelog.py b/mercurial/changelog.py --- a/mercurial/changelog.py +++ b/mercurial/changelog.py @@ -32,7 +32,7 @@ def _string_escape(text): >>> 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 @@ def decodeextra(text): 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 diff --git a/mercurial/parser.py b/mercurial/parser.py --- a/mercurial/parser.py +++ b/mercurial/parser.py @@ -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 buildargsdict(trees, funcname, argsp 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()) diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -2137,6 +2137,9 @@ def escapestr(s): # 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('\\\\', '\\')