Skip to content

Commit

Permalink
Didn't port isbasestring/isunicodestring from kitchen so switch to is…
Browse files Browse the repository at this point in the history
…instance
  • Loading branch information
abadger committed Feb 12, 2015
1 parent 740bd8f commit 9d60517
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions lib/ansible/utils/unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ def to_unicode(obj, encoding='utf-8', errors='replace', nonstring=None):
simple = obj.__str__()
except (UnicodeError, AttributeError):
simple = u''
if isbytestring(simple):
if isinstance(simple, str):
return unicode(simple, encoding, errors)
return simple
elif nonstring in ('repr', 'strict'):
obj_repr = repr(obj)
if isbytestring(obj_repr):
if isinstance(obj_repr, str):
obj_repr = unicode(obj_repr, encoding, errors)
if nonstring == 'repr':
return obj_repr
Expand Down Expand Up @@ -221,15 +221,15 @@ def to_bytes(obj, encoding='utf-8', errors='replace', nonstring=None):
simple = obj.__unicode__()
except (AttributeError, UnicodeError):
simple = ''
if isunicodestring(simple):
if isinstance(simple, unicode):
simple = simple.encode(encoding, 'replace')
return simple
elif nonstring in ('repr', 'strict'):
try:
obj_repr = obj.__repr__()
except (AttributeError, UnicodeError):
obj_repr = ''
if isunicodestring(obj_repr):
if isinstance(obj_repr, unicode):
obj_repr = obj_repr.encode(encoding, errors)
else:
obj_repr = str(obj_repr)
Expand Down
8 changes: 4 additions & 4 deletions v2/ansible/utils/unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ def to_unicode(obj, encoding='utf-8', errors='replace', nonstring=None):
simple = obj.__str__()
except (UnicodeError, AttributeError):
simple = u''
if isbytestring(simple):
if isinstance(simple, str):
return unicode(simple, encoding, errors)
return simple
elif nonstring in ('repr', 'strict'):
obj_repr = repr(obj)
if isbytestring(obj_repr):
if isinstance(obj_repr, str):
obj_repr = unicode(obj_repr, encoding, errors)
if nonstring == 'repr':
return obj_repr
Expand Down Expand Up @@ -221,15 +221,15 @@ def to_bytes(obj, encoding='utf-8', errors='replace', nonstring=None):
simple = obj.__unicode__()
except (AttributeError, UnicodeError):
simple = ''
if isunicodestring(simple):
if isinstance(simple, unicode):
simple = simple.encode(encoding, 'replace')
return simple
elif nonstring in ('repr', 'strict'):
try:
obj_repr = obj.__repr__()
except (AttributeError, UnicodeError):
obj_repr = ''
if isunicodestring(obj_repr):
if isinstance(obj_repr, unicode):
obj_repr = obj_repr.encode(encoding, errors)
else:
obj_repr = str(obj_repr)
Expand Down

0 comments on commit 9d60517

Please sign in to comment.