@contextmanager<EOL>def add_resource_context(<EOL>app: web.Application, module=None,<EOL>url_prefix: str=None, name_prefix: str=None, make_resource=lambda cls: cls()<EOL>):
assert isinstance(app.router, ResourceRouter), '<STR_LIT>'<EOL>if isinstance(module, (str, bytes)):<EOL><INDENT>module = importlib.import_module(module)<EOL><DEDENT>def get_base_name(resource, method_name, names):<EOL><INDENT>return names.get(method_name,<EOL>app.router.get_default_handler_name(resource, method_name))<EOL><DEDENT>default_make_resource = make_resource<EOL>def add_route(<EOL>path: str, resource, names: Mapping=None, make_resource=None<EOL>):<EOL><INDENT>make_resource = make_resource or default_make_resource<EOL>names = names or {}<EOL>if isinstance(resource, (str, bytes)):<EOL><INDENT>if not module:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'<EOL>)<EOL><DEDENT>resource_cls = getattr(module, resource)<EOL>resource = make_resource(resource_cls)<EOL><DEDENT>path = make_path(path, url_prefix)<EOL>if name_prefix:<EOL><INDENT>supported_method_names = get_supported_method_names(resource)<EOL>names = {<EOL>method_name: '<STR_LIT:.>'.join(<EOL>(name_prefix, get_base_name(resource, method_name, names=names))<EOL>)<EOL>for method_name in supported_method_names<EOL>}<EOL><DEDENT>return app.router.add_resource_object(path, resource, names=names)<EOL><DEDENT>yield add_route<EOL>
Context manager which yields a function for adding multiple resources from a given module
    to an app using `ResourceRouter <aiohttp_utils.routing.ResourceRouter>`.

    Example:

    .. code-block:: python

        # myapp/articles/views.py
        class ArticleList:
            async def get(self, request):
                return web.Response(b'article list...')

        class ArticleDetail:
            async def get(self, request):
                return web.Response(b'article detail...')

    .. code-block:: python

        # myapp/app.py
        from myapp.articles import views

        with add_resource_context(app, url_prefix='/api/') as route:
            route('/articles/', views.ArticleList())
            route('/articles/{pk}', views.ArticleDetail())

        app.router['ArticleList:get'].url()  # /api/articles/
        app.router['ArticleDetail:get'].url(parts={'pk': 42})  # /api/articles/42

    If you prefer, you can also pass module and class names as strings. ::

        with add_resource_context(app, module='myapp.articles.views',
                                  url_prefix='/api/') as route:
            route('/articles/', 'ArticleList')
            route('/articles/{pk}', 'ArticleDetail')

    .. note::
        If passing class names, the resource classes will be instantiated with no
        arguments. You can change this behavior by overriding ``make_resource``.

        .. code-block:: python

            # myapp/authors/views.py
            class AuthorList:
                def __init__(self, db):
                    self.db = db

                async def get(self, request):
                    # Fetch authors from self.db...

        .. code-block:: python

            # myapp/app.py
            from myapp.database import db

            with add_resource_context(app, module='myapp.authors.views',
                                    url_prefix='/api/',
                                    make_resource=lambda cls: cls(db=db)) as route:
                route('/authors/', 'AuthorList')

    :param app: Application to add routes to.
    :param resource: Import path to module (str) or module object
        which contains the resource classes.
    :param url_prefix: Prefix to prepend to all route paths.
    :param name_prefix: Prefix to prepend to all route names.
    :param make_resource: Function which receives a resource class and returns
        a resource instance.