Merge branch 'release_19.05' into release_19.09

This commit is contained in:
Nicola Soranzo
2019-10-28 14:39:29 +00:00
+5 -1
View File
@@ -1023,6 +1023,7 @@ def unicodify(value, encoding=DEFAULT_ENCODING, error='replace', strip_null=Fals
>>> s = u'lâtín strìñg'; assert unicodify(s.encode('latin-1'), 'latin-1') == s
>>> s = u'lâtín strìñg'; assert unicodify(s.encode('latin-1')) == u'l\ufffdt\ufffdn str\ufffd\ufffdg'
>>> s = u'lâtín strìñg'; assert unicodify(s.encode('latin-1'), error='ignore') == u'ltn strg'
>>> if PY2: assert unicodify(Exception(u'¼ cup of flour'.encode('latin-1')), error='ignore') == ' cup of flour'
"""
if value is None:
return value
@@ -1032,7 +1033,10 @@ def unicodify(value, encoding=DEFAULT_ENCODING, error='replace', strip_null=Fals
elif not isinstance(value, string_types) and not isinstance(value, binary_type):
# In Python 2, value is not an instance of basestring (i.e. str or unicode)
# In Python 3, value is not an instance of bytes or str
value = text_type(value)
try:
value = text_type(value)
except Exception:
value = str(value)
# Now in Python 2, value is an instance of basestring, but may be not unicode
# Now in Python 3, value is an instance of bytes or str
if not isinstance(value, text_type):