How to use the pomegranate.filters.base.Filter function in pomegranate

To help you get started, we’ve selected a few pomegranate examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github uwinx / pomegranate / pomegranate / filters / base.py View on Github external
def __init__(
        self,
        function: Callable,
        requires_context: bool = False,
    ):
        if isinstance(function, Filter):
            self.function = function.function
            self.awaitable = function.awaitable
            self.requires_context = function.requires_context

        else:
            self.function = function
            self.awaitable = False
            self.requires_context = requires_context

            if inspect.iscoroutinefunction(function) or inspect.isawaitable(function):
                self.awaitable = True
github uwinx / pomegranate / pomegranate / filters / base.py View on Github external
def exact(cls, state: str, reverse: bool = False) -> Filter:
        async def _f(*_, context):
            if reverse:
                return (await context.get_state()) != state
            return (await context.get_state()) == state

        return Filter(_f, requires_context=True)
github uwinx / pomegranate / pomegranate / filters / base.py View on Github external
def any(cls) -> Filter:
        return Filter(lambda *ignore: True)
github uwinx / pomegranate / pomegranate / filters / base.py View on Github external
def between(cls, states: List[str]) -> Filter:
        async def _f(*_, context):
            return (await context.get_state()) in states

        return Filter(_f, requires_context=True)