python-cq 0.16.1__tar.gz → 0.17.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python_cq-0.16.1 → python_cq-0.17.0}/PKG-INFO +1 -1
- {python_cq-0.16.1 → python_cq-0.17.0}/cq/_core/dispatcher/base.py +8 -6
- {python_cq-0.16.1 → python_cq-0.17.0}/cq/_core/dispatcher/pipe.py +20 -3
- {python_cq-0.16.1 → python_cq-0.17.0}/cq/_core/pipetools.py +4 -1
- {python_cq-0.16.1 → python_cq-0.17.0}/pyproject.toml +1 -1
- {python_cq-0.16.1 → python_cq-0.17.0}/.gitignore +0 -0
- {python_cq-0.16.1 → python_cq-0.17.0}/LICENSE +0 -0
- {python_cq-0.16.1 → python_cq-0.17.0}/cq/__init__.py +0 -0
- {python_cq-0.16.1 → python_cq-0.17.0}/cq/_core/__init__.py +0 -0
- {python_cq-0.16.1 → python_cq-0.17.0}/cq/_core/common/__init__.py +0 -0
- {python_cq-0.16.1 → python_cq-0.17.0}/cq/_core/common/typing.py +0 -0
- {python_cq-0.16.1 → python_cq-0.17.0}/cq/_core/cq.py +0 -0
- {python_cq-0.16.1 → python_cq-0.17.0}/cq/_core/di.py +0 -0
- {python_cq-0.16.1 → python_cq-0.17.0}/cq/_core/dispatcher/__init__.py +0 -0
- {python_cq-0.16.1 → python_cq-0.17.0}/cq/_core/dispatcher/bus.py +0 -0
- {python_cq-0.16.1 → python_cq-0.17.0}/cq/_core/dispatcher/lazy.py +0 -0
- {python_cq-0.16.1 → python_cq-0.17.0}/cq/_core/handler.py +0 -0
- {python_cq-0.16.1 → python_cq-0.17.0}/cq/_core/message.py +0 -0
- {python_cq-0.16.1 → python_cq-0.17.0}/cq/_core/middleware.py +0 -0
- {python_cq-0.16.1 → python_cq-0.17.0}/cq/_core/middlewares/__init__.py +0 -0
- {python_cq-0.16.1 → python_cq-0.17.0}/cq/_core/middlewares/scope.py +0 -0
- {python_cq-0.16.1 → python_cq-0.17.0}/cq/_core/related_events.py +0 -0
- {python_cq-0.16.1 → python_cq-0.17.0}/cq/exceptions.py +0 -0
- {python_cq-0.16.1 → python_cq-0.17.0}/cq/ext/__init__.py +0 -0
- {python_cq-0.16.1 → python_cq-0.17.0}/cq/ext/injection.py +0 -0
- {python_cq-0.16.1 → python_cq-0.17.0}/cq/middlewares/__init__.py +0 -0
- {python_cq-0.16.1 → python_cq-0.17.0}/cq/middlewares/retry.py +0 -0
- {python_cq-0.16.1 → python_cq-0.17.0}/cq/py.typed +0 -0
- {python_cq-0.16.1 → python_cq-0.17.0}/docs/index.md +0 -0
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
from abc import ABC, abstractmethod
|
|
2
2
|
from collections.abc import Awaitable, Callable
|
|
3
|
-
from contextlib import AsyncExitStack, suppress
|
|
4
3
|
from typing import Protocol, Self, runtime_checkable
|
|
5
4
|
|
|
6
5
|
from cq._core.middleware import Middleware, MiddlewareGroup
|
|
@@ -10,6 +9,9 @@ from cq._core.middleware import Middleware, MiddlewareGroup
|
|
|
10
9
|
class Dispatcher[I, O](Protocol):
|
|
11
10
|
__slots__ = ()
|
|
12
11
|
|
|
12
|
+
async def __call__(self, input_value: I, /) -> O:
|
|
13
|
+
return await self.dispatch(input_value)
|
|
14
|
+
|
|
13
15
|
@abstractmethod
|
|
14
16
|
async def dispatch(self, input_value: I, /) -> O:
|
|
15
17
|
raise NotImplementedError
|
|
@@ -34,10 +36,10 @@ class BaseDispatcher[I, O](Dispatcher[I, O], ABC):
|
|
|
34
36
|
/,
|
|
35
37
|
fail_silently: bool = False,
|
|
36
38
|
) -> O:
|
|
37
|
-
|
|
38
|
-
if fail_silently:
|
|
39
|
-
stack.enter_context(suppress(Exception))
|
|
40
|
-
|
|
39
|
+
try:
|
|
41
40
|
return await self.__middleware_group.invoke(handler, input_value)
|
|
41
|
+
except Exception:
|
|
42
|
+
if fail_silently:
|
|
43
|
+
return NotImplemented
|
|
42
44
|
|
|
43
|
-
|
|
45
|
+
raise
|
|
@@ -54,6 +54,15 @@ class PipelineSteps[**P, I, O]:
|
|
|
54
54
|
self.__steps.append(PipelineStep(converter, dispatcher))
|
|
55
55
|
return self
|
|
56
56
|
|
|
57
|
+
def add_static[T](
|
|
58
|
+
self,
|
|
59
|
+
input_value: T,
|
|
60
|
+
dispatcher: Dispatcher[T, Any] | None,
|
|
61
|
+
) -> Self:
|
|
62
|
+
converter = _StaticPipelineConverter(input_value)
|
|
63
|
+
self.add(converter, dispatcher) # type: ignore[arg-type]
|
|
64
|
+
return self
|
|
65
|
+
|
|
57
66
|
async def execute(self, input_value: I, /, *args: P.args, **kwargs: P.kwargs) -> O:
|
|
58
67
|
dispatcher = self.default_dispatcher
|
|
59
68
|
|
|
@@ -128,11 +137,10 @@ class Pipe[I, O](BaseDispatcher[I, O]):
|
|
|
128
137
|
def add_static_step[T](
|
|
129
138
|
self,
|
|
130
139
|
input_value: T,
|
|
131
|
-
|
|
140
|
+
/,
|
|
132
141
|
dispatcher: Dispatcher[T, Any] | None = None,
|
|
133
142
|
) -> Self:
|
|
134
|
-
|
|
135
|
-
self.__steps.add(converter, dispatcher)
|
|
143
|
+
self.__steps.add_static(input_value, dispatcher)
|
|
136
144
|
return self
|
|
137
145
|
|
|
138
146
|
async def dispatch(self, input_value: I, /) -> O:
|
|
@@ -189,6 +197,15 @@ class ContextPipeline[I]:
|
|
|
189
197
|
self.__middleware_group.add(*middlewares)
|
|
190
198
|
return self
|
|
191
199
|
|
|
200
|
+
def add_static_step[T](
|
|
201
|
+
self,
|
|
202
|
+
input_value: T,
|
|
203
|
+
/,
|
|
204
|
+
dispatcher: Dispatcher[T, Any] | None = None,
|
|
205
|
+
) -> Self:
|
|
206
|
+
self.__steps.add_static(input_value, dispatcher)
|
|
207
|
+
return self
|
|
208
|
+
|
|
192
209
|
if TYPE_CHECKING: # pragma: no cover
|
|
193
210
|
|
|
194
211
|
@overload
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import TYPE_CHECKING, Any, overload
|
|
1
|
+
from typing import TYPE_CHECKING, Any, Self, overload
|
|
2
2
|
|
|
3
3
|
from cq import Dispatcher
|
|
4
4
|
from cq._core.common.typing import Decorator
|
|
@@ -25,6 +25,9 @@ class ContextCommandPipeline[C: Command](ContextPipeline[C]):
|
|
|
25
25
|
command_middleware = CommandDispatchScopeMiddleware(di)
|
|
26
26
|
self.add_middlewares(command_middleware)
|
|
27
27
|
|
|
28
|
+
def add_static_query_step[Q: Query](self, query: Q, /) -> Self:
|
|
29
|
+
return self.add_static_step(query, dispatcher=self.__query_dispatcher)
|
|
30
|
+
|
|
28
31
|
if TYPE_CHECKING: # pragma: no cover
|
|
29
32
|
|
|
30
33
|
@overload
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|