refactor!: use all ruff rules

This commit is contained in:
2026-04-12 16:46:12 +02:00
parent 1a165876fe
commit 5bb9725000
9 changed files with 211 additions and 156 deletions
+16 -11
View File
@@ -1,12 +1,17 @@
import contextlib
import http.server
import logging
import os
import pathlib
import typing
from . import handler, params, project, registry
from . import handler, project, registry
if typing.TYPE_CHECKING:
from . import params
class StaplerServer:
def __init__(self, params: params.Parameters):
def __init__(self, params: params.Parameters) -> None:
self.logger = logging.getLogger(self.__class__.__name__)
self.params = params
self.registry = registry.Registry(params)
@@ -15,18 +20,20 @@ class StaplerServer:
self.request_handler,
)
def request_handler(self, *args) -> http.server.BaseHTTPRequestHandler:
def request_handler(self, *args: typing.Any) -> http.server.BaseHTTPRequestHandler:
return handler.RequestHandler(*args, params=self.params, registry=self.registry)
def __init_certbot_www(self):
os.makedirs(self.params.certbot_www, exist_ok=True)
def __init_certbot_www(self) -> None:
certbot_www_path = pathlib.Path(self.params.certbot_www)
if not certbot_www_path.exists():
certbot_www_path.mkdir(parents=True)
def __startup(self):
def __startup(self) -> None:
self.logger.info("Starting up...")
self.registry.load_pages()
self.__init_certbot_www()
def start(self):
def start(self) -> None:
self.logger.info("Version %s", project.get_version())
self.__startup()
self.logger.info(
@@ -38,7 +45,5 @@ class StaplerServer:
"Server up and ready on http://%s",
self.params.host,
)
try:
with contextlib.suppress(KeyboardInterrupt):
self.server.serve_forever()
except KeyboardInterrupt:
pass