Python3: fix strformat ascii_safe() and unicode_safe()

This commit is contained in:
Petr Dlouhý 2019-04-25 19:55:05 +01:00 committed by anarcat
parent ecba4e7ac8
commit a1c6c4935e

View file

@ -56,10 +56,10 @@ def unicode_safe (s, encoding=i18n.default_encoding, errors='replace'):
@rtype: unicode
"""
assert s is not None, "argument to unicode_safe was None"
if isinstance(s, unicode):
if isinstance(s, str_text):
# s is already unicode, nothing to do
return s
return unicode(str(s), encoding, errors)
return str_text(bytes(s), encoding, errors)
def ascii_safe (s):
@ -71,7 +71,7 @@ def ascii_safe (s):
@return: encoded ASCII version of s, or None if s was None
@rtype: string
"""
if isinstance(s, unicode):
if isinstance(s, str_text):
s = s.encode('ascii', 'ignore')
return s