1class ProtectedSection:
2
3 def __init__(self, log=(), suppress=()):
4 self.logs = log
5 self.suppress = suppress
6 self.exception = None
7
8 def __enter__(self):
9 return self
10
11 def __exit__(self, exc_type, exc_value, exc_traceback):
12 if exc_type is None:
13 self.exception = None
14 return True
15
16 if self.logs and exc_type in self.logs:
17 self.exception = exc_value
18 return True
19
20 if self.suppress and exc_type in self.suppress:
21 self.exception = None
22 return True
23
24 return False
..
----------------------------------------------------------------------
Ran 2 tests in 0.000s
OK
n | 1 | n | |||
2 | class ProtectedSection: | 1 | class ProtectedSection: | ||
3 | 2 | ||||
t | 4 | def __init__(self, **logs_and_supress): | t | 3 | def __init__(self, log=(), suppress=()): |
5 | self.logs = logs_and_supress.get('log') | 4 | self.logs = log | ||
6 | self.suppress = logs_and_supress.get('suppress') | 5 | self.suppress = suppress | ||
7 | self.exception = None | 6 | self.exception = None | ||
8 | 7 | ||||
9 | def __enter__(self): | 8 | def __enter__(self): | ||
10 | return self | 9 | return self | ||
11 | 10 | ||||
12 | def __exit__(self, exc_type, exc_value, exc_traceback): | 11 | def __exit__(self, exc_type, exc_value, exc_traceback): | ||
13 | if exc_type is None: | 12 | if exc_type is None: | ||
14 | self.exception = None | 13 | self.exception = None | ||
15 | return True | 14 | return True | ||
16 | 15 | ||||
17 | if self.logs and exc_type in self.logs: | 16 | if self.logs and exc_type in self.logs: | ||
18 | self.exception = exc_value | 17 | self.exception = exc_value | ||
19 | return True | 18 | return True | ||
20 | 19 | ||||
21 | if self.suppress and exc_type in self.suppress: | 20 | if self.suppress and exc_type in self.suppress: | ||
22 | self.exception = None | 21 | self.exception = None | ||
23 | return True | 22 | return True | ||
24 | 23 | ||||
25 | return False | 24 | return False |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | f | 1 | ||
2 | class ProtectedSection: | 2 | class ProtectedSection: | ||
3 | 3 | ||||
4 | def __init__(self, **logs_and_supress): | 4 | def __init__(self, **logs_and_supress): | ||
5 | self.logs = logs_and_supress.get('log') | 5 | self.logs = logs_and_supress.get('log') | ||
6 | self.suppress = logs_and_supress.get('suppress') | 6 | self.suppress = logs_and_supress.get('suppress') | ||
7 | self.exception = None | 7 | self.exception = None | ||
8 | 8 | ||||
9 | def __enter__(self): | 9 | def __enter__(self): | ||
10 | return self | 10 | return self | ||
11 | 11 | ||||
12 | def __exit__(self, exc_type, exc_value, exc_traceback): | 12 | def __exit__(self, exc_type, exc_value, exc_traceback): | ||
13 | if exc_type is None: | 13 | if exc_type is None: | ||
n | n | 14 | self.exception = None | ||
14 | return True | 15 | return True | ||
15 | 16 | ||||
16 | if self.logs and exc_type in self.logs: | 17 | if self.logs and exc_type in self.logs: | ||
17 | self.exception = exc_value | 18 | self.exception = exc_value | ||
18 | return True | 19 | return True | ||
19 | 20 | ||||
t | 20 | return self.suppress and exc_type in self.suppress | t | 21 | if self.suppress and exc_type in self.suppress: |
22 | self.exception = None | ||||
23 | return True | ||||
24 | |||||
25 | return False |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | f | 1 | ||
2 | class ProtectedSection: | 2 | class ProtectedSection: | ||
3 | 3 | ||||
4 | def __init__(self, **logs_and_supress): | 4 | def __init__(self, **logs_and_supress): | ||
5 | self.logs = logs_and_supress.get('log') | 5 | self.logs = logs_and_supress.get('log') | ||
6 | self.suppress = logs_and_supress.get('suppress') | 6 | self.suppress = logs_and_supress.get('suppress') | ||
7 | self.exception = None | 7 | self.exception = None | ||
8 | 8 | ||||
9 | def __enter__(self): | 9 | def __enter__(self): | ||
10 | return self | 10 | return self | ||
11 | 11 | ||||
12 | def __exit__(self, exc_type, exc_value, exc_traceback): | 12 | def __exit__(self, exc_type, exc_value, exc_traceback): | ||
13 | if exc_type is None: | 13 | if exc_type is None: | ||
14 | return True | 14 | return True | ||
15 | 15 | ||||
16 | if self.logs and exc_type in self.logs: | 16 | if self.logs and exc_type in self.logs: | ||
17 | self.exception = exc_value | 17 | self.exception = exc_value | ||
18 | return True | 18 | return True | ||
19 | 19 | ||||
t | 20 | if self.suppress and exc_type in self.suppress: | t | 20 | return self.suppress and exc_type in self.suppress |
21 | return True | ||||
22 | |||||
23 | return False |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | f | 1 | ||
2 | class ProtectedSection: | 2 | class ProtectedSection: | ||
3 | 3 | ||||
4 | def __init__(self, **logs_and_supress): | 4 | def __init__(self, **logs_and_supress): | ||
5 | self.logs = logs_and_supress.get('log') | 5 | self.logs = logs_and_supress.get('log') | ||
6 | self.suppress = logs_and_supress.get('suppress') | 6 | self.suppress = logs_and_supress.get('suppress') | ||
7 | self.exception = None | 7 | self.exception = None | ||
8 | 8 | ||||
9 | def __enter__(self): | 9 | def __enter__(self): | ||
10 | return self | 10 | return self | ||
11 | 11 | ||||
12 | def __exit__(self, exc_type, exc_value, exc_traceback): | 12 | def __exit__(self, exc_type, exc_value, exc_traceback): | ||
13 | if exc_type is None: | 13 | if exc_type is None: | ||
n | 14 | self.exception = None | n | ||
15 | return True | 14 | return True | ||
16 | 15 | ||||
17 | if self.logs and exc_type in self.logs: | 16 | if self.logs and exc_type in self.logs: | ||
18 | self.exception = exc_value | 17 | self.exception = exc_value | ||
19 | return True | 18 | return True | ||
20 | 19 | ||||
21 | if self.suppress and exc_type in self.suppress: | 20 | if self.suppress and exc_type in self.suppress: | ||
t | 22 | self.exception = None | t | ||
23 | return True | 21 | return True | ||
24 | 22 | ||||
25 | return False | 23 | return False |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|