66import asyncio
77from asyncio import AbstractEventLoop
88from logging import getLogger
9- from os . path import abspath , dirname , join
9+ from pathlib import Path
1010from platform import system
1111from threading import Thread
12- from typing import TYPE_CHECKING
1312
1413from aioquic .asyncio import serve # type: ignore[attr-defined]
1514from aioquic .h3 .connection import H3_ALPN
2322 _connect_to_server ,
2423)
2524
26- if TYPE_CHECKING :
27- from pathlib import Path
28-
2925# Override global _doc_root
30- webtransport_h3_server ._doc_root = join ( # pylint: disable=protected-access
31- dirname (abspath (__file__ )),
32- "wpt_h3_server" ,
33- "handlers" ,
26+ webtransport_h3_server ._doc_root = str ( # pylint: disable=protected-access
27+ (Path (__file__ ).parent / "wpt_h3_server" / "handlers" ).resolve ()
3428)
3529
30+
3631LOG = getLogger (__name__ )
3732
3833
@@ -42,16 +37,16 @@ def __init__(self, port: int, cert: Path, key: Path) -> None:
4237
4338 Args:
4439 port: The port on which to listen on.
45- cert: The path to the certificate file.
46- key: The path to the certificate 's private key.
40+ cert: Certificate file.
41+ key: Certificate 's private key.
4742 """
4843 self ._port = port
4944 self ._cert = cert
5045 self ._key = key
5146
5247 self ._loop : AbstractEventLoop | None = None
5348 self ._server_thread : Thread | None = None
54- self ._started : bool = False
49+ self ._started = False
5550
5651 @property
5752 def location (self ) -> str :
@@ -84,7 +79,7 @@ def _start_service() -> None:
8479 max_datagram_frame_size = 65536 ,
8580 )
8681
87- LOG .debug ("Starting WebTransport service on port %s " , self .port )
82+ LOG .debug ("Starting WebTransport service on port %d " , self .port )
8883 configuration .load_cert_chain (self ._cert , self ._key )
8984 ticket_store = SessionTicketStore ()
9085
@@ -117,14 +112,15 @@ def _start_service() -> None:
117112 def cleanup (self ) -> None :
118113 """Stop the server."""
119114
120- async def _stop_loop () -> None :
121- if self ._loop is not None :
122- self ._loop .stop ()
123-
124115 if self ._started :
116+
117+ async def _stop_loop () -> None :
118+ if self ._loop is not None :
119+ self ._loop .stop ()
120+
125121 if self ._loop is not None :
126122 asyncio .run_coroutine_threadsafe (_stop_loop (), self ._loop )
127123 if self ._server_thread is not None :
128124 self ._server_thread .join ()
129- LOG .debug ("Stopped WebTransport service on port %s " , self ._port )
130- self ._started = False
125+ LOG .debug ("Stopped WebTransport service on port %d " , self ._port )
126+ self ._started = False
0 commit comments