2022-11-21 18:44:55 +08:00
|
|
|
import abc
|
2024-04-16 00:33:48 +08:00
|
|
|
from typing import TYPE_CHECKING
|
2022-11-21 18:44:55 +08:00
|
|
|
from collections import defaultdict
|
2024-04-16 00:33:48 +08:00
|
|
|
from collections.abc import Mapping, MutableMapping
|
2022-11-21 18:44:55 +08:00
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
from .matcher import Matcher
|
|
|
|
|
|
|
|
|
2024-04-16 00:33:48 +08:00
|
|
|
class MatcherProvider(abc.ABC, MutableMapping[int, list[type["Matcher"]]]):
|
2022-11-21 18:44:55 +08:00
|
|
|
"""事件响应器存储器基类
|
|
|
|
|
|
|
|
参数:
|
|
|
|
matchers: 当前存储器中已有的事件响应器
|
|
|
|
"""
|
|
|
|
|
|
|
|
@abc.abstractmethod
|
2024-04-16 00:33:48 +08:00
|
|
|
def __init__(self, matchers: Mapping[int, list[type["Matcher"]]]):
|
2022-11-21 18:44:55 +08:00
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
|
|
|
|
class _DictProvider(defaultdict, MatcherProvider):
|
2024-04-16 00:33:48 +08:00
|
|
|
def __init__(self, matchers: Mapping[int, list[type["Matcher"]]]):
|
2022-11-21 18:44:55 +08:00
|
|
|
super().__init__(list, matchers)
|
|
|
|
|
|
|
|
|
|
|
|
DEFAULT_PROVIDER_CLASS = _DictProvider
|
|
|
|
"""默认存储器类型"""
|