def view_bind(app, cls_url, view_cls: Type['<STR_LIT>']):
if view_cls._no_route: return<EOL>cls_url = cls_url or view_cls.__class__.__name__.lower()<EOL>def add_route(name, route_info, beacon_info):<EOL><INDENT>for method in route_info['<STR_LIT>']:<EOL><INDENT>async def beacon(request): pass<EOL>route_key = route_info['<STR_LIT:url>'] if route_info['<STR_LIT:url>'] else name<EOL>app._raw_app.router.add_route(method, urljoin('<STR_LIT>', cls_url, route_key), beacon)<EOL>app.route._beacons[beacon] = beacon_info<EOL><DEDENT><DEDENT>for name, route_info_lst in view_cls._interface.items():<EOL><INDENT>for route_info in route_info_lst:<EOL><INDENT>real_handler = getattr(view_cls, name, None)<EOL>if real_handler is None: continue <EOL>assert real_handler is not None, "<STR_LIT>"<EOL>handler_name = '<STR_LIT>' % (view_cls.__name__, real_handler.__name__)<EOL>assert iscoroutinefunction(real_handler), "<STR_LIT>" % handler_name<EOL>beacon_info = {<EOL>'<STR_LIT>': view_cls,<EOL>'<STR_LIT:name>': name,<EOL>'<STR_LIT>': real_handler,<EOL>'<STR_LIT>': route_info<EOL>}<EOL>add_route(name, route_info, beacon_info)<EOL><DEDENT><DEDENT>
将 API 绑定到 web 服务上
:param view_cls:
:param app:
:param cls_url:
:return: