Exemplo n.º 1
0
 def wrapper(function: Callable) -> Callable:
     wrapped = function
     if not asyncio.iscoroutinefunction(wrapped):
         wrapped = asyncio.coroutine(wrapped)
     compiled = simplex.compile(pattern)
     self.routes[compiled] = (wrapped, pattern)
     return function
Exemplo n.º 2
0
 def wrapper(function: Callable) -> Callable:
     wrapped = function
     if not asyncio.iscoroutinefunction(wrapped):
         wrapped = asyncio.coroutine(wrapped)
     compiled = simplex.compile(pattern)
     self.routes[compiled] = (wrapped, pattern)
     return function
Exemplo n.º 3
0
    def route(self, pattern, func=None, **kwargs):
        """Register a callback for a given pattern

        @router.route("client, say [words]")
        def handle(nick, target, fields):
            # PRIVMSG - respond in kind
            if target==router.client.NICK:
                target = nick
            message = fields["words"]
            router.client.send("PRIVMSG", target=target, message=message)

        """
        if func is None:
            return functools.partial(self.route, pattern)

        # Decorator should always return the original function
        wrapped = func
        if not asyncio.iscoroutinefunction(wrapped):
            wrapped = asyncio.coroutine(wrapped)

        compiled = simplex.compile(pattern)
        self.routes[compiled] = (wrapped, pattern)
        return func
Exemplo n.º 4
0
 def wrapper(function):
     if not asyncio.iscoroutinefunction(function):
         function = asyncio.coroutine(function)
     compiled = simplex.compile(pattern)
     self.routes[compiled] = (function, pattern)
     return function