def with_write_hdf5(func):
@wraps(func)<EOL>def decorated_func(obj, fobj, *args, **kwargs):<EOL><INDENT>if not isinstance(fobj, h5py.HLObject):<EOL><INDENT>append = kwargs.get('<STR_LIT>', False)<EOL>overwrite = kwargs.get('<STR_LIT>', False)<EOL>if os.path.exists(fobj) and not (overwrite or append):<EOL><INDENT>raise IOError("<STR_LIT>" % fobj)<EOL><DEDENT>with h5py.File(fobj, '<STR_LIT:a>' if append else '<STR_LIT:w>') as h5f:<EOL><INDENT>return func(obj, h5f, *args, **kwargs)<EOL><DEDENT><DEDENT>return func(obj, fobj, *args, **kwargs)<EOL><DEDENT>return decorated_func<EOL>
Decorate an HDF5-writing function to open a filepath if needed

    ``func`` should be written to take the object to be written as the
    first argument, and then presume an `h5py.Group` as the second.

    This method uses keywords ``append`` and ``overwrite`` as follows if
    the output file already exists:

    - ``append=False, overwrite=False``: raise `~exceptions.IOError`
    - ``append=True``: open in mode ``a``
    - ``append=False, overwrite=True``: open in mode ``w``