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


Python web.Response方法代码示例

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


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

示例1: test_requests_error_code

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Response [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

示例2: test_requests_invalid_protocol

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Response [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

示例3: test_requests_cannot_connect_twice

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Response [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

示例4: test_requests_cannot_execute_if_not_connected

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Response [as 别名]
def test_requests_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("/")

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

        query = gql(query1_str)

        with pytest.raises(TransportClosed):
            sample_transport.execute(query)

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

示例5: test_aiohttp_error_code

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Response [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

示例6: test_aiohttp_invalid_protocol

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Response [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

示例7: test_aiohttp_subscribe_not_supported

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Response [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

示例8: test_aiohttp_cannot_connect_twice

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Response [as 别名]
def test_aiohttp_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("/")

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

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

        with pytest.raises(TransportAlreadyConnected):
            await session.transport.connect() 
开发者ID:graphql-python,项目名称:gql,代码行数:18,代码来源:test_aiohttp.py

示例9: test_aiohttp_cannot_execute_if_not_connected

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Response [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

示例10: set_config

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Response [as 别名]
def set_config(self, request):
        uid = await self.check_user(request)
        if uid is None:
            return web.Response(status=401)
        data = await request.json()
        mid, key, value = int(data["mid"]), data["key"], data["value"]
        mod = self.client_data[uid][0].modules[mid]
        if value:
            try:
                value = ast.literal_eval(value)
            except (ValueError, SyntaxError):
                pass
            self.client_data[uid][2].setdefault(mod.__module__, {}).setdefault("__config__", {})[key] = value
        else:
            try:
                del self.client_data[uid][2].setdefault(mod.__module__, {}).setdefault("__config__", {})[key]
            except KeyError:
                pass
        self.client_data[uid][0].send_config_one(mod, self.client_data[uid][2], skip_hook=True)
        self.client_data[uid][2].save()
        return web.Response() 
开发者ID:friendly-telegram,项目名称:friendly-telegram,代码行数:23,代码来源:config.py

示例11: messages

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Response [as 别名]
def messages(req: Request) -> Response:
    # Main bot message handler.
    if "application/json" in req.headers["Content-Type"]:
        body = await req.json()
    else:
        return Response(status=415)

    inbound_activity: Activity = Activity().deserialize(body)

    current_conversation_id = inbound_activity.conversation.id
    current_service_url = inbound_activity.service_url

    next_conversation_id = FACTORY.create_skill_conversation_id(current_conversation_id, current_service_url)

    await CLIENT.post_activity(CONFIG.APP_ID, CONFIG.SKILL_APP_ID, TO_URI, SERVICE_URL, next_conversation_id, inbound_activity)
    return Response(status=201) 
开发者ID:microsoft,项目名称:botbuilder-python,代码行数:18,代码来源:app.py

示例12: messages

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Response [as 别名]
def messages(req: Request) -> Response:
    # Main bot message handler.
    if "application/json" in req.headers["Content-Type"]:
        body = await req.json()
    else:
        return Response(status=415)

    activity = Activity().deserialize(body)
    auth_header = req.headers["Authorization"] if "Authorization" in req.headers else ""

    try:
        response = await ADAPTER.process_activity(activity, auth_header, BOT.on_turn)
        if response:
            return json_response(data=response.body, status=response.status)
        return Response(status=201)
    except Exception as exception:
        raise exception 
开发者ID:microsoft,项目名称:botbuilder-python,代码行数:19,代码来源:app.py

示例13: messages

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Response [as 别名]
def messages(req: Request) -> Response:
    # Main bot message handler.
    if "application/json" in req.headers["Content-Type"]:
        body = await req.json()
    else:
        return Response(status=415)

    activity = Activity().deserialize(body)
    auth_header = req.headers["Authorization"] if "Authorization" in req.headers else ""

    try:
        invoke_response = await ADAPTER.process_activity(activity, auth_header, BOT.on_turn)
        if invoke_response:
            return json_response(data=invoke_response.body, status=invoke_response.status)
        return Response(status=201)
    except PermissionError:
        return Response(status=401)
    except Exception:
        return Response(status=500) 
开发者ID:microsoft,项目名称:botbuilder-python,代码行数:21,代码来源:app.py

示例14: messages

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Response [as 别名]
def messages(req: Request) -> Response:
    # Main bot message handler.
    if "application/json" in req.headers["Content-Type"]:
        body = await req.json()
    else:
        return Response(status=415)

    activity = Activity().deserialize(body)
    auth_header = req.headers["Authorization"] if "Authorization" in req.headers else ""

    try:
        invoke_response = await ADAPTER.process_activity(
            activity, auth_header, BOT.on_turn
        )
        if invoke_response:
            return json_response(
                data=invoke_response.body, status=invoke_response.status
            )
        return Response(status=201)
    except PermissionError:
        return Response(status=401)
    except Exception:
        return Response(status=500) 
开发者ID:microsoft,项目名称:botbuilder-python,代码行数:25,代码来源:app.py

示例15: messages

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Response [as 别名]
def messages(req: Request) -> Response:
    # Create the Bot
    bot = AuthBot(CONVERSATION_STATE, USER_STATE, DIALOG)

    # Main bot message handler.
    if "application/json" in req.headers["Content-Type"]:
        body = await req.json()
    else:
        return Response(status=415)

    activity = Activity().deserialize(body)
    auth_header = req.headers["Authorization"] if "Authorization" in req.headers else ""

    try:
        await ADAPTER.process_activity(activity, auth_header, bot.on_turn)
        return Response(status=201)
    except Exception as exception:
        raise exception 
开发者ID:microsoft,项目名称:botbuilder-python,代码行数:20,代码来源:app.py


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