aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author苏向夜 <fu050409@163.com>2023-12-14 17:41:19 +0800
committer苏向夜 <fu050409@163.com>2023-12-14 17:41:19 +0800
commit61bda5c7c0d96ba7d5cdb61828e9182bbf2741a2 (patch)
tree88ea13da54b8bf716b8ed1a9fdbbfb6124e73bdc
parent3c509e39213376e7f09565cce4668fb5b44a6590 (diff)
downloadinfini-61bda5c7c0d96ba7d5cdb61828e9182bbf2741a2.tar.gz
infini-61bda5c7c0d96ba7d5cdb61828e9182bbf2741a2.zip
:sparkles: 允许在业务层拦截参数
-rw-r--r--src/infini/handler.py12
-rw-r--r--src/infini/matcher.py4
2 files changed, 6 insertions, 10 deletions
diff --git a/src/infini/handler.py b/src/infini/handler.py
index 1edef9fa..8f50fc8c 100644
--- a/src/infini/handler.py
+++ b/src/infini/handler.py
@@ -10,18 +10,12 @@ class Result(metaclass=ABCMeta):
event: str
status: bool
- exception: HydroError | None = None
+ kwargs: dict = {}
- def __init__(
- self, event: str, status: bool, exception: HydroError | None = None
- ) -> None:
+ def __init__(self, event: str, status: bool, **kwargs) -> None:
self.event = event
self.status = status
- self.exception = exception
-
- def ok(self):
- """规则执行期间是否产生异常"""
- return isinstance(self.exception, HydroError)
+ self.kwargs = kwargs
class Handler:
diff --git a/src/infini/matcher.py b/src/infini/matcher.py
index 1a6bfe45..d7cfa336 100644
--- a/src/infini/matcher.py
+++ b/src/infini/matcher.py
@@ -37,7 +37,9 @@ class Matcher:
def run(self, event: MatcherEvent) -> str:
result = self.match(event.name).process(**event.kwargs)
- return self.events.process(result.event, **event.kwargs)
+ return self.events.process(
+ result.event, **result.kwargs if result.kwargs else event.kwargs
+ )
matcher = Matcher()