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
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
def wrapper(function): if not asyncio.iscoroutinefunction(function): function = asyncio.coroutine(function) compiled = simplex.compile(pattern) self.routes[compiled] = (function, pattern) return function