From 7fb3aa0f428a8c8ff7d4d0559cd024767efc61b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Wed, 25 Oct 2023 20:50:03 +0200 Subject: [PATCH] Dependable remove __call__ --- api/ovdashboard_api/routers/v1/_common.py | 11 ++++------- api/ovdashboard_api/routers/v1/file.py | 2 +- api/ovdashboard_api/routers/v1/image.py | 2 +- api/ovdashboard_api/routers/v1/text.py | 2 +- api/ovdashboard_api/routers/v1/ticker.py | 6 +++--- 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/api/ovdashboard_api/routers/v1/_common.py b/api/ovdashboard_api/routers/v1/_common.py index abfbaf1..872a675 100644 --- a/api/ovdashboard_api/routers/v1/_common.py +++ b/api/ovdashboard_api/routers/v1/_common.py @@ -5,7 +5,7 @@ Dependables for defining Routers. import re from dataclasses import dataclass from logging import getLogger -from typing import Awaitable, Callable, ParamSpec, TypeVar +from typing import Awaitable, Callable, Generic, ParamSpec, TypeVar from fastapi import HTTPException, status from webdav3.exceptions import RemoteResourceNotFound @@ -29,13 +29,10 @@ Return = TypeVar("Return") @dataclass(slots=True, frozen=True) -class Dependable[**Params, Return]: +class Dependable(Generic[Params, Return]): func: Callable[Params, Awaitable[Return]] responses: dict - async def __call__(self, *args: Params.args, **kwds: Params.kwargs) -> Return: - return await self.func(*args, **kwds) - type _NDependable[Return] = Dependable[[], Return] @@ -115,7 +112,7 @@ def filter_prefix( prefix: str, ) -> list[str]: return list( - item for item in (await src()) if item.lower().startswith(prefix.lower()) + item for item in (await src.func()) if item.lower().startswith(prefix.lower()) ) return Dependable( @@ -142,7 +139,7 @@ def filter_prefix_unique( async def _filter_prefix_unique( prefix: str, ) -> str: - names = await src(prefix) + names = await src.func(prefix) match names: case [name]: diff --git a/api/ovdashboard_api/routers/v1/file.py b/api/ovdashboard_api/routers/v1/file.py index 93d0bbb..4b01d1d 100644 --- a/api/ovdashboard_api/routers/v1/file.py +++ b/api/ovdashboard_api/routers/v1/file.py @@ -41,7 +41,7 @@ _fpu = filter_prefix_unique(_fp) async def start_router() -> None: _logger.debug(f"{router.prefix} router starting.") - remote_path = await _rp() + remote_path = await _rp.func() if not webdav_ensure_path(remote_path): webdav_ensure_files( remote_path, diff --git a/api/ovdashboard_api/routers/v1/image.py b/api/ovdashboard_api/routers/v1/image.py index c0adf47..d5481ac 100644 --- a/api/ovdashboard_api/routers/v1/image.py +++ b/api/ovdashboard_api/routers/v1/image.py @@ -41,7 +41,7 @@ _fpu = filter_prefix_unique(_fp) async def start_router() -> None: _logger.debug(f"{router.prefix} router starting.") - remote_path = await _rp() + remote_path = await _rp.func() if not webdav_ensure_path(remote_path): webdav_ensure_files( remote_path, diff --git a/api/ovdashboard_api/routers/v1/text.py b/api/ovdashboard_api/routers/v1/text.py index 89111b0..47ed546 100644 --- a/api/ovdashboard_api/routers/v1/text.py +++ b/api/ovdashboard_api/routers/v1/text.py @@ -39,7 +39,7 @@ _fpu = filter_prefix_unique(_fp) async def start_router() -> None: _logger.debug(f"{router.prefix} router starting.") - remote_path = await _rp() + remote_path = await _rp.func() if not webdav_ensure_path(remote_path): webdav_ensure_files( remote_path, diff --git a/api/ovdashboard_api/routers/v1/ticker.py b/api/ovdashboard_api/routers/v1/ticker.py index 949fa6f..7ab19c8 100644 --- a/api/ovdashboard_api/routers/v1/ticker.py +++ b/api/ovdashboard_api/routers/v1/ticker.py @@ -26,7 +26,7 @@ router = APIRouter(prefix="/ticker", tags=["text"]) async def start_router() -> None: _logger.debug(f"{router.prefix} router starting.") - remote_path = await _rp() + remote_path = await _rp.func() if not webdav_ensure_path(remote_path): webdav_ensure_files( remote_path, @@ -36,8 +36,8 @@ async def start_router() -> None: async def get_ticker_lines() -> Iterator[str]: cfg = await get_config() - file_name = await _fpu(cfg.ticker.file_name) - remote_path = await _rp() + file_name = await _fpu.func(cfg.ticker.file_name) + remote_path = await _rp.func() ticker = await WebDAV.read_str(f"{remote_path}/{file_name}")