Skip to content

Commit

Permalink
Unicodify bytearrays
Browse files Browse the repository at this point in the history
  • Loading branch information
nsoranzo committed May 30, 2018
1 parent 7b5e190 commit 2ebe887
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/galaxy/util/__init__.py
Expand Up @@ -938,6 +938,8 @@ def unicodify(value, encoding=DEFAULT_ENCODING, error='replace', default=None):
True
>>> unicodify(3) == u'3'
True
>>> unicodify(bytearray([115, 116, 114, 196, 169, 195, 177, 103])) == u'strĩñg'
True
>>> unicodify(Exception('message')) == u'message'
True
>>> unicodify('cómplǐcḁtëd strĩñg') == u'cómplǐcḁtëd strĩñg'
Expand All @@ -952,7 +954,9 @@ def unicodify(value, encoding=DEFAULT_ENCODING, error='replace', default=None):
if value is None:
return None
try:
if not isinstance(value, string_types) and not isinstance(value, binary_type):
if isinstance(value, bytearray):
value = bytes(value)
elif not isinstance(value, string_types) and not isinstance(value, binary_type):
# In Python 2, value is not an instance of basestring
# In Python 3, value is not an instance of bytes or str
value = str(value)
Expand Down

0 comments on commit 2ebe887

Please sign in to comment.