def service_root(request, response): """Request routing for Slumber. """ # We have many return statements, but there's no point in artificially # breaking the function up to reduce them # pylint: disable = R0911 if not request.path.endswith('/'): return HttpResponsePermanentRedirect(request.path + '/') path = request.path[len(reverse('slumber.server.views.service_root')):-1] service = get_slumber_service() if service: if not path: return get_service_directory(request, response) elif not path.startswith(service + '/') and path != service: return HttpResponseNotFound() path = path[len(service) + 1:] if not path: return get_applications(request, response) else: # Find the app with the longest matching path apps = [a for a in applications() if path.startswith(a.path)] application = None for app in apps: if not application or len(app.path) > len(application.path): application = app if not application: return HttpResponseNotFound() remaining_path = path[len(application.path)+1:] if not remaining_path: return get_models(request, response, application) models = remaining_path.split('/') # Find the model instance and possibly return its details model = application.models.get(models.pop(0), None) if len(models) == 0: return get_model(request, response, model) try: # Execute the operation (if it can be found) operation_name = models.pop(0) operation = model.operation_by_name(operation_name) return operation.operation(request, response, application.path, model.name, *models) except NotAnOperation: return HttpResponseNotFound()
def service_root(request, response): """Request routing for Slumber. """ # We have many return statements, but there's no point in artificially # breaking the function up to reduce them # pylint: disable = R0911 if not request.path.endswith('/'): return HttpResponsePermanentRedirect(request.path + '/') path = request.path[len(reverse('slumber.server.views.service_root')):-1] service = get_slumber_service() if service: if not path: return get_service_directory(request, response) elif not path.startswith(service + '/') and path != service: return HttpResponseNotFound() path = path[len(service) + 1:] if not path: return get_applications(request, response) else: # Find the app with the longest matching path apps = [a for a in applications() if path.startswith(a.path)] application = None for app in apps: if not application or len(app.path) > len(application.path): application = app if not application: return HttpResponseNotFound() remaining_path = path[len(application.path) + 1:] if not remaining_path: return get_models(request, response, application) models = remaining_path.split('/') # Find the model instance and possibly return its details model = application.models.get(models.pop(0), None) if len(models) == 0: return get_model(request, response, model) try: # Execute the operation (if it can be found) operation_name = models.pop(0) operation = model.operation_by_name(operation_name) return operation.operation(request, response, application.path, model.name, *models) except NotAnOperation: return HttpResponseNotFound()
def _get_slumber_authn_name(): """Used in the implementation of get_auth_name so it can be easily patched. """ return getattr(settings, 'SLUMBER_AUTHN_NAME', get_slumber_service())
def service_root(request, response): """Request routing for Slumber. """ # We have many return statements, but there's no point in artificially # breaking the function up to reduce them # pylint: disable = R0911 # pylint: disable = too-many-branches # pylint: disable = too-many-locals service = get_slumber_service() apps = applications() if not request.path.endswith('/'): return HttpResponsePermanentRedirect(request.path + '/') path = request.path[len(reverse('slumber.server.views.service_root')):-1] longest = None for op_name in OPERATION_URIS.keys(): if not longest or len(op_name) > len(longest): logging.debug("Comparing %s with %s", path, op_name) if path.startswith(op_name): longest = op_name if longest: operation = OPERATION_URIS[longest] if len(path) > len(longest) + 1: path_remainder = path[len(longest)+1:].split('/') else: path_remainder = [] logging.debug("%s %s %s", path, longest, path_remainder) return operation.operation(request, response, operation.model.app, operation.model, *path_remainder) if service: if not path: return get_service_directory(request, response) elif not path.startswith(service + '/') and path != service: return HttpResponseNotFound() path = path[len(service) + 1:] if not path: return _get_applications(request, response, apps) else: # Find the app with the longest matching path apps = [a for a in apps if path.startswith(a.path)] application = None for app in apps: if not application or len(app.path) > len(application.path): application = app if not application: return HttpResponseNotFound("No app") remaining_path = path[len(application.path)+1:] if not remaining_path: return get_models(request, response, application) models = remaining_path.split('/') # Find the model instance and possibly return its details model = application.models.get(models.pop(0), None) if len(models) == 0: return get_model(request, response, model) try: # Execute the operation (if it can be found) operation_name = models.pop(0) operation = model.operations[operation_name] return operation.operation(request, response, application.path, model.name, *models) except KeyError: return HttpResponseNotFound("No op")
def service_root(request, response): """Request routing for Slumber. """ # We have many return statements, but there's no point in artificially # breaking the function up to reduce them # pylint: disable = R0911 # pylint: disable = too-many-branches # pylint: disable = too-many-locals service = get_slumber_service() apps = applications() if not request.path.endswith('/'): return HttpResponsePermanentRedirect(request.path + '/') path = request.path[len(reverse('slumber.server.views.service_root')):-1] longest = None for op_name in OPERATION_URIS.keys(): if not longest or len(op_name) > len(longest): logging.debug("Comparing %s with %s", path, op_name) if path.startswith(op_name): longest = op_name if longest: operation = OPERATION_URIS[longest] if len(path) > len(longest) + 1: path_remainder = path[len(longest) + 1:].split('/') else: path_remainder = [] logging.debug("%s %s %s", path, longest, path_remainder) return operation.operation(request, response, operation.model.app, operation.model, *path_remainder) if service: if not path: return get_service_directory(request, response) elif not path.startswith(service + '/') and path != service: return HttpResponseNotFound() path = path[len(service) + 1:] if not path: return _get_applications(request, response, apps) else: # Find the app with the longest matching path apps = [a for a in apps if path.startswith(a.path)] application = None for app in apps: if not application or len(app.path) > len(application.path): application = app if not application: return HttpResponseNotFound("No app") remaining_path = path[len(application.path) + 1:] if not remaining_path: return get_models(request, response, application) models = remaining_path.split('/') # Find the model instance and possibly return its details model = application.models.get(models.pop(0), None) if len(models) == 0: return get_model(request, response, model) try: # Execute the operation (if it can be found) operation_name = models.pop(0) operation = model.operations[operation_name] return operation.operation(request, response, application.path, model.name, *models) except KeyError: return HttpResponseNotFound("No op")