Beispiel #1
0
def call_service(func, api_kwargs, context, request):

    wrap_request(request)

    # Checking that the accept headers sent by the client
    # match what can be handled by the function, if specified.
    #
    # If not, returns a HTTP 406 NOT ACCEPTABLE with the list of available
    # choices

    if 'accept' in request.headers and 'accept' in api_kwargs:
        accept = api_kwargs.get('accept')

        if callable(accept):
            acceptable = accept(request)
        else:
            acceptable = accept

        acceptable = to_list(acceptable)

        # does it comply with the headers sent by the client?
        best_match = request.accept.best_match(acceptable)
        if best_match:
            return func(request)
        else:
            # if not, return the list of accepted headers
            resp = request.response
            resp.status = 406
            resp.content_type = "application/json"
            resp.body = json.dumps(acceptable)
            return resp

    for validator in to_list(api_kwargs.get('validator', [])):
        validator(request)
        if len(request.errors) > 0:
            return json_error(request.errors)

    return func(request)
Beispiel #2
0
def call_service(func, api_kwargs, context, request):

    wrap_request(request)

    # Checking that the accept headers sent by the client
    # match what can be handled by the function, if specified.
    #
    # If not, returns a HTTP 406 NOT ACCEPTABLE with the list of available
    # choices

    if 'accept' in request.headers and 'accept' in api_kwargs:
        accept = api_kwargs.get('accept')

        if callable(accept):
            acceptable = accept(request)
        else:
            acceptable = accept

        acceptable = to_list(acceptable)

        # does it comply with the headers sent by the client?
        best_match = request.accept.best_match(acceptable)
        if best_match:
            return func(request)
        else:
            # if not, return the list of accepted headers
            resp = request.response
            resp.status = 406
            resp.content_type = "application/json"
            resp.body = json.dumps(acceptable)
            return resp

    for validator in to_list(api_kwargs.get('validator', [])):
        validator(request)
        if len(request.errors) > 0:
            return json_error(request.errors)

    return func(request)
Beispiel #3
0
 def __apply(request):
     wrap_request(request)
     return func(request)