Total Complexity | 4 |
Total Lines | 25 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | from typing import Type |
||
12 | class Runner: |
||
13 | def __init__(self, router: AbstractRouter) -> None: |
||
14 | self._router = router |
||
15 | |||
16 | def run(self, settings: Type[AbstractSettings]) -> None: |
||
17 | run_simple( |
||
18 | hostname=settings.hostname, |
||
19 | port=settings.port, |
||
20 | application=self._get_wsgi_app(), |
||
21 | use_reloader=True, |
||
22 | use_debugger=settings.debug, |
||
23 | ) |
||
24 | |||
25 | def _get_wsgi_app(self): |
||
26 | @WSGIRequest.application |
||
27 | def application(wsgi_request: WSGIRequest) -> WSGIResponse: |
||
28 | request_data = RequestData(wsgi_request) |
||
29 | request_func = self._router.dispatch( |
||
30 | request_data.path, request_data.method |
||
31 | ) |
||
32 | request = Request(request_data, request_func) |
||
33 | response = Response(request) |
||
34 | return response.wsgi() |
||
35 | |||
36 | return application |
||
37 |