py3: call codecs.escape_encode() directly
authorYuya Nishihara <yuya@tcha.org>
Wed, 15 Mar 2017 23:28:39 +0900
changeset 31462 3b7a6941a6ef
parent 31461 52dabcc49968
child 31463 a5bad127128d
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
mercurial/util.py
--- 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()