mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-09-21 14:57:42 +00:00
Autogenerated type safety parameterisation of all methods
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from typing import Any
|
||||
|
||||
from tornado.web import RequestHandler
|
||||
|
||||
from webserver.handlers.api.spots import APISpotsHandler, APISpotsStreamHandler
|
||||
|
||||
@@ -13,7 +18,7 @@ _LEGACY_PARAM_TO_HEADER_MAP = {
|
||||
}
|
||||
|
||||
|
||||
def _handle_legacy_params(handler):
|
||||
def _handle_legacy_params(handler: RequestHandler) -> None:
|
||||
"""Copy v1 query-string QRZ/HamQTH credentials into the v2 headers, so the v2 handler can see them"""
|
||||
|
||||
for param, header in _LEGACY_PARAM_TO_HEADER_MAP.items():
|
||||
@@ -27,11 +32,11 @@ def _handle_legacy_params(handler):
|
||||
class V1APISpotsHandler(APISpotsHandler):
|
||||
"""API request handler for /api/v1/spots (GET). Included in early Spothole v2 for backwards compatibility."""
|
||||
|
||||
def prepare(self):
|
||||
def prepare(self) -> None:
|
||||
_handle_legacy_params(self)
|
||||
super().prepare()
|
||||
|
||||
def write(self, chunk):
|
||||
def write(self, chunk: str | bytes | dict[str, Any]) -> None:
|
||||
if isinstance(chunk, str):
|
||||
chunk = _GRID_SOURCE_RE.sub('"dx_location_source": "SPOT"', chunk)
|
||||
super().write(chunk)
|
||||
@@ -40,11 +45,11 @@ class V1APISpotsHandler(APISpotsHandler):
|
||||
class V1APISpotsStreamHandler(APISpotsStreamHandler):
|
||||
"""API request handler for /api/v1/spots/stream (SSE). Included in early Spothole v2 for backwards compatibility."""
|
||||
|
||||
def prepare(self):
|
||||
def prepare(self) -> None:
|
||||
_handle_legacy_params(self)
|
||||
super().prepare()
|
||||
|
||||
def write_message(self, *args, **kwargs):
|
||||
def write_message(self, *args: Any, **kwargs: Any) -> None:
|
||||
args = list(args)
|
||||
for i, a in enumerate(args):
|
||||
if isinstance(a, str) and '"dx_location_source"' in a:
|
||||
|
||||
Reference in New Issue
Block a user