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 # reset state
9 return self
10
11 def __exit__(self, exc_type, exc_value, traceback):
12 if exc_type is None:
13 return False
14
15 if exc_type in self.log:
16 self.exception = exc_value
17 return True
18 if exc_type in self.suppress:
19 return True
20 return False
..
----------------------------------------------------------------------
Ran 2 tests in 0.000s
OK
f | 1 | class ProtectedSection: | f | 1 | class ProtectedSection: |
2 | def __init__(self, log=(), suppress=()): | 2 | def __init__(self, log=(), suppress=()): | ||
3 | self.log = log | 3 | self.log = log | ||
4 | self.suppress = suppress | 4 | self.suppress = suppress | ||
5 | self.exception = None | 5 | self.exception = None | ||
6 | 6 | ||||
7 | def __enter__(self): | 7 | def __enter__(self): | ||
n | n | 8 | self.exception = None # reset state | ||
8 | return self | 9 | return self | ||
9 | 10 | ||||
10 | def __exit__(self, exc_type, exc_value, traceback): | 11 | def __exit__(self, exc_type, exc_value, traceback): | ||
11 | if exc_type is None: | 12 | if exc_type is None: | ||
12 | return False | 13 | return False | ||
13 | 14 | ||||
14 | if exc_type in self.log: | 15 | if exc_type in self.log: | ||
15 | self.exception = exc_value | 16 | self.exception = exc_value | ||
16 | return True | 17 | return True | ||
17 | if exc_type in self.suppress: | 18 | if exc_type in self.suppress: | ||
t | 18 | self.exception = None | t | ||
19 | return True | 19 | return True | ||
20 | return False | 20 | return False |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|