Exemplo n.º 1
0
def handle_request(request, more_id=None):
    try:
        r_dict = req_parse.parse(request, more_id)
        path = request.path.lower()
        
        if path.endswith('/'):
            path = path.rstrip('/')

        # Cutoff more_id
        if '/xapi/statements/more' in path:
            path = '/xapi/statements/more'

        req_dict = validators[path][r_dict['method']](r_dict)
        return processors[path][req_dict['method']](req_dict)
    except exceptions.BadRequest as err:
        return HttpResponse(err.message, status=400)
    except ValidationError as ve:
        return HttpResponse(ve.messages[0], status=400)
    except exceptions.Unauthorized as autherr:
        r = HttpResponse(autherr, status = 401)
        r['WWW-Authenticate'] = 'Basic realm="ADLLRS"'
        return r
    except exceptions.OauthUnauthorized as oauth_err:
        return oauth_err.response
    except exceptions.Forbidden as forb:
        return HttpResponse(forb.message, status=403)
    except exceptions.NotFound as nf:
        return HttpResponse(nf.message, status=404)
    except exceptions.Conflict as c:
        return HttpResponse(c.message, status=409)
    except exceptions.PreconditionFail as pf:
        return HttpResponse(pf.message, status=412)
    except Exception as err:
        return HttpResponse(err.message, status=500)
Exemplo n.º 2
0
def handle_request(request):
    try:
        r_dict = req_parse.parse(request)
        path = request.path
        if path.endswith('/'):
            path = path.rstrip('/')
        req_dict = validators[path][r_dict['method']](r_dict)
        return processors[path][req_dict['method']](req_dict)
    except exceptions.BadRequest as err:
        return HttpResponse(err.message, status=400)        
    except exceptions.Unauthorized as autherr:
        r = HttpResponse(autherr, status = 401)
        r['WWW-Authenticate'] = 'Basic realm="ADLLRS"'
        return r
    except exceptions.OauthUnauthorized as oauth_err:
        return oauth_err.response
    except exceptions.Forbidden as forb:
        return HttpResponse(forb.message, status=403)
    except exceptions.NotFound as nf:
        return HttpResponse(nf.message, status=404)
    except exceptions.Conflict as c:
        return HttpResponse(c.message, status=409)
    except exceptions.PreconditionFail as pf:
        return HttpResponse(pf.message, status=412)
    except Exception as err:
        return HttpResponse(err.message, status=500)
Exemplo n.º 3
0
def handle_request(request, more_id=None):
    try:
        r_dict = req_parse.parse(request, more_id)
        path = request.path.lower()
	print("Testing this:")
	print(r_dict)

        if path.endswith('/'):
            path = path.rstrip('/')

        # Cutoff more_id
        if '/xapi/statements/more' in path:
            path = '/xapi/statements/more'

        req_dict = validators[path][r_dict['method']](r_dict)
        return processors[path][req_dict['method']](req_dict)

    except exceptions.BadRequest as err:
        log_exception(request.path, err)
        return HttpResponse(err.message, status=400)
    except ValidationError as ve:
        log_exception(request.path, ve)
        return HttpResponse(ve.messages[0], status=400)
    except exceptions.Unauthorized as autherr:
        log_exception(request.path, autherr)
        r = HttpResponse(autherr, status = 401)
	logger.info("401: ")
	logger.info(r_dict)
        r['WWW-Authenticate'] = 'Basic realm="ADLLRS"'
        return r
    except exceptions.OauthUnauthorized as oauth_err:
        log_exception(request.path, oauth_err)
        return oauth_err.response
    except exceptions.Forbidden as forb:
        log_exception(request.path, forb)
	logger.info("403:")
	logger.info(r_dict)
        return HttpResponse(forb.message, status=403)
    except exceptions.NotFound as nf:
        log_exception(request.path, nf)
	logger.info("404:")
	logger.info(r_dict)
        return HttpResponse(nf.message, status=404)
    except exceptions.Conflict as c:
        log_exception(request.path, c)
        return HttpResponse(c.message, status=409)
    except exceptions.PreconditionFail as pf:
        log_exception(request.path, pf)
        return HttpResponse(pf.message, status=412)
    except Exception as err:
        log_exception(request.path, err)
	logger.info("500: ")
	if r_dict is not None:
	    logger_info(r_dict)
        return HttpResponse(err.message, status=500)
Exemplo n.º 4
0
def handle_request(request, more_id=None):
    try:
        r_dict = req_parse.parse(request, more_id)
        path = request.path.lower()

        if path.endswith('/'):
            path = path.rstrip('/')

        # Cutoff more_id
        if '/xapi/statements/more' in path:
            path = '/xapi/statements/more'

        req_dict = validators[path][r_dict['method']](r_dict)
        return processors[path][req_dict['method']](req_dict)

    except exceptions.BadRequest as err:
        log_exception(request.path, err)
        return HttpResponse(err.message, status=400)
    except ValidationError as ve:
        log_exception(request.path, ve)
        return HttpResponse(ve.messages[0], status=400)
    except exceptions.Unauthorized as autherr:
        log_exception(request.path, autherr)
        r = HttpResponse(autherr, status=401)
        r['WWW-Authenticate'] = 'Basic realm="ADLLRS"'
        return r
    except exceptions.OauthUnauthorized as oauth_err:
        log_exception(request.path, oauth_err)
        return oauth_err.response
    except exceptions.Forbidden as forb:
        log_exception(request.path, forb)
        return HttpResponse(forb.message, status=403)
    except exceptions.NotFound as nf:
        log_exception(request.path, nf)
        return HttpResponse(nf.message, status=404)
    except exceptions.Conflict as c:
        log_exception(request.path, c)
        return HttpResponse(c.message, status=409)
    except exceptions.PreconditionFail as pf:
        log_exception(request.path, pf)
        return HttpResponse(pf.message, status=412)
    except Exception as err:
        log_exception(request.path, err)
        return HttpResponse(err.message, status=500)