import functools
import os
import shutil
import tempfile
from unittest import mock
from unittest.mock import MagicMock

import pytest

from aiohttp import abc, web
from aiohttp.web_urldispatcher import SystemRoute


@pytest.fixture(scope='function')
def tmp_dir_path(request):
    """
    Give a path for a temporary directory
    The directory is destroyed at the end of the test.
    """
    # Temporary directory.
    tmp_dir = tempfile.mkdtemp()

    def teardown():
        # Delete the whole directory:
        shutil.rmtree(tmp_dir)

    request.addfinalizer(teardown)
    return tmp_dir


@pytest.mark.parametrize(
    "show_index,status,prefix,data",
    [pytest.param(False, 403, '/', None, id="index_forbidden"),
     pytest.param(True, 200, '/',
                  b'<html>\n<head>\n<title>Index of /.</title>\n'
                  b'</head>\n<body>\n<h1>Index of /.</h1>\n<ul>\n'
                  b'<li><a href="/my_dir">my_dir/</a></li>\n'
                  b'<li><a href="/my_file">my_file</a></li>\n'
                  b'</ul>\n</body>\n</html>',
                  id="index_root"),
     pytest.param(True, 200, '/static',
                  b'<html>\n<head>\n<title>Index of /.</title>\n'
                  b'</head>\n<body>\n<h1>Index of /.</h1>\n<ul>\n'
                  b'<li><a href="/static/my_dir">my_dir/</a></li>\n'
                  b'<li><a href="/static/my_file">my_file</a></li>\n'
                  b'</ul>\n</body>\n</html>',
                  id="index_static")])
async def test_access_root_of_static_handler(tmp_dir_path, aiohttp_client,
                                             show_index, status, prefix, data):
    """
    Tests the operation of static file server.
    Try to access the root of static file server, and make
    sure that correct HTTP statuses are returned depending if we directory
    index should be shown or not.
    """
    # Put a file inside tmp_dir_path:
    my_file_path = os.path.join(tmp_dir_path, 'my_file')
    with open(my_file_path, 'w') as fw:
        fw.write('hello')

    my_dir_path = os.path.join(tmp_dir_path, 'my_dir')
    os.mkdir(my_dir_path)

    my_file_path = os.path.join(my_dir_path, 'my_file_in_dir')
    with open(my_file_path, 'w') as fw:
        fw.write('world')

    app = web.Application()

    # Register global static route:
    app.router.add_static(prefix, tmp_dir_path, show_index=show_index)
    client = await aiohttp_client(app)

    # Request the root of the static directory.
    r = await client.get(prefix)
    assert r.status == status

    if data:
        assert r.headers['Content-Type'] == "text/html; charset=utf-8"
        read_ = (await r.read())
        assert read_ == data


async def test_follow_symlink(tmp_dir_path, aiohttp_client):
    """
    Tests the access to a symlink, in static folder
    """
    data = 'hello world'

    my_dir_path = os.path.join(tmp_dir_path, 'my_dir')
    os.mkdir(my_dir_path)

    my_file_path = os.path.join(my_dir_path, 'my_file_in_dir')
    with open(my_file_path, 'w') as fw:
        fw.write(data)

    my_symlink_path = os.path.join(tmp_dir_path, 'my_symlink')
    os.symlink(my_dir_path, my_symlink_path)

    app = web.Application()

    # Register global static route:
    app.router.add_static('/', tmp_dir_path, follow_symlinks=True)
    client = await aiohttp_client(app)

    # Request the root of the static directory.
    r = await client.get('/my_symlink/my_file_in_dir')
    assert r.status == 200
    assert (await r.text()) == data


@pytest.mark.parametrize('dir_name,filename,data', [
    ('', 'test file.txt', 'test text'),
    ('test dir name', 'test dir file .txt', 'test text file folder')
])
async def test_access_to_the_file_with_spaces(tmp_dir_path, aiohttp_client,
                                              dir_name, filename, data):
    """
    Checks operation of static files with spaces
    """

    my_dir_path = os.path.join(tmp_dir_path, dir_name)

    if dir_name:
        os.mkdir(my_dir_path)

    my_file_path = os.path.join(my_dir_path, filename)

    with open(my_file_path, 'w') as fw:
        fw.write(data)

    app = web.Application()

    url = os.path.join('/', dir_name, filename)

    app.router.add_static('/', tmp_dir_path)
    client = await aiohttp_client(app)

    r = await client.get(url)
    assert r.status == 200
    assert (await r.text()) == data


async def test_access_non_existing_resource(tmp_dir_path, aiohttp_client):
    """
    Tests accessing non-existing resource
    Try to access a non-exiting resource and make sure that 404 HTTP status
    returned.
    """
    app = web.Application()

    # Register global static route:
    app.router.add_static('/', tmp_dir_path, show_index=True)
    client = await aiohttp_client(app)

    # Request the root of the static directory.
    r = await client.get('/non_existing_resource')
    assert r.status == 404


@pytest.mark.parametrize('registered_path,request_url', [
    ('/a:b', '/a:b'),
    ('/a@b', '/a@b'),
    ('/a:b', '/a%3Ab'),
])
async def test_url_escaping(aiohttp_client, registered_path, request_url):
    """
    Tests accessing a resource with
    """
    app = web.Application()

    async def handler(request):
        return web.Response()
    app.router.add_get(registered_path, handler)
    client = await aiohttp_client(app)

    r = await client.get(request_url)
    assert r.status == 200


async def test_handler_metadata_persistence():
    """
    Tests accessing metadata of a handler after registering it on the app
    router.
    """
    app = web.Application()

    async def async_handler(request):
        """Doc"""
        return web.Response()

    def sync_handler(request):
        """Doc"""
        return web.Response()

    app.router.add_get('/async', async_handler)
    with pytest.warns(DeprecationWarning):
        app.router.add_get('/sync', sync_handler)

    for resource in app.router.resources():
        for route in resource:
            assert route.handler.__doc__ == 'Doc'


async def test_unauthorized_folder_access(tmp_dir_path, aiohttp_client):
    """
    Tests the unauthorized access to a folder of static file server.
    Try to list a folder content of static file server when server does not
    have permissions to do so for the folder.
    """
    my_dir_path = os.path.join(tmp_dir_path, 'my_dir')
    os.mkdir(my_dir_path)

    app = web.Application()

    with mock.patch('pathlib.Path.__new__') as path_constructor:
        path = MagicMock()
        path.joinpath.return_value = path
        path.resolve.return_value = path
        path.iterdir.return_value.__iter__.side_effect = PermissionError()
        path_constructor.return_value = path

        # Register global static route:
        app.router.add_static('/', tmp_dir_path, show_index=True)
        client = await aiohttp_client(app)

        # Request the root of the static directory.
        r = await client.get('/my_dir')
        assert r.status == 403


async def test_access_symlink_loop(tmp_dir_path, aiohttp_client):
    """
    Tests the access to a looped symlink, which could not be resolved.
    """
    my_dir_path = os.path.join(tmp_dir_path, 'my_symlink')
    os.symlink(my_dir_path, my_dir_path)

    app = web.Application()

    # Register global static route:
    app.router.add_static('/', tmp_dir_path, show_index=True)
    client = await aiohttp_client(app)

    # Request the root of the static directory.
    r = await client.get('/my_symlink')
    assert r.status == 404


async def test_access_special_resource(tmp_dir_path, aiohttp_client):
    """
    Tests the access to a resource that is neither a file nor a directory.
    Checks that if a special resource is accessed (f.e. named pipe or UNIX
    domain socket) then 404 HTTP status returned.
    """
    app = web.Application()

    with mock.patch('pathlib.Path.__new__') as path_constructor:
        special = MagicMock()
        special.is_dir.return_value = False
        special.is_file.return_value = False

        path = MagicMock()
        path.joinpath.side_effect = lambda p: (special if p == 'special'
                                               else path)
        path.resolve.return_value = path
        special.resolve.return_value = special

        path_constructor.return_value = path

        # Register global static route:
        app.router.add_static('/', tmp_dir_path, show_index=True)
        client = await aiohttp_client(app)

        # Request the root of the static directory.
        r = await client.get('/special')
        assert r.status == 404


async def test_partialy_applied_handler(aiohttp_client):
    app = web.Application()

    async def handler(data, request):
        return web.Response(body=data)

    with pytest.warns(DeprecationWarning):
        app.router.add_route('GET', '/', functools.partial(handler, b'hello'))
    client = await aiohttp_client(app)

    r = await client.get('/')
    data = (await r.read())
    assert data == b'hello'


def test_system_route():
    route = SystemRoute(web.HTTPCreated(reason='test'))
    with pytest.raises(RuntimeError):
        route.url_for()
    assert route.name is None
    assert route.resource is None
    assert "<SystemRoute 201: test>" == repr(route)
    assert 201 == route.status
    assert 'test' == route.reason


async def test_412_is_returned(aiohttp_client):

    class MyRouter(abc.AbstractRouter):

        async def resolve(self, request):
            raise web.HTTPPreconditionFailed()

    app = web.Application(router=MyRouter())

    client = await aiohttp_client(app)

    resp = await client.get('/')

    assert resp.status == 412


async def test_allow_head(aiohttp_client):
    """
    Test allow_head on routes.
    """
    app = web.Application()

    async def handler(_):
        return web.Response()
    app.router.add_get('/a', handler, name='a')
    app.router.add_get('/b', handler, allow_head=False, name='b')
    client = await aiohttp_client(app)

    r = await client.get('/a')
    assert r.status == 200
    await r.release()

    r = await client.head('/a')
    assert r.status == 200
    await r.release()

    r = await client.get('/b')
    assert r.status == 200
    await r.release()

    r = await client.head('/b')
    assert r.status == 405
    await r.release()


@pytest.mark.parametrize("path", [
    '/a',
    '/{a}',
])
def test_reuse_last_added_resource(path):
    """
    Test that adding a route with the same name and path of the last added
    resource doesn't create a new resource.
    """
    app = web.Application()

    async def handler(request):
        return web.Response()

    app.router.add_get(path, handler, name="a")
    app.router.add_post(path, handler, name="a")

    assert len(app.router.resources()) == 1


def test_resource_raw_match():
    app = web.Application()

    async def handler(request):
        return web.Response()

    route = app.router.add_get("/a", handler, name="a")
    assert route.resource.raw_match("/a")

    route = app.router.add_get("/{b}", handler, name="b")
    assert route.resource.raw_match("/{b}")

    resource = app.router.add_static("/static", ".")
    assert not resource.raw_match("/static")


async def test_add_view(aiohttp_client):
    app = web.Application()

    class MyView(web.View):
        async def get(self):
            return web.Response()

        async def post(self):
            return web.Response()

    app.router.add_view("/a", MyView)

    client = await aiohttp_client(app)

    r = await client.get("/a")
    assert r.status == 200
    await r.release()

    r = await client.post("/a")
    assert r.status == 200
    await r.release()

    r = await client.put("/a")
    assert r.status == 405
    await r.release()


async def test_decorate_view(aiohttp_client):
    routes = web.RouteTableDef()

    @routes.view("/a")
    class MyView(web.View):
        async def get(self):
            return web.Response()

        async def post(self):
            return web.Response()

    app = web.Application()
    app.router.add_routes(routes)

    client = await aiohttp_client(app)

    r = await client.get("/a")
    assert r.status == 200
    await r.release()

    r = await client.post("/a")
    assert r.status == 200
    await r.release()

    r = await client.put("/a")
    assert r.status == 405
    await r.release()


async def test_web_view(aiohttp_client):
    app = web.Application()

    class MyView(web.View):
        async def get(self):
            return web.Response()

        async def post(self):
            return web.Response()

    app.router.add_routes([
        web.view("/a", MyView)
    ])

    client = await aiohttp_client(app)

    r = await client.get("/a")
    assert r.status == 200
    await r.release()

    r = await client.post("/a")
    assert r.status == 200
    await r.release()

    r = await client.put("/a")
    assert r.status == 405
    await r.release()

[((14, 1, 14, 33), 'pytest.fixture', 'pytest.fixture', (), '', False, 'import pytest\n'), ((112, 1, 115, 2), 'pytest.mark.parametrize', 'pytest.mark.parametrize', ({(112, 25, 112, 49): '"""dir_name,filename,data"""', (112, 51, 115, 1): "[('', 'test file.txt', 'test text'), ('test dir name', 'test dir file .txt',\n    'test text file folder')]"}, {}), "('dir_name,filename,data', [('', 'test file.txt',\n    'test text'), ('test dir name', 'test dir file .txt',\n    'test text file folder')])", False, 'import pytest\n'), ((161, 1, 165, 2), 'pytest.mark.parametrize', 'pytest.mark.parametrize', ({(161, 25, 161, 54): '"""registered_path,request_url"""', (161, 56, 165, 1): "[('/a:b', '/a:b'), ('/a@b', '/a@b'), ('/a:b', '/a%3Ab')]"}, {}), "('registered_path,request_url', [('/a:b', '/a:b'), (\n    '/a@b', '/a@b'), ('/a:b', '/a%3Ab')])", False, 'import pytest\n'), ((351, 1, 354, 2), 'pytest.mark.parametrize', 'pytest.mark.parametrize', ({(351, 25, 351, 31): '"""path"""', (351, 33, 354, 1): "['/a', '/{a}']"}, {}), "('path', ['/a', '/{a}'])", False, 'import pytest\n'), ((21, 14, 21, 32), 'tempfile.mkdtemp', 'tempfile.mkdtemp', ({}, {}), '()', False, 'import tempfile\n'), ((57, 19, 57, 56), 'os.path.join', 'os.path.join', ({(57, 32, 57, 44): 'tmp_dir_path', (57, 46, 57, 55): '"""my_file"""'}, {}), "(tmp_dir_path, 'my_file')", False, 'import os\n'), ((61, 18, 61, 54), 'os.path.join', 'os.path.join', ({(61, 31, 61, 43): 'tmp_dir_path', (61, 45, 61, 53): '"""my_dir"""'}, {}), "(tmp_dir_path, 'my_dir')", False, 'import os\n'), ((62, 4, 62, 25), 'os.mkdir', 'os.mkdir', ({(62, 13, 62, 24): 'my_dir_path'}, {}), '(my_dir_path)', False, 'import os\n'), ((64, 19, 64, 62), 'os.path.join', 'os.path.join', ({(64, 32, 64, 43): 'my_dir_path', (64, 45, 64, 61): '"""my_file_in_dir"""'}, {}), "(my_dir_path, 'my_file_in_dir')", False, 'import os\n'), ((68, 10, 68, 27), 'aiohttp.web.Application', 'web.Application', ({}, {}), '()', False, 'from aiohttp import abc, web\n'), ((90, 18, 90, 54), 'os.path.join', 'os.path.join', ({(90, 31, 90, 43): 'tmp_dir_path', (90, 45, 90, 53): '"""my_dir"""'}, {}), "(tmp_dir_path, 'my_dir')", False, 'import os\n'), ((91, 4, 91, 25), 'os.mkdir', 'os.mkdir', ({(91, 13, 91, 24): 'my_dir_path'}, {}), '(my_dir_path)', False, 'import os\n'), ((93, 19, 93, 62), 'os.path.join', 'os.path.join', ({(93, 32, 93, 43): 'my_dir_path', (93, 45, 93, 61): '"""my_file_in_dir"""'}, {}), "(my_dir_path, 'my_file_in_dir')", False, 'import os\n'), ((97, 22, 97, 62), 'os.path.join', 'os.path.join', ({(97, 35, 97, 47): 'tmp_dir_path', (97, 49, 97, 61): '"""my_symlink"""'}, {}), "(tmp_dir_path, 'my_symlink')", False, 'import os\n'), ((98, 4, 98, 44), 'os.symlink', 'os.symlink', ({(98, 15, 98, 26): 'my_dir_path', (98, 28, 98, 43): 'my_symlink_path'}, {}), '(my_dir_path, my_symlink_path)', False, 'import os\n'), ((100, 10, 100, 27), 'aiohttp.web.Application', 'web.Application', ({}, {}), '()', False, 'from aiohttp import abc, web\n'), ((122, 18, 122, 54), 'os.path.join', 'os.path.join', ({(122, 31, 122, 43): 'tmp_dir_path', (122, 45, 122, 53): 'dir_name'}, {}), '(tmp_dir_path, dir_name)', False, 'import os\n'), ((127, 19, 127, 54), 'os.path.join', 'os.path.join', ({(127, 32, 127, 43): 'my_dir_path', (127, 45, 127, 53): 'filename'}, {}), '(my_dir_path, filename)', False, 'import os\n'), ((132, 10, 132, 27), 'aiohttp.web.Application', 'web.Application', ({}, {}), '()', False, 'from aiohttp import abc, web\n'), ((134, 10, 134, 47), 'os.path.join', 'os.path.join', ({(134, 23, 134, 26): '"""/"""', (134, 28, 134, 36): 'dir_name', (134, 38, 134, 46): 'filename'}, {}), "('/', dir_name, filename)", False, 'import os\n'), ((150, 10, 150, 27), 'aiohttp.web.Application', 'web.Application', ({}, {}), '()', False, 'from aiohttp import abc, web\n'), ((170, 10, 170, 27), 'aiohttp.web.Application', 'web.Application', ({}, {}), '()', False, 'from aiohttp import abc, web\n'), ((186, 10, 186, 27), 'aiohttp.web.Application', 'web.Application', ({}, {}), '()', False, 'from aiohttp import abc, web\n'), ((211, 18, 211, 54), 'os.path.join', 'os.path.join', ({(211, 31, 211, 43): 'tmp_dir_path', (211, 45, 211, 53): '"""my_dir"""'}, {}), "(tmp_dir_path, 'my_dir')", False, 'import os\n'), ((212, 4, 212, 25), 'os.mkdir', 'os.mkdir', ({(212, 13, 212, 24): 'my_dir_path'}, {}), '(my_dir_path)', False, 'import os\n'), ((214, 10, 214, 27), 'aiohttp.web.Application', 'web.Application', ({}, {}), '()', False, 'from aiohttp import abc, web\n'), ((236, 18, 236, 58), 'os.path.join', 'os.path.join', ({(236, 31, 236, 43): 'tmp_dir_path', (236, 45, 236, 57): '"""my_symlink"""'}, {}), "(tmp_dir_path, 'my_symlink')", False, 'import os\n'), ((237, 4, 237, 40), 'os.symlink', 'os.symlink', ({(237, 15, 237, 26): 'my_dir_path', (237, 28, 237, 39): 'my_dir_path'}, {}), '(my_dir_path, my_dir_path)', False, 'import os\n'), ((239, 10, 239, 27), 'aiohttp.web.Application', 'web.Application', ({}, {}), '()', False, 'from aiohttp import abc, web\n'), ((256, 10, 256, 27), 'aiohttp.web.Application', 'web.Application', ({}, {}), '()', False, 'from aiohttp import abc, web\n'), ((281, 10, 281, 27), 'aiohttp.web.Application', 'web.Application', ({}, {}), '()', False, 'from aiohttp import abc, web\n'), ((326, 10, 326, 27), 'aiohttp.web.Application', 'web.Application', ({}, {}), '()', False, 'from aiohttp import abc, web\n'), ((360, 10, 360, 27), 'aiohttp.web.Application', 'web.Application', ({}, {}), '()', False, 'from aiohttp import abc, web\n'), ((372, 10, 372, 27), 'aiohttp.web.Application', 'web.Application', ({}, {}), '()', False, 'from aiohttp import abc, web\n'), ((388, 10, 388, 27), 'aiohttp.web.Application', 'web.Application', ({}, {}), '()', False, 'from aiohttp import abc, web\n'), ((415, 13, 415, 32), 'aiohttp.web.RouteTableDef', 'web.RouteTableDef', ({}, {}), '()', False, 'from aiohttp import abc, web\n'), ((425, 10, 425, 27), 'aiohttp.web.Application', 'web.Application', ({}, {}), '()', False, 'from aiohttp import abc, web\n'), ((444, 10, 444, 27), 'aiohttp.web.Application', 'web.Application', ({}, {}), '()', False, 'from aiohttp import abc, web\n'), ((25, 8, 25, 30), 'shutil.rmtree', 'shutil.rmtree', ({(25, 22, 25, 29): 'tmp_dir'}, {}), '(tmp_dir)', False, 'import shutil\n'), ((33, 5, 33, 62), 'pytest.param', 'pytest.param', (), '', False, 'import pytest\n'), ((34, 5, 40, 34), 'pytest.param', 'pytest.param', (), '', False, 'import pytest\n'), ((41, 5, 47, 36), 'pytest.param', 'pytest.param', (), '', False, 'import pytest\n'), ((125, 8, 125, 29), 'os.mkdir', 'os.mkdir', ({(125, 17, 125, 28): 'my_dir_path'}, {}), '(my_dir_path)', False, 'import os\n'), ((173, 15, 173, 29), 'aiohttp.web.Response', 'web.Response', ({}, {}), '()', False, 'from aiohttp import abc, web\n'), ((190, 15, 190, 29), 'aiohttp.web.Response', 'web.Response', ({}, {}), '()', False, 'from aiohttp import abc, web\n'), ((194, 15, 194, 29), 'aiohttp.web.Response', 'web.Response', ({}, {}), '()', False, 'from aiohttp import abc, web\n'), ((197, 9, 197, 41), 'pytest.warns', 'pytest.warns', ({(197, 22, 197, 40): 'DeprecationWarning'}, {}), '(DeprecationWarning)', False, 'import pytest\n'), ((216, 9, 216, 43), 'unittest.mock.patch', 'mock.patch', ({(216, 20, 216, 42): '"""pathlib.Path.__new__"""'}, {}), "('pathlib.Path.__new__')", False, 'from unittest import mock\n'), ((217, 15, 217, 26), 'unittest.mock.MagicMock', 'MagicMock', ({}, {}), '()', False, 'from unittest.mock import MagicMock\n'), ((258, 9, 258, 43), 'unittest.mock.patch', 'mock.patch', ({(258, 20, 258, 42): '"""pathlib.Path.__new__"""'}, {}), "('pathlib.Path.__new__')", False, 'from unittest import mock\n'), ((259, 18, 259, 29), 'unittest.mock.MagicMock', 'MagicMock', ({}, {}), '()', False, 'from unittest.mock import MagicMock\n'), ((263, 15, 263, 26), 'unittest.mock.MagicMock', 'MagicMock', ({}, {}), '()', False, 'from unittest.mock import MagicMock\n'), ((284, 15, 284, 38), 'aiohttp.web.Response', 'web.Response', (), '', False, 'from aiohttp import abc, web\n'), ((286, 9, 286, 41), 'pytest.warns', 'pytest.warns', ({(286, 22, 286, 40): 'DeprecationWarning'}, {}), '(DeprecationWarning)', False, 'import pytest\n'), ((296, 24, 296, 54), 'aiohttp.web.HTTPCreated', 'web.HTTPCreated', (), '', False, 'from aiohttp import abc, web\n'), ((297, 9, 297, 36), 'pytest.raises', 'pytest.raises', ({(297, 23, 297, 35): 'RuntimeError'}, {}), '(RuntimeError)', False, 'import pytest\n'), ((329, 15, 329, 29), 'aiohttp.web.Response', 'web.Response', ({}, {}), '()', False, 'from aiohttp import abc, web\n'), ((363, 15, 363, 29), 'aiohttp.web.Response', 'web.Response', ({}, {}), '()', False, 'from aiohttp import abc, web\n'), ((375, 15, 375, 29), 'aiohttp.web.Response', 'web.Response', ({}, {}), '()', False, 'from aiohttp import abc, web\n'), ((287, 41, 287, 77), 'functools.partial', 'functools.partial', ({(287, 59, 287, 66): 'handler', (287, 68, 287, 76): "b'hello'"}, {}), "(handler, b'hello')", False, 'import functools\n'), ((311, 18, 311, 46), 'aiohttp.web.HTTPPreconditionFailed', 'web.HTTPPreconditionFailed', ({}, {}), '()', False, 'from aiohttp import abc, web\n'), ((392, 19, 392, 33), 'aiohttp.web.Response', 'web.Response', ({}, {}), '()', False, 'from aiohttp import abc, web\n'), ((395, 19, 395, 33), 'aiohttp.web.Response', 'web.Response', ({}, {}), '()', False, 'from aiohttp import abc, web\n'), ((420, 19, 420, 33), 'aiohttp.web.Response', 'web.Response', ({}, {}), '()', False, 'from aiohttp import abc, web\n'), ((423, 19, 423, 33), 'aiohttp.web.Response', 'web.Response', ({}, {}), '()', False, 'from aiohttp import abc, web\n'), ((448, 19, 448, 33), 'aiohttp.web.Response', 'web.Response', ({}, {}), '()', False, 'from aiohttp import abc, web\n'), ((451, 19, 451, 33), 'aiohttp.web.Response', 'web.Response', ({}, {}), '()', False, 'from aiohttp import abc, web\n'), ((454, 8, 454, 30), 'aiohttp.web.view', 'web.view', ({(454, 17, 454, 21): '"""/a"""', (454, 23, 454, 29): 'MyView'}, {}), "('/a', MyView)", False, 'from aiohttp import abc, web\n')]