[PATCH 1 of 4] util: wrap s.decode('string_escape') calls for future py3 compatibility
Yuya Nishihara
yuya at tcha.org
Fri Mar 17 15:25:47 UTC 2017
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1489761766 -32400
# Fri Mar 17 23:42:46 2017 +0900
# Node ID fa032607ed52a0ba605bb4c496426ffb01b09c54
# Parent 96929bd6e58d29bc3d44e1db7c1283f224bd1dc1
util: wrap s.decode('string_escape') calls for future py3 compatibility
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('\\\\', '\\')
More information about the Mercurial-devel
mailing list