Replace .config rather than reconstructing plugins, drivers, and UIs.
[hooke.git] / hooke / util / util.py
1 # Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
2 #
3 # This file is part of Hooke.
4 #
5 # Hooke is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU Lesser General Public License as
7 # published by the Free Software Foundation, either version 3 of the
8 # License, or (at your option) any later version.
9 #
10 # Hooke is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
13 # Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with Hooke.  If not, see
17 # <http://www.gnu.org/licenses/>.
18
19
20 class Closing (object):
21     """Add .__enter__() .__exit__() for `with` statements.
22
23     See :pep:`343`.
24     """
25     def __init__(self, obj):
26         self.obj = obj
27
28     def __enter__(self):
29         return self.obj
30
31     def __exit__(self, *exc_info):
32         try:
33             close_it = self.obj.close
34         except AttributeError:
35             pass
36         else:
37             close_it()