Skip to content
Snippets Groups Projects
Commit c5739011 authored by Gregory Ashton's avatar Gregory Ashton
Browse files

Merge branch 'data-reading-convert-byte-arrays' into 'master'

Adds decoding for single strings and list of strings

See merge request Monash/tupak!50
parents 194d88a9 b15a91ca
No related branches found
No related tags found
1 merge request!50Adds decoding for single strings and list of strings
Pipeline #
......@@ -39,7 +39,7 @@ class Result(dict):
def __init__(self, dictionary=None):
if type(dictionary) is dict:
for key in dictionary:
setattr(self, key, dictionary[key])
setattr(self, key, self._decode_object(dictionary[key]))
def __getattr__(self, name):
try:
......@@ -62,6 +62,22 @@ class Result(dict):
else:
return ''
def _decode_object(self, item):
""" When reading in data, ensure all bytes are decoded to strings """
try:
return item.decode()
except AttributeError:
pass
try:
return [i.decode() for i in item]
except (AttributeError, TypeError):
pass
logging.debug("Unable to decode item")
return item
def get_result_dictionary(self):
return dict(self)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment