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)) ])
def reset_handlers(self): self.wildcard_router = _ApplicationRouter(self, []) self.default_router = _ApplicationRouter(self, [ Rule(AnyMatches(), self.wildcard_router) ])
def __init__(self, app, url): super().__init__(app, url) self.router = _ApplicationRouter(app) self.app.default_router.add_rules([(url + r'(.*)', self.router)])