本文整理汇总了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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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
示例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()
示例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)
示例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()
示例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)
示例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
示例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)
示例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)
示例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