Erster Stand der Hintergrundprozesse, die auf der Synology unter /volume1/homes/wagner/SolarManager laufen: der Manager selbst, die Sammler je Geraet, die MQTT-Bruecke, der Wecker und - neu hinzugezogen - der AutoAction-Runner, der als Hintergrundprozess hierher gehoert und nicht ins Web-Verzeichnis. Zugangsdaten stehen nicht mehr im Quelltext, sondern in config.ini, die nicht mit eingecheckt wird. Vorlage ist config.ini.example, gelesen wird sie von konfig.py. Betroffen waren solarManager.py (Datenbank und Wattpilot), zeit.py, gatherWaterData.py, wecker.py und skoda_testdaten.py, das sich das Passwort bisher aus dem Quelltext eines anderen Moduls herausgesucht hat. Die Kia-Anbindung ist mit dem Fahrzeug entfallen: kiaTest.py, gatherCarData.py und hyundai_kia_connect_api sind nicht mehr dabei, ebenso gatherInverterData.py, auf das nur noch eine auskommentierte Zeile zeigte. Die mitgelieferten Bibliotheken bleiben im Repository - die NAS hat kein pip, sie muessen neben den Skripten liegen. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
80 lines
2.6 KiB
Python
80 lines
2.6 KiB
Python
"""Low level HTTP server."""
|
|
import asyncio
|
|
import warnings
|
|
from typing import Any, Awaitable, Callable, Dict, List, Optional # noqa
|
|
|
|
from .abc import AbstractStreamWriter
|
|
from .http_parser import RawRequestMessage
|
|
from .streams import StreamReader
|
|
from .web_protocol import RequestHandler, _RequestFactory, _RequestHandler
|
|
from .web_request import BaseRequest
|
|
|
|
__all__ = ("Server",)
|
|
|
|
|
|
class Server:
|
|
def __init__(
|
|
self,
|
|
handler: _RequestHandler,
|
|
*,
|
|
request_factory: Optional[_RequestFactory] = None,
|
|
debug: Optional[bool] = None,
|
|
handler_cancellation: bool = False,
|
|
**kwargs: Any,
|
|
) -> None:
|
|
if debug is not None:
|
|
warnings.warn(
|
|
"debug argument is no-op since 4.0 " "and scheduled for removal in 5.0",
|
|
DeprecationWarning,
|
|
stacklevel=2,
|
|
)
|
|
self._loop = asyncio.get_running_loop()
|
|
self._connections: Dict[RequestHandler, asyncio.Transport] = {}
|
|
self._kwargs = kwargs
|
|
self.requests_count = 0
|
|
self.request_handler = handler
|
|
self.request_factory = request_factory or self._make_request
|
|
self.handler_cancellation = handler_cancellation
|
|
|
|
@property
|
|
def connections(self) -> List[RequestHandler]:
|
|
return list(self._connections.keys())
|
|
|
|
def connection_made(
|
|
self, handler: RequestHandler, transport: asyncio.Transport
|
|
) -> None:
|
|
self._connections[handler] = transport
|
|
|
|
def connection_lost(
|
|
self, handler: RequestHandler, exc: Optional[BaseException] = None
|
|
) -> None:
|
|
if handler in self._connections:
|
|
del self._connections[handler]
|
|
|
|
def _make_request(
|
|
self,
|
|
message: RawRequestMessage,
|
|
payload: StreamReader,
|
|
protocol: RequestHandler,
|
|
writer: AbstractStreamWriter,
|
|
task: "asyncio.Task[None]",
|
|
) -> BaseRequest:
|
|
return BaseRequest(message, payload, protocol, writer, task, self._loop)
|
|
|
|
async def shutdown(self, timeout: Optional[float] = None) -> None:
|
|
coros = [conn.shutdown(timeout) for conn in self._connections]
|
|
await asyncio.gather(*coros)
|
|
self._connections.clear()
|
|
|
|
def __call__(self) -> RequestHandler:
|
|
try:
|
|
return RequestHandler(self, loop=self._loop, **self._kwargs)
|
|
except TypeError:
|
|
# Failsafe creation: remove all custom handler_args
|
|
kwargs = {
|
|
k: v
|
|
for k, v in self._kwargs.items()
|
|
if k in ["debug", "access_log_class"]
|
|
}
|
|
return RequestHandler(self, loop=self._loop, **kwargs)
|