コード例 #1
0
ファイル: router.py プロジェクト: AMorporkian/bottom
 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
コード例 #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
コード例 #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
コード例 #4
0
ファイル: router.py プロジェクト: Vgr255/bottom
 def wrapper(function):
     if not asyncio.iscoroutinefunction(function):
         function = asyncio.coroutine(function)
     compiled = simplex.compile(pattern)
     self.routes[compiled] = (function, pattern)
     return function