From 77c107fd5a01f03fbc51b86f05249100c757f6de Mon Sep 17 00:00:00 2001
From: Amir Mohammadi <amir.mohammadi@idiap.ch>
Date: Wed, 31 Aug 2016 19:43:02 +0200
Subject: [PATCH] Add with statement support to File and HDF5File

---
 bob/io/base/__init__.py | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/bob/io/base/__init__.py b/bob/io/base/__init__.py
index 48ee091..4423e68 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
 
-- 
GitLab