3
3
from socket import socket as Socket
4
4
from ssl import SSLContext
5
5
import threading
6
- from typing import Any , Callable , Dict , List , cast
6
+ from typing import Any , Callable , Dict , List , Optional , cast
7
7
8
8
from aiohttp import web
9
9
13
13
class Server :
14
14
"""A handle to a running server."""
15
15
16
- def __init__ (self , handle_event : EventCallback , host : str , port : int , ssl_context : SSLContext = None ):
16
+ def __init__ (
17
+ self ,
18
+ handle_event : EventCallback ,
19
+ host : str ,
20
+ port : int ,
21
+ ssl_context : Optional [SSLContext ] = None ,
22
+ ):
17
23
"""Initialize a Server."""
18
24
self .host = host
19
25
self .port = port
@@ -63,7 +69,9 @@ def _run(self) -> None:
63
69
asyncio .set_event_loop (self ._server_loop )
64
70
self ._server_loop .run_until_complete (self ._runner .setup ())
65
71
66
- site = web .TCPSite (self ._runner , self .host , self .port , ssl_context = self .ssl_context )
72
+ site = web .TCPSite (
73
+ self ._runner , self .host , self .port , ssl_context = self .ssl_context
74
+ )
67
75
self ._server_loop .run_until_complete (site .start ())
68
76
69
77
# If the Server was initialized with port 0, determine what port the
@@ -84,7 +92,10 @@ async def _stop(self) -> None:
84
92
85
93
86
94
def create_server (
87
- handle_event : EventCallback , host : str = "0.0.0.0" , port : int = 0 , ssl_context : SSLContext = None
95
+ handle_event : EventCallback ,
96
+ host : str = "0.0.0.0" ,
97
+ port : int = 0 ,
98
+ ssl_context : Optional [SSLContext ] = None ,
88
99
) -> Server :
89
100
"""Create a new server."""
90
101
return Server (handle_event , host , port , ssl_context )
0 commit comments