예제 #1
0
    def add_plugin_handlers(self, plugin_id, handlers):
        """plugin apiを追加する"""

        # plugin apiのprefixをURLに追加する
        path_prefix = '/plugins/{}/'.format(plugin_id)
        replaced_handlers = []
        for rule in handlers:
            if isinstance(rule, (tuple, list)):
                if isinstance(rule[0], str):
                    if not rule[0].startswith('/'):
                        raise ValueError(
                            'invalid plugin url path, must be startswith \'/\''
                        )
                    rule = (path_prefix + rule[0][1:], *rule[1:])
                else:
                    assert 0, 'not implemented'
            else:
                assert 0, 'not implemented'

            replaced_handlers.append(rule)

        # 登録
        self.wildcard_router.add_rules([
            (path_prefix + '.*$',
             web._ApplicationRouter(self, replaced_handlers))
        ])
예제 #2
0
 def reset_handlers(self):
     self.wildcard_router = _ApplicationRouter(self, [])
     self.default_router = _ApplicationRouter(self, [
         Rule(AnyMatches(), self.wildcard_router)
     ])
예제 #3
0
 def __init__(self, app, url):
     super().__init__(app, url)
     self.router = _ApplicationRouter(app)
     self.app.default_router.add_rules([(url + r'(.*)', self.router)])