diff --git a/bob/io/base/__init__.py b/bob/io/base/__init__.py index 48ee091f5ebaa07ea5f8ecaa2286017dfda581ad..4423e68f9f86b2d0792a871f3612d5a7219859aa 100644 --- a/bob/io/base/__init__.py +++ b/bob/io/base/__init__.py @@ -5,13 +5,34 @@ import bob.core import bob.extension bob.extension.load_bob_library('bob.io.base', __file__) -from ._library import File, HDF5File, extensions +from ._library import File as File_C, HDF5File as HDF5File_C, extensions from . import version from .version import module as __version__ from .version import api as __api_version__ import os + +class File(File_C): + __doc__ = File_C.__doc__ + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + self.close() + + +class HDF5File(HDF5File_C): + __doc__ = HDF5File_C.__doc__ + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + self.close() + + def _is_string(s): """Returns ``True`` if the given object is a string