本文整理汇总了Python中pyramid.request.Request.validated方法的典型用法代码示例。如果您正苦于以下问题:Python Request.validated方法的具体用法?Python Request.validated怎么用?Python Request.validated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.request.Request
的用法示例。
在下文中一共展示了Request.validated方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate_request_data
# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import validated [as 别名]
def validate_request_data(context: ILocation, request: Request, schema=MappingSchema(), extra_validators=[]):
""" 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.
The `None` value is allowed to disable schema validation.
:param extra_validators: Functions called after schema validation.
The passed arguments are `context` and `request`.
The should append errors to `request.errors` and
validated data to `request.validated`.
:raises HTTPBadRequest: HTTP 400 for bad request data.
"""
parent = context if request.method == "POST" else context.__parent__
workflow = _get_workflow(context, request)
schema_with_binding = schema.bind(
context=context, request=request, registry=request.registry, workflow=workflow, parent_pool=parent
)
body = {}
if request.content_type == "multipart/form-data":
body = unflatten_multipart_request(request)
if request.content_type == "application/json":
body = _extract_json_body(request)
validate_user_headers(request)
qs = _extract_querystring(request)
validate_body_or_querystring(body, qs, schema_with_binding, context, request)
_validate_extra_validators(extra_validators, context, request)
if request.errors:
request.validated = {}
raise HTTPBadRequest()
示例2: _validate_list_schema
# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import validated [as 别名]
def _validate_list_schema(schema: SequenceSchema, cstruct: list, request: Request, 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_to_request(err, request, location)