本文整理汇总了Python中aiohttp.web.HTTPOk方法的典型用法代码示例。如果您正苦于以下问题:Python web.HTTPOk方法的具体用法?Python web.HTTPOk怎么用?Python web.HTTPOk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aiohttp.web
的用法示例。
在下文中一共展示了web.HTTPOk方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _test_transport
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPOk [as 别名]
def _test_transport(make_route, make_request):
route = make_route()
request = make_request(
"GET", "/sm/", match_info={"transport": "xhr", "session": "s1", "server": "000"}
)
params = []
class Transport:
def __init__(self, manager, session, request):
params.append((manager, session, request))
def process(self):
return web.HTTPOk()
route = make_route(handlers={"test": (True, Transport)})
res = await route.handler(request)
assert isinstance(res, web.HTTPOk)
assert params[0] == (route.manager, route.manager["s1"], request)
示例2: liveness_probe
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPOk [as 别名]
def liveness_probe(self, request):
if self.bot.is_ready():
raise web.HTTPOk()
raise web.HTTPNotAcceptable()
示例3: test_raw_websocket
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPOk [as 别名]
def test_raw_websocket(make_route, make_request, mocker):
ws = mocker.patch("sockjs.route.RawWebSocketTransport")
loop = asyncio.get_event_loop()
ws.return_value.process.return_value = loop.create_future()
ws.return_value.process.return_value.set_result(web.HTTPOk())
route = make_route()
request = make_request("GET", "/sm/", headers=CIMultiDict({}))
res = await route.websocket(request)
assert isinstance(res, web.HTTPOk)
assert ws.called
assert ws.return_value.process.called
示例4: receive_hook
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPOk [as 别名]
def receive_hook(self, request):
topic = request.match_info["topic"]
payload = await request.json()
self.hook_results.append((topic, payload))
raise web.HTTPOk()
示例5: receive_message
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPOk [as 别名]
def receive_message(self, request):
payload = await request.json()
self.message_results.append(payload)
raise web.HTTPOk()
示例6: binary
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPOk [as 别名]
def binary(app, handler):
async def middleware_handler(request):
response = await handler(request)
if isinstance(response, (bytes, bytearray, memoryview)):
return web.HTTPOk(body=response)
elif isinstance(response, str):
return web.HTTPOk(text=response)
else:
return response
return middleware_handler
示例7: test_get
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPOk [as 别名]
def test_get(view, mocker, prefix):
m = mocker.Mock()
m.method = 'GET'
m.path = ''
m.match_info = {}
with pytest.raises(web.HTTPOk):
await view.factory(prefix=prefix)().get()
示例8: handler
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPOk [as 别名]
def handler(request):
return web.HTTPOk()
示例9: handler
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPOk [as 别名]
def handler(request):
"""
---
description: swagger operation
"""
raise web.HTTPOk()
示例10: get
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPOk [as 别名]
def get(self, request):
raise web.HTTPOk(text='simple handler get')
示例11: callback
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPOk [as 别名]
def callback(self, request: web.Request):
"""Route for handling HTTP callback"""
request_json = await request.json()
hash = request_json['hash']
self.logger.debug(f"callback received {hash}")
# cache
if not await RedisDB.instance().exists(f"callback:{hash}"):
await RedisDB.instance().set(f"callback:{hash}", "val", expires=300)
else:
return web.HTTPOk()
# De-serialize block
request_json['block'] = json.loads(request_json['block'])
# only consider sends
if 'is_send' in request_json and (request_json['is_send'] or request_json['is_send'] == 'true'):
if 'amount' in request_json:
# only consider self.min_amount or larger
converted_amount = Env.raw_to_amount(int(request_json['amount']))
if converted_amount >= self.min_amount:
# Figure out of this is one of our users
link = request_json['block']['link_as_account']
account = await Account.filter(address=link).prefetch_related('user').first()
if account is None:
return web.HTTPOk()
# See if this is an internal TX
transaction = await Transaction.filter(block_hash=hash).prefetch_related('receiving_user').first()
if transaction is not None and transaction.receiving_user is not None:
return web.HTTPOk()
self.logger.debug(f'Deposit received: {request_json["amount"]} for {account.user.id}')
amount_string = f"{Env.raw_to_amount(int(request_json['amount']))} {Env.currency_symbol()}"
discord_user = await self.bot.fetch_user(account.user.id)
if discord_user is not None:
await Messages.send_success_dm(discord_user, f"Your deposit of **{amount_string}** has been received. It will be in your available balance shortly!", header="Deposit Success", footer=f"I only notify you of deposits that are {self.min_amount} {Env.currency_symbol()} or greater.")
return web.HTTPOk()
示例12: response_file
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPOk [as 别名]
def response_file(url, mime_type, filename=None):
headers = {'X-Accel-Redirect': url}
if filename:
v = 'attachment; filename="{}"'.format(filename)
headers['Content-Disposition'] = v
raise web.HTTPOk(
content_type=mime_type,
headers=headers,
)
示例13: http200
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPOk [as 别名]
def http200(request):
raise web.HTTPOk(body=b'')