Example #1
0
def describe_service(request,
                     app,
                     version,
                     service_name,
                     extension='html',
                     service_type='function'):
    """
    Gets a function descriptor.
    """
    check_extension(extension)

    try:
        if service_type == 'resource':
            return render_to_response(
                'sharrock/resource.%s' % extension, {
                    'resource': registry.get_descriptor(
                        app, version, service_name),
                    'api_root': api_root,
                    'resource_root': resource_root
                })
        else:
            return render_to_response(
                'sharrock/descriptor.%s' % extension, {
                    'descriptor':
                    registry.get_descriptor(app, version, service_name),
                    'api_root':
                    api_root,
                    'resource_root':
                    resource_root
                })
    except KeyError:
        raise Http404
Example #2
0
def describe_service(request,app,version,service_name,extension='html',service_type='function'):
    """
    Gets a function descriptor.
    """
    check_extension(extension)

    try:
        if service_type == 'resource':
            return render_to_response('sharrock/resource.%s' % extension,
                                      {'resource':registry.get_descriptor(app,version,service_name),'api_root':api_root,'resource_root':resource_root})
        else:
            return render_to_response('sharrock/descriptor.%s' % extension,
                                      {'descriptor':registry.get_descriptor(app,version,service_name),'api_root':api_root,'resource_root':resource_root})
    except KeyError:
        raise Http404
Example #3
0
def execute_service(request, app, version, service_name, extension='json'):
    """
    Executes the named service.
    """
    check_extension(extension)

    try:
        service = registry.get_descriptor(app, version, service_name)
        serialized_result = service.http_service(request, format=extension)
        response = HttpResponse(serialized_result,
                                get_response_mimetype(extension))
        if service.is_deprecated:
            # set warning header
            response[
                'Warning'] = 'METHOD DEPRECATED: %s' % service.is_deprecated
        return response
    except KeyError:
        raise Http404
    except AccessDenied as ad:
        return HttpResponse(str(ad), status=403)
    except ParamRequired as pr:
        return HttpResponse(str(pr), status=400)  # missing parameter
    except Conflict as con:
        return HttpResponse(
            str(con),
            status=409)  # something user-resolvable is wrong with the function
    except BaseException as e:
        log.exception('Exception while accessing function %s.' % service_name)
        raise e
Example #4
0
def execute_resource(request,app,version,resource_name,extension='json',model_id=None):
    """
    Executes the specified resource.
    """
    check_extension(extension)

    try:
        try:
            resource = registry.get_descriptor(app,version,resource_name)
        except KeyError:
            raise Http404
        status_code, response_headers, serialized_result = resource.http_service(request,format=extension)
        response = HttpResponse(content=serialized_result,content_type=response_headers['Content-type'],status=status_code)
        for header_name, header_value  in response_headers.items():
            response[header_name] = header_value
        return response
    except AccessDenied as ad:
        return HttpResponse(unicode(ad),status=403) # access denied within the descriptor
    except ParamRequired as pr:
        return HttpResponse(unicode(pr),status=400) # there is a missing required parameter
    except MethodNotAllowed as mna:
        return HttpResponse(unicode(mna),status=405) # the employed http method is not supported
    except Conflict as con:
        return HttpResponse(unicode(con),status=409) # something user-resolvable is wrong with the resource
    except FailedToLocate as ftl:
        return HttpResponse(unicode(ftl),status=404) # descriptor has been marked with @not_found_as_404 and has raise ObjectDoesNotExist
    except BaseException as e:
        log.exception('Exception while accessing resource %s.' % resource_name)
        raise e
Example #5
0
def execute_service(request,app,version,service_name,extension='json'):
    """
    Executes the named service.
    """
    check_extension(extension)

    try:
        service = registry.get_descriptor(app,version,service_name)
        serialized_result = service.http_service(request,format=extension)
        response = HttpResponse(serialized_result,get_response_mimetype(extension))
        if service.is_deprecated:
            # set warning header
            response['Warning'] = 'METHOD DEPRECATED: %s' % service.is_deprecated
        return response
    except AccessDenied as ad:
        return HttpResponse(unicode(ad),status=403)
    except ParamRequired as pr:
        return HttpResponse(unicode(pr),status=400) # missing parameter
    except Conflict as con:
        return HttpResponse(unicode(con),status=409) # something user-resolvable is wrong with the function
    except FailedToLocate as ftl:
        return HttpResponse(unicode(ftl),status=404) # descriptor has been marked with @not_found_as_404 and has raise ObjectDoesNotExist
    except BaseException as e:
        log.exception('Exception while accessing function %s.' % service_name)
        raise e
Example #6
0
def execute_service(request,app,version,service_name,extension='json'):
    """
    Executes the named service.
    """
    check_extension(extension)

    try:
        service = registry.get_descriptor(app,version,service_name)
        serialized_result = service.http_service(request,format=extension)
        response = HttpResponse(serialized_result,get_response_mimetype(extension))
        if service.is_deprecated:
            # set warning header
            response['Warning'] = 'METHOD DEPRECATED: %s' % service.is_deprecated
        return response
    except KeyError:
        raise Http404
    except AccessDenied as ad:
        return HttpResponse(str(ad),status=403)
    except ParamRequired as pr:
        return HttpResponse(str(pr),status=400) # missing parameter
    except Conflict as con:
        return HttpResponse(str(con),status=409) # something user-resolvable is wrong with the function
    except BaseException as e:
        log.exception('Exception while accessing function %s.' % service_name)
        raise e
Example #7
0
def execute_resource(request,
                     app,
                     version,
                     resource_name,
                     extension='json',
                     model_id=None):
    """
    Executes the specified resource.
    """
    check_extension(extension)

    try:
        try:
            resource = registry.get_descriptor(app, version, resource_name)
        except KeyError:
            raise Http404
        status_code, response_headers, serialized_result = resource.http_service(
            request, format=extension)
        response = HttpResponse(content=serialized_result,
                                mimetype=response_headers['Content-type'],
                                status=status_code)
        for header_name, header_value in response_headers.items():
            response[header_name] = header_value
        return response
    except AccessDenied as ad:
        return HttpResponse(str(ad),
                            status=403)  # access denied within the descriptor
    except ParamRequired as pr:
        return HttpResponse(
            str(pr), status=400)  # there is a missing required parameter
    except MethodNotAllowed as mna:
        return HttpResponse(
            str(mna), status=405)  # the employed http method is not supported
    except Conflict as con:
        return HttpResponse(
            str(con),
            status=409)  # something user-resolvable is wrong with the resource
    except BaseException as e:
        log.exception('Exception while accessing resource %s.' % resource_name)
        raise e