<commit_before>import json, bottle, traceback
from bottle import request as bottle_req, response as bottle_resp
from .endpoint import EndpointHandler
from .login import LoginHandler, LogoutHandler
from .actions import ActionAPI
from . import exceptions, http
from functools import wraps

application = bottle.Bottle()


def to_json(fnc):
    @wraps(fnc)
    def inner(*args, **kwargs):
        bottle_resp.headers['Content-Type'] = 'application/json'
        from_func = fnc(*args, **kwargs)
        return json.dumps({'result': from_func})
    return inner


@application.route('/<url:re:.+>', method=['GET', 'POST', 'PUT', 'DELETE'], apply=to_json)
def dispatch(url):
    """
        This class is the beginning of all entrypoint in the Ray API. Here, each url
        will be redirect to the right handler: ActionHandler, LoginHandler or EndpointHandler.
    """
    url = bottle_req.path

    if url[-1] == '/':
        url = url[:-1]

    response_code = 200

    try:
        processed = process(url, bottle_req, bottle_resp)

        try:
            from_func, http_status = processed[0], processed[1]
            bottle_resp.status = http_status
            return from_func
        except:
            return processed

    except exceptions.RayException as e:
        response_code = e.http_code

    except Exception:
        traceback.print_exc()

    bottle_resp.status = response_code


def process(fullpath, request, response):
    if is_login(fullpath):
        return LoginHandler(request, response, fullpath).process()

    if is_logout(fullpath):
        return LogoutHandler(response).logout()

    elif is_endpoint(fullpath):
        print('veiop aquioasjds')
        return EndpointHandler(request, fullpath).process()

    elif is_action(fullpath):
        return __handle_action(fullpath), 200

    else:
        raise exceptions.BadRequest()
<commit_msg>Adding log statements<commit_after>import json, bottle, traceback, logging
from bottle import request as bottle_req, response as bottle_resp

from .endpoint import EndpointHandler
from .login import LoginHandler, LogoutHandler
from .actions import ActionAPI
from . import exceptions, http
from functools import wraps


application = bottle.Bottle()
log = logging.getLogger('ray')


def to_json(fnc):
    @wraps(fnc)
    def inner(*args, **kwargs):
        bottle_resp.headers['Content-Type'] = 'application/json'
        from_func = fnc(*args, **kwargs)
        return json.dumps({'result': from_func})
    return inner


@application.route('/<url:re:.+>', method=['GET', 'POST', 'PUT', 'DELETE'], apply=to_json)
def dispatch(url):
    """
        This class is the beginning of all entrypoint in the Ray API. Here, each url
        will be redirect to the right handler: ActionHandler, LoginHandler or EndpointHandler.
    """

    url = bottle_req.path
    log.debug('request: %s', url)

    if url[-1] == '/':
        url = url[:-1]

    response_code = 200

    try:
        processed = process(url, bottle_req, bottle_resp)

        try:
            from_func, http_status = processed[0], processed[1]
            bottle_resp.status = http_status
            return from_func
        except:
            return processed

    except exceptions.RayException as e:
        log.warn('RayException raised: %s', e)
        response_code = e.http_code

    except Exception as e:
        log.error('Not expected exception raised: %s', e.message())
        traceback.print_exc()

    bottle_resp.status = response_code


def process(fullpath, request, response):
    if is_login(fullpath):
        return LoginHandler(request, response, fullpath).process()

    if is_logout(fullpath):
        return LogoutHandler(response).logout()

    elif is_endpoint(fullpath):
        return EndpointHandler(request, fullpath).process()

    elif is_action(fullpath):
        return __handle_action(fullpath), 200

    else:
        raise exceptions.BadRequest()

{'fraction_non_alphanumeric': 0.10328160773340117, 'fraction_numerical': 0.005087763927753753, 'mean_word_length': 3.06198347107438, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2087327', 'n_tokens_mistral': 1149, 'n_tokens_neox': 1117, 'n_words': 320}