本文整理汇总了Python中pyramid.interfaces.IRequest.validated方法的典型用法代码示例。如果您正苦于以下问题:Python IRequest.validated方法的具体用法?Python IRequest.validated怎么用?Python IRequest.validated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.interfaces.IRequest
的用法示例。
在下文中一共展示了IRequest.validated方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _validate_list_schema
# 需要导入模块: from pyramid.interfaces import IRequest [as 别名]
# 或者: from pyramid.interfaces.IRequest import validated [as 别名]
def _validate_list_schema(schema: SequenceSchema, cstruct: list,
request: IRequest, location='body'):
if location != 'body': # for now we only support location == body
return
child_cstructs = schema.cstruct_children(cstruct)
try:
request.validated = schema.deserialize(child_cstructs)
except Invalid as err:
_add_colander_invalid_error(err, request, location)
示例2: _validate_request_data
# 需要导入模块: from pyramid.interfaces import IRequest [as 别名]
# 或者: from pyramid.interfaces.IRequest import validated [as 别名]
def _validate_request_data(context: IResource,
request: IRequest,
schema: colander.Schema):
"""Validate request data.
:param context: passed to validator functions
:param request: passed to validator functions
:param schema: Schema to validate. Data to validate is extracted from the
request.body. For schema nodes with attribute `location` ==
`querystring` the data is extracted from the query string.
The validated data (dict or list) is stored in the
`request.validated` attribute.
:raises HTTPBadRequest: HTTP 400 for bad request data.
"""
body = {}
if request.content_type == 'multipart/form-data':
body = unflatten_multipart_request(request)
if request.content_type == 'application/json':
body = _extract_json_body(request)
qs = _extract_querystring(request)
_validate_body_or_querystring(body, qs, schema, context, request)
if request.errors:
request.validated = {}
raise HTTPBadRequest()