Предизвикателства > Безгрешен блок > Решения > Решението на Георги Балтиев

Резултати
1 точки от тестове
0 точки от учител

1 точки общо

2 успешни теста
0 неуспешни теста
Код

 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

Дискусия
История

n1 n
2class ProtectedSection:1class ProtectedSection:
32
t4    def __init__(self, **logs_and_supress):t3    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 = None6        self.exception = None
87
9    def __enter__(self):8    def __enter__(self):
10        return self9        return self
1110
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 = None13            self.exception = None
15            return True14            return True
1615
17        if self.logs and exc_type in self.logs:16        if self.logs and exc_type in self.logs:
18            self.exception = exc_value17            self.exception = exc_value
19            return True18            return True
2019
21        if self.suppress and exc_type in self.suppress:20        if self.suppress and exc_type in self.suppress:
22            self.exception = None21            self.exception = None
23            return True22            return True
2423
25        return False24        return False
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1f1
2class ProtectedSection:2class ProtectedSection:
33
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 = None7        self.exception = None
88
9    def __enter__(self):9    def __enter__(self):
10        return self10        return self
1111
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:
nn14            self.exception = None
14            return True15            return True
1516
16        if self.logs and exc_type in self.logs:17        if self.logs and exc_type in self.logs:
17            self.exception = exc_value18            self.exception = exc_value
18            return True19            return True
1920
t20        return self.suppress and exc_type in self.suppresst21        if self.suppress and exc_type in self.suppress:
22            self.exception = None
23            return True
24 
25        return False
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1f1
2class ProtectedSection:2class ProtectedSection:
33
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 = None7        self.exception = None
88
9    def __enter__(self):9    def __enter__(self):
10        return self10        return self
1111
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 True14            return True
1515
16        if self.logs and exc_type in self.logs:16        if self.logs and exc_type in self.logs:
17            self.exception = exc_value17            self.exception = exc_value
18            return True18            return True
1919
t20        if self.suppress and exc_type in self.suppress:t20        return self.suppress and exc_type in self.suppress
21            return True
22 
23        return False
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1f1
2class ProtectedSection:2class ProtectedSection:
33
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 = None7        self.exception = None
88
9    def __enter__(self):9    def __enter__(self):
10        return self10        return self
1111
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:
n14            self.exception = Nonen
15            return True14            return True
1615
17        if self.logs and exc_type in self.logs:16        if self.logs and exc_type in self.logs:
18            self.exception = exc_value17            self.exception = exc_value
19            return True18            return True
2019
21        if self.suppress and exc_type in self.suppress:20        if self.suppress and exc_type in self.suppress:
t22            self.exception = Nonet
23            return True21            return True
2422
25        return False23        return False
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op