Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _load(py_container, h_group):
""" Load a hickle file
Recursive funnction to load hdf5 data into a PyContainer()
Args:
py_container (PyContainer): Python container to load data into
h_group (h5 group or dataset): h5py object, group or dataset, to spider
and load all datasets.
"""
group_dtype = h5._hl.group.Group
dataset_dtype = h5._hl.dataset.Dataset
#either a file, group, or dataset
if isinstance(h_group, (H5FileWrapper, group_dtype)):
py_subcontainer = PyContainer()
try:
py_subcontainer.container_type = bytes(h_group.attrs['type'][0])
except KeyError:
raise
#py_subcontainer.container_type = ''
py_subcontainer.name = h_group.name
if py_subcontainer.container_type == b'dict_item':
py_subcontainer.key_type = h_group.attrs['key_type']
if py_subcontainer.container_type not in types_not_to_sort:
h_keys = sort_keys(h_group.keys())
else:
h_keys = h_group.keys()
elif isinstance(f, string_types):
filename = f
h5f = h5.File(filename, mode)
elif isinstance(f, (H5FileWrapper, h5._hl.files.File)):
try:
filename = f.filename
except ValueError:
raise ClosedFileError
h5f = f
# Since this file was already open, do not close the file afterward
close_flag = False
else:
print(f.__class__)
raise FileError
h5f.__class__ = H5FileWrapper
h5f.track_times = track_times
return(h5f, close_flag)
def create_dataset(self, *args, **kwargs):
kwargs['track_times'] = getattr(self, 'track_times', True)
return super(H5FileWrapper, self).create_dataset(*args, **kwargs)