Total Complexity | 4 |
Total Lines | 15 |
Duplicated Lines | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 0 |
1 | import abc |
||
21 | class Router(AbstractRouter): |
||
22 | def __init__(self, schema: AbstractSchema) -> None: |
||
23 | self._schema = schema |
||
24 | |||
25 | def dispatch(self, path: str, method: str) -> Callable: |
||
26 | match_result = self._schema.match(path) |
||
27 | endpoint_kwargs = match_result['kwargs'] |
||
28 | endpoint_obj = match_result['endpoint'](**endpoint_kwargs) |
||
29 | if self._is_accepted_method(endpoint_obj, method): |
||
30 | return getattr(endpoint_obj, method.lower()) |
||
31 | else: |
||
32 | raise exceptions.MethodNotAllowed() |
||
33 | |||
34 | def _is_accepted_method(self, endpoint_obj: AbstractEndpoint, method: str): |
||
35 | return method in endpoint_obj.allowed_methods |
||
36 |