1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Didn't port isbasestring/isunicodestring from kitchen so switch to isinstance

This commit is contained in:
Toshio Kuratomi 2015-02-12 13:55:27 -08:00
parent 740bd8fbde
commit 9d605171a7
2 changed files with 8 additions and 8 deletions

View file

@ -116,12 +116,12 @@ def to_unicode(obj, encoding='utf-8', errors='replace', nonstring=None):
simple = obj.__str__() simple = obj.__str__()
except (UnicodeError, AttributeError): except (UnicodeError, AttributeError):
simple = u'' simple = u''
if isbytestring(simple): if isinstance(simple, str):
return unicode(simple, encoding, errors) return unicode(simple, encoding, errors)
return simple return simple
elif nonstring in ('repr', 'strict'): elif nonstring in ('repr', 'strict'):
obj_repr = repr(obj) obj_repr = repr(obj)
if isbytestring(obj_repr): if isinstance(obj_repr, str):
obj_repr = unicode(obj_repr, encoding, errors) obj_repr = unicode(obj_repr, encoding, errors)
if nonstring == 'repr': if nonstring == 'repr':
return obj_repr return obj_repr
@ -221,7 +221,7 @@ def to_bytes(obj, encoding='utf-8', errors='replace', nonstring=None):
simple = obj.__unicode__() simple = obj.__unicode__()
except (AttributeError, UnicodeError): except (AttributeError, UnicodeError):
simple = '' simple = ''
if isunicodestring(simple): if isinstance(simple, unicode):
simple = simple.encode(encoding, 'replace') simple = simple.encode(encoding, 'replace')
return simple return simple
elif nonstring in ('repr', 'strict'): elif nonstring in ('repr', 'strict'):
@ -229,7 +229,7 @@ def to_bytes(obj, encoding='utf-8', errors='replace', nonstring=None):
obj_repr = obj.__repr__() obj_repr = obj.__repr__()
except (AttributeError, UnicodeError): except (AttributeError, UnicodeError):
obj_repr = '' obj_repr = ''
if isunicodestring(obj_repr): if isinstance(obj_repr, unicode):
obj_repr = obj_repr.encode(encoding, errors) obj_repr = obj_repr.encode(encoding, errors)
else: else:
obj_repr = str(obj_repr) obj_repr = str(obj_repr)

View file

@ -116,12 +116,12 @@ def to_unicode(obj, encoding='utf-8', errors='replace', nonstring=None):
simple = obj.__str__() simple = obj.__str__()
except (UnicodeError, AttributeError): except (UnicodeError, AttributeError):
simple = u'' simple = u''
if isbytestring(simple): if isinstance(simple, str):
return unicode(simple, encoding, errors) return unicode(simple, encoding, errors)
return simple return simple
elif nonstring in ('repr', 'strict'): elif nonstring in ('repr', 'strict'):
obj_repr = repr(obj) obj_repr = repr(obj)
if isbytestring(obj_repr): if isinstance(obj_repr, str):
obj_repr = unicode(obj_repr, encoding, errors) obj_repr = unicode(obj_repr, encoding, errors)
if nonstring == 'repr': if nonstring == 'repr':
return obj_repr return obj_repr
@ -221,7 +221,7 @@ def to_bytes(obj, encoding='utf-8', errors='replace', nonstring=None):
simple = obj.__unicode__() simple = obj.__unicode__()
except (AttributeError, UnicodeError): except (AttributeError, UnicodeError):
simple = '' simple = ''
if isunicodestring(simple): if isinstance(simple, unicode):
simple = simple.encode(encoding, 'replace') simple = simple.encode(encoding, 'replace')
return simple return simple
elif nonstring in ('repr', 'strict'): elif nonstring in ('repr', 'strict'):
@ -229,7 +229,7 @@ def to_bytes(obj, encoding='utf-8', errors='replace', nonstring=None):
obj_repr = obj.__repr__() obj_repr = obj.__repr__()
except (AttributeError, UnicodeError): except (AttributeError, UnicodeError):
obj_repr = '' obj_repr = ''
if isunicodestring(obj_repr): if isinstance(obj_repr, unicode):
obj_repr = obj_repr.encode(encoding, errors) obj_repr = obj_repr.encode(encoding, errors)
else: else:
obj_repr = str(obj_repr) obj_repr = str(obj_repr)