Commit 7eb6822c authored by Thomas Vincent's avatar Thomas Vincent

check if decode is available before calling it

parent e624fd83
......@@ -59,7 +59,9 @@ def getNodeClass(nodeType, attrs=None):
for key, value in attrs.items():
info = _registeredAttributes.get(key)
if info:
klass = info.get(value.decode())
if hasattr(value, 'decode'):
value = value.decode()
klass = info.get(value)
if klass:
break
if not klass:
......@@ -291,7 +293,7 @@ class H5DatasetNode(H5Base):
ndims = len(item.shape)
if ndims == 0:
data = item[()]
if isinstance(data, (np.string_, bytes_type)):
if hasattr(data, 'decode'):
text = data.decode().replace('\n', ' ')
else:
text = str(data)
......
......@@ -59,10 +59,10 @@ def projectItemFactory(h5File, h5Path, mode=None):
klass = None
with h5py.File(h5File, mode='r') as h5f:
attrs = h5f[h5Path].attrs
# For some reason attrs.get sometimes fails,
# using "in" seems a bit more robust.
if 'XsocsClass' in attrs:
xsocsClass = attrs['XsocsClass'].decode()
xsocsClass = attrs['XsocsClass']
if hasattr(xsocsClass, 'decode'):
xsocsClass = xsocsClass.decode()
klass = getItemClass(xsocsClass)
del attrs
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment