# HG changeset patch # User Yuya Nishihara # Date 1489586810 -32400 # Node ID 53865692a354c9a0d20dbebed48a36b8a5d539d5 # Parent b3b4c487707c152dbf8eb6c9c5f9e1c9ff2f4e69 util: wrap s.encode('string_escape') call for future py3 compatibility diff -r b3b4c487707c -r 53865692a354 hgext/extdiff.py --- a/hgext/extdiff.py Mon Mar 13 09:24:53 2017 -0700 +++ b/hgext/extdiff.py Wed Mar 15 23:06:50 2017 +0900 @@ -342,7 +342,7 @@ def __init__(self, path, cmdline): # We can't pass non-ASCII through docstrings (and path is # in an unknown encoding anyway) - docpath = path.encode("string-escape") + docpath = util.escapestr(path) self.__doc__ = self.__doc__ % {'path': util.uirepr(docpath)} self._cmdline = cmdline diff -r b3b4c487707c -r 53865692a354 mercurial/cmdutil.py --- a/mercurial/cmdutil.py Mon Mar 13 09:24:53 2017 -0700 +++ b/mercurial/cmdutil.py Wed Mar 15 23:06:50 2017 +0900 @@ -1300,7 +1300,7 @@ for key, value in sorted(extra.items()): # i18n: column positioning for "hg log" self.ui.write(_("extra: %s=%s\n") - % (key, value.encode('string_escape')), + % (key, util.escapestr(value)), label='ui.debug log.extra') description = ctx.description().strip() diff -r b3b4c487707c -r 53865692a354 mercurial/debugcommands.py --- a/mercurial/debugcommands.py Mon Mar 13 09:24:53 2017 -0700 +++ b/mercurial/debugcommands.py Wed Mar 15 23:06:50 2017 +0900 @@ -1514,8 +1514,8 @@ return not r else: for k, v in sorted(target.listkeys(namespace).iteritems()): - ui.write("%s\t%s\n" % (k.encode('string-escape'), - v.encode('string-escape'))) + ui.write("%s\t%s\n" % (util.escapestr(k), + util.escapestr(v))) @command('debugpvec', [], _('A B')) def debugpvec(ui, repo, a, b=None): diff -r b3b4c487707c -r 53865692a354 mercurial/subrepo.py --- a/mercurial/subrepo.py Mon Mar 13 09:24:53 2017 -0700 +++ b/mercurial/subrepo.py Wed Mar 15 23:06:50 2017 +0900 @@ -130,7 +130,7 @@ for pattern, repl in p.items('subpaths'): # Turn r'C:\foo\bar' into r'C:\\foo\\bar' since re.sub # does a string decode. - repl = repl.encode('string-escape') + repl = util.escapestr(repl) # However, we still want to allow back references to go # through unharmed, so we turn r'\\1' into r'\1'. Again, # extra escapes are needed because re.sub string decodes. diff -r b3b4c487707c -r 53865692a354 mercurial/templatefilters.py --- a/mercurial/templatefilters.py Mon Mar 13 09:24:53 2017 -0700 +++ b/mercurial/templatefilters.py Wed Mar 15 23:06:50 2017 +0900 @@ -345,7 +345,7 @@ @templatefilter('stringescape') def stringescape(text): - return text.encode('string_escape') + return util.escapestr(text) @templatefilter('stringify') def stringify(thing): diff -r b3b4c487707c -r 53865692a354 mercurial/util.py --- a/mercurial/util.py Mon Mar 13 09:24:53 2017 -0700 +++ b/mercurial/util.py Wed Mar 15 23:06:50 2017 +0900 @@ -2130,6 +2130,9 @@ (1, 1, _('%.0f bytes')), ) +def escapestr(s): + return s.encode('string_escape') + def uirepr(s): # Avoid double backslash in Windows path repr() return repr(s).replace('\\\\', '\\') diff -r b3b4c487707c -r 53865692a354 mercurial/wireproto.py --- a/mercurial/wireproto.py Mon Mar 13 09:24:53 2017 -0700 +++ b/mercurial/wireproto.py Wed Mar 15 23:06:50 2017 +0900 @@ -900,7 +900,7 @@ def pushkey(repo, proto, namespace, key, old, new): # compatibility with pre-1.8 clients which were accidentally # sending raw binary nodes rather than utf-8-encoded hex - if len(new) == 20 and new.encode('string-escape') != new: + if len(new) == 20 and util.escapestr(new) != new: # looks like it could be a binary node try: new.decode('utf-8')