changeset 31453:3b7a6941a6ef

py3: call codecs.escape_encode() directly string_escape doesn't exist on Python 3, but fortunately the undocumented codecs.escape_encode() function exists on CPython 2.6, 2.7, 3.5 and PyPy 5.6. So let's use it for now. http://stackoverflow.com/a/23151714
author Yuya Nishihara <yuya@tcha.org>
date Wed, 15 Mar 2017 23:28:39 +0900
parents 52dabcc49968
children a5bad127128d
files mercurial/util.py
diffstat 1 files changed, 4 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/util.py	Wed Mar 15 23:21:30 2017 +0900
+++ b/mercurial/util.py	Wed Mar 15 23:28:39 2017 +0900
@@ -17,6 +17,7 @@
 
 import bz2
 import calendar
+import codecs
 import collections
 import datetime
 import errno
@@ -2131,7 +2132,9 @@
     )
 
 def escapestr(s):
-    return s.encode('string_escape')
+    # call underlying function of s.encode('string_escape') directly for
+    # Python 3 compatibility
+    return codecs.escape_encode(s)[0]
 
 def uirepr(s):
     # Avoid double backslash in Windows path repr()