def wrapper(request, *args, **kwargs): try: user_args = parser.parse(search_args, request) except ValidationError as err: return user_error(err.messages) return view(request, *args, search_args=SearchArgs(**user_args), **kwargs)
def echo_many_schema(request): try: return json_response( parser.parse(hello_many_schema, request, locations=("json", ))) except ma.ValidationError as err: return json_response(err.messages, status=parser.DEFAULT_VALIDATION_STATUS)
def get(self, request): try: args = parser.parse(hello_args, self.request) except ma.ValidationError as err: return json_response(err.messages, status=parser.DEFAULT_VALIDATION_STATUS) return json_response(args)
def echo_nested(request): argmap = { "name": fields.Nested({ "first": fields.Str(), "last": fields.Str() }) } return json_response(parser.parse(argmap, request))
def echo_nested(request): argmap = { 'name': fields.Nested({ 'first': fields.Str(), 'last': fields.Str() }) } return json_response(parser.parse(argmap, request))
def echo_nested_many(request): argmap = { 'users': fields.Nested({ 'id': fields.Int(), 'name': fields.Str() }, many=True) } return json_response(parser.parse(argmap, request))
def echo_nested_many(request): argmap = { "users": fields.Nested({ "id": fields.Int(), "name": fields.Str() }, many=True) } return json_response(parser.parse(argmap, request))
def error400(request): def always_fail(value): raise ValidationError('something went wrong', status_code=400) argmap = {'text': fields.Str(validate=always_fail)} try: return parser.parse(argmap, request) except ValidationError as err: return json_response(err.messages, status=err.status_code)
def echo(request): try: args = parser.parse(hello_args, request) except ma.ValidationError as err: return json_response(err.messages, status=parser.DEFAULT_VALIDATION_STATUS) except json.JSONDecodeError: return json_response({"json": ["Invalid JSON body."]}, status=400) return json_response(args)
def always_error(request): def always_fail(value): raise ma.ValidationError("something went wrong") argmap = {"text": fields.Str(validate=always_fail)} try: return parser.parse(argmap, request) except ma.ValidationError as err: return json_response(err.messages, status=parser.DEFAULT_VALIDATION_STATUS)
def wrapper(request, *args, **kwargs): try: user_args = parser.parse(search_args, request, location="querystring") except ValidationError as err: logger.info("in val error") return user_error(err.messages) return view(request, *args, search_args=SearchArgs(**user_args), **kwargs)
def echo_file(request): args = {'myfile': fields.Field()} result = parser.parse(args, request, locations=('files', )) myfile = result['myfile'] content = myfile.read().decode('utf8') return json_response({'myfile': content})
def echo_cookie(request): return json_response( parser.parse(hello_args, request, locations=('cookies', )))
def parsing(request, validator): try: args = parser.parse(validator, request) except ValidationError as err: raise ValueError(err.message) return args
def echo_multi_form(request): return json_response(parser.parse(hello_multiple, request, location="form"))
def echo_multi(request): return json_response(parser.parse(hello_multiple, request, location="query"))
def echo_headers(request): return json_response( parser.parse(hello_exclude_schema, request, location="headers"))
def echo_multi(request): return json_response(parser.parse(hello_multiple, request))
def echo(request): try: args = parser.parse(hello_args, request) except ValidationError as err: return json_response(err.messages, status=err.status_code) return json_response(args)
def echo_file(request): args = {"myfile": fields.Field()} result = parser.parse(args, request, location="files") myfile = result["myfile"] content = myfile.read().decode("utf8") return json_response({"myfile": content})
def always_error(request): def always_fail(value): raise ma.ValidationError("something went wrong") argmap = {"text": fields.Str(validate=always_fail)} return parser.parse(argmap, request)
def echo_many_schema(request): return json_response(parser.parse(hello_many_schema, request))
def get(self, request): location_kwarg = {} if request.method == "POST" else {"location": "query"} return json_response(parser.parse(hello_args, self.request, **location_kwarg))
def echo_json(request): return json_response(parser.parse(hello_args, request))
def echo_query(request): return json_response( parser.parse(hello_args, request, locations=('query', )))
def echo(request): return json_response(parser.parse(hello_args, request, location="query"))
def echo_many_schema(request): try: return json_response( parser.parse(hello_many_schema, request, locations=('json', ))) except ValidationError as err: return json_response(err.messages, status=err.status_code)
def echo_json_or_form(request): return json_response(parser.parse(hello_args, request, location="json_or_form"))
def echo_headers(request): return json_response( parser.parse(hello_args, request, locations=('headers', )))
def echo_ignoring_extra_data(request): return json_response(parser.parse(hello_exclude_schema, request, unknown=None))