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)
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()