[docs]classFilter(ABC):""" If you want to register own filters like builtin filters you will need to write subclass of this class with overriding the :code:`__call__` method and adding filter attributes. """ifTYPE_CHECKING:# This checking type-hint is needed because mypy checks validity of overrides and raises:# error: Signature of "__call__" incompatible with supertype "BaseFilter" [override]# https://mypy.readthedocs.io/en/latest/error_code_list.html#check-validity-of-overrides-override__call__:Callable[...,Awaitable[Union[bool,Dict[str,Any]]]]else:# pragma: no cover
[docs]@abstractmethodasyncdef__call__(self,*args:Any,**kwargs:Any)->Union[bool,Dict[str,Any]]:""" This method should be overridden. Accepts incoming event and should return boolean or dict. :return: :class:`bool` or :class:`Dict[str, Any]` """pass
[docs]defupdate_handler_flags(self,flags:Dict[str,Any])->None:""" Also if you want to extend handler flags with using this filter you should implement this method :param flags: existing flags, can be updated directly """pass
def_signature_to_string(self,*args:Any,**kwargs:Any)->str:items=[repr(arg)forarginargs]items.extend([f"{k}={v!r}"fork,vinkwargs.items()ifvisnotNone])returnf"{type(self).__name__}({', '.join(items)})"def__await__(self):# type: ignore # pragma: no cover# Is needed only for inspection and this method is never be calledreturnself.__call__