当前位置: 首页>>代码示例>>Python>>正文


Python web.Application方法代码示例

本文整理汇总了Python中aiohttp.web.Application方法的典型用法代码示例。如果您正苦于以下问题:Python web.Application方法的具体用法?Python web.Application怎么用?Python web.Application使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在aiohttp.web的用法示例。


在下文中一共展示了web.Application方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_requests_error_code_500

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Application [as 别名]
def test_requests_error_code_500(event_loop, aiohttp_server):
    async def handler(request):
        # Will generate http error code 500
        raise Exception("Server error")

    app = web.Application()
    app.router.add_route("POST", "/", handler)
    server = await aiohttp_server(app)

    url = server.make_url("/")

    def test_code():
        sample_transport = RequestsHTTPTransport(url=url)

        with Client(transport=sample_transport,) as session:

            query = gql(query1_str)

            with pytest.raises(TransportServerError):
                session.execute(query)

    await run_sync_test(event_loop, server, test_code) 
开发者ID:graphql-python,项目名称:gql,代码行数:24,代码来源:test_requests.py

示例2: test_requests_error_code

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Application [as 别名]
def test_requests_error_code(event_loop, aiohttp_server):
    async def handler(request):
        return web.Response(
            text=query1_server_error_answer, content_type="application/json"
        )

    app = web.Application()
    app.router.add_route("POST", "/", handler)
    server = await aiohttp_server(app)

    url = server.make_url("/")

    def test_code():
        sample_transport = RequestsHTTPTransport(url=url)

        with Client(transport=sample_transport,) as session:

            query = gql(query1_str)

            with pytest.raises(TransportQueryError):
                session.execute(query)

    await run_sync_test(event_loop, server, test_code) 
开发者ID:graphql-python,项目名称:gql,代码行数:25,代码来源:test_requests.py

示例3: test_requests_invalid_protocol

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Application [as 别名]
def test_requests_invalid_protocol(event_loop, aiohttp_server, response):
    async def handler(request):
        return web.Response(text=response, content_type="application/json")

    app = web.Application()
    app.router.add_route("POST", "/", handler)
    server = await aiohttp_server(app)

    url = server.make_url("/")

    def test_code():
        sample_transport = RequestsHTTPTransport(url=url)

        with Client(transport=sample_transport,) as session:

            query = gql(query1_str)

            with pytest.raises(TransportProtocolError):
                session.execute(query)

    await run_sync_test(event_loop, server, test_code) 
开发者ID:graphql-python,项目名称:gql,代码行数:23,代码来源:test_requests.py

示例4: test_requests_cannot_connect_twice

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Application [as 别名]
def test_requests_cannot_connect_twice(event_loop, aiohttp_server):
    async def handler(request):
        return web.Response(text=query1_server_answer, content_type="application/json")

    app = web.Application()
    app.router.add_route("POST", "/", handler)
    server = await aiohttp_server(app)

    url = server.make_url("/")

    def test_code():
        sample_transport = RequestsHTTPTransport(url=url)

        with Client(transport=sample_transport,) as session:

            with pytest.raises(TransportAlreadyConnected):
                session.transport.connect()

    await run_sync_test(event_loop, server, test_code) 
开发者ID:graphql-python,项目名称:gql,代码行数:21,代码来源:test_requests.py

示例5: test_aiohttp_query

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Application [as 别名]
def test_aiohttp_query(event_loop, aiohttp_server):
    async def handler(request):
        return web.Response(text=query1_server_answer, content_type="application/json")

    app = web.Application()
    app.router.add_route("POST", "/", handler)
    server = await aiohttp_server(app)

    url = server.make_url("/")

    sample_transport = AIOHTTPTransport(url=url, timeout=10)

    async with Client(transport=sample_transport,) as session:

        query = gql(query1_str)

        # Execute query asynchronously
        result = await session.execute(query)

        continents = result["continents"]

        africa = continents[0]

        assert africa["code"] == "AF" 
开发者ID:graphql-python,项目名称:gql,代码行数:26,代码来源:test_aiohttp.py

示例6: test_aiohttp_error_code_500

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Application [as 别名]
def test_aiohttp_error_code_500(event_loop, aiohttp_server):
    async def handler(request):
        # Will generate http error code 500
        raise Exception("Server error")

    app = web.Application()
    app.router.add_route("POST", "/", handler)
    server = await aiohttp_server(app)

    url = server.make_url("/")

    sample_transport = AIOHTTPTransport(url=url)

    async with Client(transport=sample_transport,) as session:

        query = gql(query1_str)

        with pytest.raises(TransportServerError):
            await session.execute(query) 
开发者ID:graphql-python,项目名称:gql,代码行数:21,代码来源:test_aiohttp.py

示例7: test_aiohttp_error_code

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Application [as 别名]
def test_aiohttp_error_code(event_loop, aiohttp_server):
    async def handler(request):
        return web.Response(
            text=query1_server_error_answer, content_type="application/json"
        )

    app = web.Application()
    app.router.add_route("POST", "/", handler)
    server = await aiohttp_server(app)

    url = server.make_url("/")

    sample_transport = AIOHTTPTransport(url=url)

    async with Client(transport=sample_transport,) as session:

        query = gql(query1_str)

        with pytest.raises(TransportQueryError):
            await session.execute(query) 
开发者ID:graphql-python,项目名称:gql,代码行数:22,代码来源:test_aiohttp.py

示例8: test_aiohttp_invalid_protocol

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Application [as 别名]
def test_aiohttp_invalid_protocol(event_loop, aiohttp_server, response):
    async def handler(request):
        return web.Response(text=response, content_type="application/json")

    app = web.Application()
    app.router.add_route("POST", "/", handler)
    server = await aiohttp_server(app)

    url = server.make_url("/")

    sample_transport = AIOHTTPTransport(url=url)

    async with Client(transport=sample_transport,) as session:

        query = gql(query1_str)

        with pytest.raises(TransportProtocolError):
            await session.execute(query) 
开发者ID:graphql-python,项目名称:gql,代码行数:20,代码来源:test_aiohttp.py

示例9: test_aiohttp_subscribe_not_supported

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Application [as 别名]
def test_aiohttp_subscribe_not_supported(event_loop, aiohttp_server):
    async def handler(request):
        return web.Response(text="does not matter", content_type="application/json")

    app = web.Application()
    app.router.add_route("POST", "/", handler)
    server = await aiohttp_server(app)

    url = server.make_url("/")

    sample_transport = AIOHTTPTransport(url=url)

    async with Client(transport=sample_transport,) as session:

        query = gql(query1_str)

        with pytest.raises(NotImplementedError):
            async for result in session.subscribe(query):
                pass 
开发者ID:graphql-python,项目名称:gql,代码行数:21,代码来源:test_aiohttp.py

示例10: test_aiohttp_cannot_execute_if_not_connected

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Application [as 别名]
def test_aiohttp_cannot_execute_if_not_connected(event_loop, aiohttp_server):
    async def handler(request):
        return web.Response(text=query1_server_answer, content_type="application/json")

    app = web.Application()
    app.router.add_route("POST", "/", handler)
    server = await aiohttp_server(app)

    url = server.make_url("/")

    sample_transport = AIOHTTPTransport(url=url, timeout=10)

    query = gql(query1_str)

    with pytest.raises(TransportClosed):
        await sample_transport.execute(query) 
开发者ID:graphql-python,项目名称:gql,代码行数:18,代码来源:test_aiohttp.py

示例11: create_app

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Application [as 别名]
def create_app(loop):
    """Create headnode aiohttp application

    :param loop: The asyncio loop to use for the application
    :rtype: aiohttp.web.Application
    """
    app = init()  

    # create a client Session here so that all client requests
    #   will share the same connection pool 
    app["loop"] = loop
    app["last_health_check"] = 0

    app.on_startup.append(start_background_tasks)

    return app 
开发者ID:HDFGroup,项目名称:hsds,代码行数:18,代码来源:headnode.py

示例12: handle_agent_error

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Application [as 别名]
def handle_agent_error(self, app: web.Application, agent_id: AgentId, event_name: str,
                                 message: str,
                                 traceback: str = None,
                                 user: Any = None,
                                 context_env: Any = None,
                                 severity: LogSeverity = None) -> None:
        if severity is None:
            severity = LogSeverity.ERROR
        async with self.dbpool.acquire() as conn, conn.begin():
            query = error_logs.insert().values({
                'severity': severity,
                'source': 'agent',
                'user': user,
                'message': message,
                'context_lang': 'python',
                'context_env': context_env,
                'traceback': traceback
            })
            await conn.execute(query)
        log.debug('Agent log collected: {}', message) 
开发者ID:lablup,项目名称:backend.ai-manager,代码行数:22,代码来源:error_monitor.py

示例13: config_server_ctx

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Application [as 别名]
def config_server_ctx(app: web.Application) -> AsyncIterator[None]:
    # populate public interfaces
    app['config_server'] = ConfigServer(
        app, app['config']['etcd']['addr'],
        app['config']['etcd']['user'], app['config']['etcd']['password'],
        app['config']['etcd']['namespace'])

    app['config'].update(
        await load_shared_config(app['config_server'].etcd)
    )
    app['config']['redis'] = redis_config_iv.check(
        await app['config_server'].etcd.get_prefix('config/redis')
    )
    _update_public_interface_objs(app)
    yield
    await app['config_server'].close() 
开发者ID:lablup,项目名称:backend.ai-manager,代码行数:18,代码来源:server.py

示例14: handle_loop_error

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Application [as 别名]
def handle_loop_error(
    root_app: web.Application,
    loop: asyncio.AbstractEventLoop,
    context: Mapping[str, Any],
) -> None:
    if isinstance(loop, aiojobs.Scheduler):
        loop = current_loop()
    exception = context.get('exception')
    msg = context.get('message', '(empty message)')
    if exception is not None:
        if sys.exc_info()[0] is not None:
            log.exception('Error inside event loop: {0}', msg)
            if 'error_monitor' in root_app:
                loop.create_task(root_app['error_monitor'].capture_exception())
        else:
            exc_info = (type(exception), exception, exception.__traceback__)
            log.error('Error inside event loop: {0}', msg, exc_info=exc_info)
            if 'error_monitor' in root_app:
                loop.create_task(root_app['error_monitor'].capture_exception(exception)) 
开发者ID:lablup,项目名称:backend.ai-manager,代码行数:21,代码来源:server.py

示例15: _init_subapp

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Application [as 别名]
def _init_subapp(pkg_name: str,
                 root_app: web.Application,
                 subapp: web.Application,
                 global_middlewares: Iterable[WebMiddleware]) -> None:
    subapp.on_response_prepare.append(on_prepare)

    async def _copy_public_interface_objs(subapp: web.Application):
        # Allow subapp's access to the root app properties.
        # These are the public APIs exposed to plugins as well.
        for key, obj in public_interface_objs.items():
            subapp[key] = obj

    # We must copy the public interface prior to all user-defined startup signal handlers.
    subapp.on_startup.insert(0, _copy_public_interface_objs)
    prefix = subapp.get('prefix', pkg_name.split('.')[-1].replace('_', '-'))
    aiojobs.aiohttp.setup(subapp, **root_app['scheduler_opts'])
    root_app.add_subapp('/' + prefix, subapp)
    root_app.middlewares.extend(global_middlewares) 
开发者ID:lablup,项目名称:backend.ai-manager,代码行数:20,代码来源:server.py


注:本文中的aiohttp.web.Application方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。