1class ProtectedSection:
2 def __init__(self, log=(), suppress=()):
3 self.log = log
4 self.suppress = suppress
5 self.exception = None
6
7 def __enter__(self):
8 self.exception = None
9 return self
10
11 def __exit__(self, exc_type, exc_val, exc_tb):
12 if exc_type is None:
13 return True
14 elif exc_type in self.log:
15 self.exception = exc_val
16 return True
17 elif exc_type in self.suppress:
18 return True
19 else:
20 return False
..
----------------------------------------------------------------------
Ran 2 tests in 0.000s
OK