Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 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 | 53865692a354 |
children | da83f12d7a88 |
comparison
equal
deleted
inserted
replaced
31452:52dabcc49968 | 31453:3b7a6941a6ef |
---|---|
15 | 15 |
16 from __future__ import absolute_import | 16 from __future__ import absolute_import |
17 | 17 |
18 import bz2 | 18 import bz2 |
19 import calendar | 19 import calendar |
20 import codecs | |
20 import collections | 21 import collections |
21 import datetime | 22 import datetime |
22 import errno | 23 import errno |
23 import gc | 24 import gc |
24 import hashlib | 25 import hashlib |
2129 (1, 1 << 10, _('%.2f KB')), | 2130 (1, 1 << 10, _('%.2f KB')), |
2130 (1, 1, _('%.0f bytes')), | 2131 (1, 1, _('%.0f bytes')), |
2131 ) | 2132 ) |
2132 | 2133 |
2133 def escapestr(s): | 2134 def escapestr(s): |
2134 return s.encode('string_escape') | 2135 # call underlying function of s.encode('string_escape') directly for |
2136 # Python 3 compatibility | |
2137 return codecs.escape_encode(s)[0] | |
2135 | 2138 |
2136 def uirepr(s): | 2139 def uirepr(s): |
2137 # Avoid double backslash in Windows path repr() | 2140 # Avoid double backslash in Windows path repr() |
2138 return repr(s).replace('\\\\', '\\') | 2141 return repr(s).replace('\\\\', '\\') |
2139 | 2142 |