Dependable remove __call__

This commit is contained in:
Jörn-Michael Miehe 2023-10-25 20:50:03 +02:00
parent e428fea3da
commit 7fb3aa0f42
5 changed files with 10 additions and 13 deletions

View file

@ -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]:

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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}")