Moved Closing from hooke.driver.jpk to hooke.util.util
[hooke.git] / hooke / util / util.py
1 # Copyright
2
3
4 class Closing (object):
5     """Add .__enter__() .__exit__() for `with` statements.
6
7     See :pep:`343`.
8     """
9     def __init__(self, obj):
10         self.obj = obj
11
12     def __enter__(self):
13         return self.obj
14
15     def __exit__(self, *exc_info):
16         try:
17             close_it = self.obj.close
18         except AttributeError:
19             pass
20         else:
21             close_it()