simplyfy ascii escaping by using backslashreplace error handling

This commit is contained in:
Ronny Pfannschmidt 2017-08-30 16:39:44 +02:00
parent 488bbd2aeb
commit 78a027e128
2 changed files with 2 additions and 8 deletions

View File

@ -121,7 +121,6 @@ if sys.version_info[:2] == (2, 6):
if _PY3:
import codecs
imap = map
izip = zip
STRING_TYPES = bytes, str
@ -146,13 +145,7 @@ if _PY3:
"""
if isinstance(val, bytes):
if val:
# source: http://goo.gl/bGsnwC
encoded_bytes, _ = codecs.escape_encode(val)
return encoded_bytes.decode('ascii')
else:
# empty bytes crashes codecs.escape_encode (#1087)
return ''
return val.decode('ascii', 'backslashreplace')
else:
return val.encode('unicode_escape').decode('ascii')
else:

1
changelog/2734.trivial Normal file
View File

@ -0,0 +1 @@
- simplify ascii string escaping by using the backslashreplace error handler