本文整理汇总了Python中aiohttp.web.HTTPBadRequest方法的典型用法代码示例。如果您正苦于以下问题:Python web.HTTPBadRequest方法的具体用法?Python web.HTTPBadRequest怎么用?Python web.HTTPBadRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aiohttp.web
的用法示例。
在下文中一共展示了web.HTTPBadRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_operation
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPBadRequest [as 别名]
def update_operation(self, op_id, state=None, autonomous=None, obfuscator=None):
async def validate(op):
try:
if not len(op):
raise web.HTTPNotFound
elif await op[0].is_finished():
raise web.HTTPBadRequest(body='This operation has already finished.')
elif state not in op[0].states.values():
raise web.HTTPBadRequest(body='state must be one of {}'.format(op[0].states.values()))
except Exception as e:
self.log.error(repr(e))
operation = await self.get_service('data_svc').locate('operations', match=dict(id=op_id))
if state:
await validate(operation)
operation[0].state = state
if state == operation[0].states['FINISHED']:
operation[0].finish = self.get_current_timestamp()
self.log.debug('Changing operation=%s state to %s' % (op_id, state))
if autonomous:
operation[0].autonomous = 0 if operation[0].autonomous else 1
self.log.debug('Toggled operation=%s autonomous to %s' % (op_id, bool(operation[0].autonomous)))
if obfuscator:
operation[0].obfuscator = obfuscator
self.log.debug('Updated operation=%s obfuscator to %s' % (op_id, operation[0].obfuscator))
示例2: rotate_public_did_keypair
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPBadRequest [as 别名]
def rotate_public_did_keypair(request: web.BaseRequest):
"""
Request handler for rotating key pair associated with public DID.
Args:
request: aiohttp request object
"""
context = request.app["request_context"]
ledger = await context.inject(BaseLedger, required=False)
if not ledger:
reason = "No ledger available"
if not context.settings.get_value("wallet.type"):
reason += ": missing wallet-type?"
raise web.HTTPForbidden(reason=reason)
async with ledger:
try:
await ledger.rotate_public_did_keypair() # do not take seed over the wire
except (WalletError, BadLedgerRequestError) as err:
raise web.HTTPBadRequest(reason=err.roll_up) from err
return web.json_response({})
示例3: test_publish_registry_x
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPBadRequest [as 别名]
def test_publish_registry_x(self):
REV_REG_ID = "{}:4:{}:3:CL:1234:default:CL_ACCUM:default".format(
self.test_did, self.test_did
)
request = async_mock.MagicMock()
request.app = self.app
request.match_info = {"rev_reg_id": REV_REG_ID}
with async_mock.patch.object(
test_module, "IndyRevocation", autospec=True
) as mock_indy_revoc:
mock_indy_revoc.return_value = async_mock.MagicMock(
get_issuer_rev_reg_record=async_mock.CoroutineMock(
return_value=async_mock.MagicMock(
publish_registry_definition=async_mock.CoroutineMock(
side_effect=test_module.RevocationError()
),
)
)
)
with self.assertRaises(test_module.web.HTTPBadRequest):
await test_module.publish_registry(request)
示例4: connections_retrieve
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPBadRequest [as 别名]
def connections_retrieve(request: web.BaseRequest):
"""
Request handler for fetching a single connection record.
Args:
request: aiohttp request object
Returns:
The connection record response
"""
context = request.app["request_context"]
connection_id = request.match_info["conn_id"]
try:
record = await ConnectionRecord.retrieve_by_id(context, connection_id)
result = record.serialize()
except StorageNotFoundError as err:
raise web.HTTPNotFound(reason=err.roll_up) from err
except BaseModelError as err:
raise web.HTTPBadRequest(reason=err.roll_up) from err
return web.json_response(result)
示例5: connections_establish_inbound
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPBadRequest [as 别名]
def connections_establish_inbound(request: web.BaseRequest):
"""
Request handler for setting the inbound connection on a connection record.
Args:
request: aiohttp request object
"""
context = request.app["request_context"]
connection_id = request.match_info["conn_id"]
outbound_handler = request.app["outbound_message_router"]
inbound_connection_id = request.match_info["ref_id"]
try:
connection = await ConnectionRecord.retrieve_by_id(context, connection_id)
connection_mgr = ConnectionManager(context)
await connection_mgr.establish_inbound(
connection, inbound_connection_id, outbound_handler
)
except StorageNotFoundError as err:
raise web.HTTPNotFound(reason=err.roll_up) from err
except (StorageError, WalletError, ConnectionManagerError) as err:
raise web.HTTPBadRequest(reason=err.roll_up) from err
return web.json_response({})
示例6: connections_remove
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPBadRequest [as 别名]
def connections_remove(request: web.BaseRequest):
"""
Request handler for removing a connection record.
Args:
request: aiohttp request object
"""
context = request.app["request_context"]
connection_id = request.match_info["conn_id"]
try:
connection = await ConnectionRecord.retrieve_by_id(context, connection_id)
await connection.delete_record(context)
except StorageNotFoundError as err:
raise web.HTTPNotFound(reason=err.roll_up) from err
except StorageError as err:
raise web.HTTPBadRequest(reason=err.roll_up) from err
return web.json_response({})
示例7: actionmenu_close
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPBadRequest [as 别名]
def actionmenu_close(request: web.BaseRequest):
"""
Request handler for closing the menu associated with a connection.
Args:
request: aiohttp request object
"""
context = request.app["request_context"]
connection_id = request.match_info["conn_id"]
menu = await retrieve_connection_menu(connection_id, context)
if not menu:
raise web.HTTPNotFound(
reason=f"No {MENU_RECORD_TYPE} record found for connection {connection_id}"
)
try:
await save_connection_menu(None, connection_id, context)
except StorageError as err:
raise web.HTTPBadRequest(reason=err.roll_up) from err
return web.json_response({})
示例8: credential_exchange_publish_revocations
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPBadRequest [as 别名]
def credential_exchange_publish_revocations(request: web.BaseRequest):
"""
Request handler for publishing pending revocations to the ledger.
Args:
request: aiohttp request object
Returns:
Credential revocation ids published as revoked by revocation registry id.
"""
context = request.app["request_context"]
body = await request.json()
rrid2crid = body.get("rrid2crid")
credential_manager = CredentialManager(context)
try:
results = await credential_manager.publish_pending_revocations(rrid2crid)
except (RevocationError, StorageError, IssuerError, LedgerError) as err:
raise web.HTTPBadRequest(reason=err.roll_up) from err
return web.json_response({"rrid2crid": results})
示例9: credential_exchange_remove
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPBadRequest [as 别名]
def credential_exchange_remove(request: web.BaseRequest):
"""
Request handler for removing a credential exchange record.
Args:
request: aiohttp request object
"""
context = request.app["request_context"]
outbound_handler = request.app["outbound_message_router"]
credential_exchange_id = request.match_info["cred_ex_id"]
cred_ex_record = None
try:
cred_ex_record = await V10CredentialExchange.retrieve_by_id(
context, credential_exchange_id
)
await cred_ex_record.delete_record(context)
except StorageNotFoundError as err:
await internal_error(err, web.HTTPNotFound, cred_ex_record, outbound_handler)
except StorageError as err:
await internal_error(err, web.HTTPBadRequest, cred_ex_record, outbound_handler)
return web.json_response({})
示例10: presentation_exchange_retrieve
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPBadRequest [as 别名]
def presentation_exchange_retrieve(request: web.BaseRequest):
"""
Request handler for fetching a single presentation exchange record.
Args:
request: aiohttp request object
Returns:
The presentation exchange record response
"""
context = request.app["request_context"]
presentation_exchange_id = request.match_info["pres_ex_id"]
try:
record = await V10PresentationExchange.retrieve_by_id(
context, presentation_exchange_id
)
result = record.serialize()
except StorageNotFoundError as err:
raise web.HTTPNotFound(reason=err.roll_up) from err
except (BaseModelError, StorageError) as err:
raise web.HTTPBadRequest(reason=err.roll_up) from err
return web.json_response(result)
示例11: presentation_exchange_remove
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPBadRequest [as 别名]
def presentation_exchange_remove(request: web.BaseRequest):
"""
Request handler for removing a presentation exchange record.
Args:
request: aiohttp request object
"""
context = request.app["request_context"]
presentation_exchange_id = request.match_info["pres_ex_id"]
try:
presentation_exchange_record = await V10PresentationExchange.retrieve_by_id(
context, presentation_exchange_id
)
await presentation_exchange_record.delete_record(context)
except StorageNotFoundError as err:
raise web.HTTPNotFound(reason=err.roll_up) from err
except StorageError as err:
raise web.HTTPBadRequest(reason=err.roll_up) from err
return web.json_response({})
示例12: wallet_create_did
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPBadRequest [as 别名]
def wallet_create_did(request: web.BaseRequest):
"""
Request handler for creating a new local DID in the wallet.
Args:
request: aiohttp request object
Returns:
The DID info
"""
context = request.app["request_context"]
wallet: BaseWallet = await context.inject(BaseWallet, required=False)
if not wallet:
raise web.HTTPForbidden(reason="No wallet available")
try:
info = await wallet.create_local_did()
except WalletError as err:
raise web.HTTPBadRequest(reason=err.roll_up) from err
return web.json_response({"result": format_did_info(info)})
示例13: wallet_get_public_did
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPBadRequest [as 别名]
def wallet_get_public_did(request: web.BaseRequest):
"""
Request handler for fetching the current public DID.
Args:
request: aiohttp request object
Returns:
The DID info
"""
context = request.app["request_context"]
wallet: BaseWallet = await context.inject(BaseWallet, required=False)
if not wallet:
raise web.HTTPForbidden(reason="No wallet available")
try:
info = await wallet.get_public_did()
except WalletError as err:
raise web.HTTPBadRequest(reason=err.roll_up) from err
return web.json_response({"result": format_did_info(info)})
示例14: body_to_dict
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPBadRequest [as 别名]
def body_to_dict(body, schema):
# type: (str, Dict) -> Dict
"""
:param body: The body content
:param schema: The expected JSONSchema
:return: A dictionary containing the parsed body
:raises SuspiciousOperation: If the body is not in JSON format, or does not
conform to the specified schema.
"""
try:
data = json.loads(body)
jsonschema.validate(data, schema=schema)
return data
except Exception as e:
# The SuspiciousOperation exception will result in an
# HttpResponseBadRequest response.
raise HTTPBadRequest()
示例15: check_token
# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import HTTPBadRequest [as 别名]
def check_token(self, request: web.Request) -> Optional['u.User']:
try:
token = request.headers["Authorization"]
token = token[len("Bearer "):]
except KeyError:
raise web.HTTPBadRequest(body='{"error": "Missing Authorization header"}',
headers=self._headers)
except IndexError:
raise web.HTTPBadRequest(body='{"error": "Malformed Authorization header"}',
headers=self._headers)
if self.shared_secret and token == self.shared_secret:
try:
user_id = request.query["user_id"]
except KeyError:
raise web.HTTPBadRequest(body='{"error": "Missing user_id query param"}',
headers=self._headers)
else:
user_id = self.verify_token(token)
if not user_id:
raise web.HTTPForbidden(body='{"error": "Invalid token"}', headers=self._headers)
user = u.User.get_by_mxid(user_id)
return user