Skip to content

Commit 64ff430

Browse files
committed
fix: a few more minor nits
1 parent a8556b1 commit 64ff430

File tree

3 files changed

+32
-31
lines changed

3 files changed

+32
-31
lines changed

src/grizzly/services/core.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
# This Source Code Form is subject to the terms of the Mozilla Public
22
# License, v. 2.0. If a copy of the MPL was not distributed with this
33
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
from __future__ import annotations
5+
46
import asyncio
5-
from collections.abc import Mapping
67
from enum import Enum
78
from logging import getLogger
8-
from pathlib import Path
9-
from typing import cast
9+
from typing import TYPE_CHECKING, cast
1010

1111
from sapphire import ServerMap, create_listening_socket
1212

13-
from .base import BaseService
1413
from .webtransport.core import WebTransportServer
1514

15+
if TYPE_CHECKING:
16+
from collections.abc import Mapping
17+
from pathlib import Path
18+
19+
from .base import BaseService
20+
1621
LOG = getLogger(__name__)
1722

1823

@@ -29,7 +34,7 @@ def __init__(self, services: Mapping[ServiceName, BaseService]):
2934
"""Initialize new WebServices instance
3035
3136
Args:
32-
services (dict of ServiceName: BaseService): Collection of services.
37+
services: Collection of services.
3338
"""
3439
self.services = services
3540

@@ -46,10 +51,10 @@ async def is_running(self, timeout: float = 20) -> bool:
4651
"""Polls all available services to ensure they are running and accessible.
4752
4853
Args:
49-
timeout (int): Total time to wait.
54+
timeout: Total time to wait.
5055
5156
Returns:
52-
bool: Indicates if all services started successfully.
57+
Indicates if all services started successfully.
5358
"""
5459
tasks = {}
5560
for name, service in self.services.items():
@@ -79,12 +84,12 @@ def map_locations(self, server_map: ServerMap) -> None:
7984
)
8085

8186
@classmethod
82-
def start_services(cls, cert: Path, key: Path) -> "WebServices":
87+
def start_services(cls, cert: Path, key: Path) -> WebServices:
8388
"""Start all available services
8489
8590
Args:
86-
cert (Path): Path to the certificate file
87-
key (Path): Path to the certificate's private key
91+
cert: Certificate file
92+
key: Certificate's private key
8893
"""
8994
services = {}
9095
# Start WebTransport service

src/grizzly/services/webtransport/core.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
import asyncio
77
from asyncio import AbstractEventLoop
88
from logging import getLogger
9-
from os.path import abspath, dirname, join
9+
from pathlib import Path
1010
from platform import system
1111
from threading import Thread
12-
from typing import TYPE_CHECKING
1312

1413
from aioquic.asyncio import serve # type: ignore[attr-defined]
1514
from aioquic.h3.connection import H3_ALPN
@@ -23,16 +22,12 @@
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+
3631
LOG = 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

src/grizzly/services/webtransport/test_webtransport.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# pylint: disable=protected-access
55
import asyncio
66

7-
import pytest
7+
from pytest import raises
88

99
from sapphire import CertificateBundle
1010

@@ -32,7 +32,7 @@ def test_webtransport_01():
3232
web_transport.cleanup()
3333

3434
assert not web_transport._started
35-
with pytest.raises(asyncio.TimeoutError):
35+
with raises(asyncio.TimeoutError):
3636
asyncio.run(asyncio.wait_for(web_transport.is_ready(), timeout=1.0))
3737
finally:
3838
cert.cleanup()

0 commit comments

Comments
 (0)