aboutsummaryrefslogtreecommitdiff
path: root/services/manager/_decorator.py
diff options
context:
space:
mode:
authorYuqian Yang <crupest@crupest.life>2025-02-23 16:40:32 +0800
committerYuqian Yang <crupest@crupest.life>2025-02-23 16:40:32 +0800
commit90868bf85dc295f70620dbcbd5790999fe239550 (patch)
tree08c0f73597a751acff14a4d224446e87b2d8775d /services/manager/_decorator.py
parent1e9b2436eaffa4130f6a69c3a108f6feb9dd4ac8 (diff)
downloadcrupest-90868bf85dc295f70620dbcbd5790999fe239550.tar.gz
crupest-90868bf85dc295f70620dbcbd5790999fe239550.tar.bz2
crupest-90868bf85dc295f70620dbcbd5790999fe239550.zip
feat(python): move python codes.
Diffstat (limited to 'services/manager/_decorator.py')
-rw-r--r--services/manager/_decorator.py97
1 files changed, 0 insertions, 97 deletions
diff --git a/services/manager/_decorator.py b/services/manager/_decorator.py
deleted file mode 100644
index 137fc05..0000000
--- a/services/manager/_decorator.py
+++ /dev/null
@@ -1,97 +0,0 @@
-from __future__ import annotations
-
-from collections.abc import Callable
-from typing import (
- Concatenate,
- Generic,
- ParamSpec,
- TypeVar,
- cast,
-)
-
-from ._base import CRU
-
-_P = ParamSpec("_P")
-_T = TypeVar("_T")
-_O = TypeVar("_O")
-_R = TypeVar("_R")
-
-
-class CruDecorator:
-
- class ConvertResult(Generic[_T, _O]):
- def __init__(
- self,
- converter: Callable[[_T], _O],
- ) -> None:
- self.converter = converter
-
- def __call__(self, origin: Callable[_P, _T]) -> Callable[_P, _O]:
- converter = self.converter
-
- def real_impl(*args: _P.args, **kwargs: _P.kwargs) -> _O:
- return converter(origin(*args, **kwargs))
-
- return real_impl
-
- class ImplementedBy(Generic[_T, _O, _P, _R]):
- def __init__(
- self,
- impl: Callable[Concatenate[_O, _P], _R],
- converter: Callable[[_T], _O],
- ) -> None:
- self.impl = impl
- self.converter = converter
-
- def __call__(
- self, _origin: Callable[[_T], None]
- ) -> Callable[Concatenate[_T, _P], _R]:
- converter = self.converter
- impl = self.impl
-
- def real_impl(_self: _T, *args: _P.args, **kwargs: _P.kwargs) -> _R:
- return cast(Callable[Concatenate[_O, _P], _R], impl)(
- converter(_self), *args, **kwargs
- )
-
- return real_impl
-
- @staticmethod
- def create_factory(converter: Callable[[_T], _O]) -> Callable[
- [Callable[Concatenate[_O, _P], _R]],
- CruDecorator.ImplementedBy[_T, _O, _P, _R],
- ]:
- def create(
- m: Callable[Concatenate[_O, _P], _R],
- ) -> CruDecorator.ImplementedBy[_T, _O, _P, _R]:
- return CruDecorator.ImplementedBy(m, converter)
-
- return create
-
- class ImplementedByNoSelf(Generic[_P, _R]):
- def __init__(self, impl: Callable[_P, _R]) -> None:
- self.impl = impl
-
- def __call__(
- self, _origin: Callable[[_T], None]
- ) -> Callable[Concatenate[_T, _P], _R]:
- impl = self.impl
-
- def real_impl(_self: _T, *args: _P.args, **kwargs: _P.kwargs) -> _R:
- return cast(Callable[_P, _R], impl)(*args, **kwargs)
-
- return real_impl
-
- @staticmethod
- def create_factory() -> (
- Callable[[Callable[_P, _R]], CruDecorator.ImplementedByNoSelf[_P, _R]]
- ):
- def create(
- m: Callable[_P, _R],
- ) -> CruDecorator.ImplementedByNoSelf[_P, _R]:
- return CruDecorator.ImplementedByNoSelf(m)
-
- return create
-
-
-CRU.add_objects(CruDecorator)