Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Assume that we will have to close the file after dump or load
close_flag = True
# Were we handed a file object or just a file name string?
if isinstance(f, (file, io.TextIOWrapper)):
filename, mode = f.name, f.mode
f.close()
h5f = h5.File(filename, mode)
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)