Beispiel #1
0
 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)
Beispiel #2
0
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)
Beispiel #3
0
 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)
Beispiel #4
0
def echo_nested(request):
    argmap = {
        "name": fields.Nested({
            "first": fields.Str(),
            "last": fields.Str()
        })
    }
    return json_response(parser.parse(argmap, request))
Beispiel #5
0
def echo_nested(request):
    argmap = {
        'name': fields.Nested({
            'first': fields.Str(),
            'last': fields.Str()
        })
    }
    return json_response(parser.parse(argmap, request))
Beispiel #6
0
def echo_nested_many(request):
    argmap = {
        'users':
        fields.Nested({
            'id': fields.Int(),
            'name': fields.Str()
        }, many=True)
    }
    return json_response(parser.parse(argmap, request))
Beispiel #7
0
def echo_nested_many(request):
    argmap = {
        "users":
        fields.Nested({
            "id": fields.Int(),
            "name": fields.Str()
        }, many=True)
    }
    return json_response(parser.parse(argmap, request))
Beispiel #8
0
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)
Beispiel #9
0
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)
Beispiel #10
0
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)
Beispiel #12
0
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})
Beispiel #13
0
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
Beispiel #15
0
def echo_multi_form(request):
    return json_response(parser.parse(hello_multiple, request, location="form"))
Beispiel #16
0
def echo_multi(request):
    return json_response(parser.parse(hello_multiple, request, location="query"))
Beispiel #17
0
def echo_headers(request):
    return json_response(
        parser.parse(hello_exclude_schema, request, location="headers"))
Beispiel #18
0
def echo_multi(request):
    return json_response(parser.parse(hello_multiple, request))
Beispiel #19
0
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)
Beispiel #20
0
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})
Beispiel #21
0
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)
Beispiel #22
0
def echo_many_schema(request):
    return json_response(parser.parse(hello_many_schema, request))
Beispiel #23
0
 def get(self, request):
     location_kwarg = {} if request.method == "POST" else {"location": "query"}
     return json_response(parser.parse(hello_args, self.request, **location_kwarg))
Beispiel #24
0
def echo_json(request):
    return json_response(parser.parse(hello_args, request))
Beispiel #25
0
def echo_query(request):
    return json_response(
        parser.parse(hello_args, request, locations=('query', )))
Beispiel #26
0
def echo(request):
    return json_response(parser.parse(hello_args, request, location="query"))
Beispiel #27
0
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)
Beispiel #28
0
def echo_json_or_form(request):
    return json_response(parser.parse(hello_args, request, location="json_or_form"))
Beispiel #29
0
def echo_headers(request):
    return json_response(
        parser.parse(hello_args, request, locations=('headers', )))
Beispiel #30
0
def echo_ignoring_extra_data(request):
    return json_response(parser.parse(hello_exclude_schema, request, unknown=None))