<commit_before>MAX_AGE = 1728000


def set_max_age(age):
    """:see 'Access-Control-Max-Age': str(MAX_AGE) below"""
    global MAX_AGE
    MAX_AGE = age


def add_cors_headers_response_callback(event):
    """
    add CORS so the requests can work from different (test / development) port
    do this at least for testing ... might not make call in production
    :param event:

    :see config.add_subscriber(add_cors_headers_response_callback, NewRequest):

    :see credit goes to https://stackoverflow.com/users/211490/wichert-akkerman
    :see https://stackoverflow.com/questions/21107057/pyramid-cors-for-ajax-requests
    """
    def cors_headers(request, response):
        response.headers.update({
            'Access-Control-Allow-Origin': '*',
            'Access-Control-Allow-Methods': 'POST,GET,DELETE,PUT,OPTIONS',
            'Access-Control-Allow-Headers': 'Origin, Content-Type, Accept, Authorization',
            'Access-Control-Allow-Credentials': 'true',
            'Access-Control-Max-Age': str(MAX_AGE),
        })

    # set the function above to be called for each response, where we'll set the CORS headers
    event.request.add_response_callback(cors_headers)<commit_msg>add logging ... see how much time a req/rep takes<commit_after>import logging
log = logging.getLogger(__file__)


MAX_AGE = 1728000


def set_max_age(age):
    """:see 'Access-Control-Max-Age': str(MAX_AGE) below"""
    global MAX_AGE
    MAX_AGE = age
    log.info("set Access-Control-Max-Age response header to {}".format(age))


def add_cors_headers_response_callback(event):
    """
    add CORS so the requests can work from different (test / development) port
    do this at least for testing ... might not make call in production
    :param event:

    :see config.add_subscriber(add_cors_headers_response_callback, NewRequest):

    :see credit goes to https://stackoverflow.com/users/211490/wichert-akkerman
    :see https://stackoverflow.com/questions/21107057/pyramid-cors-for-ajax-requests
    """
    def cors_headers(request, response):
        response.headers.update({
            'Access-Control-Allow-Origin': '*',
            'Access-Control-Allow-Methods': 'POST,GET,DELETE,PUT,OPTIONS',
            'Access-Control-Allow-Headers': 'Origin, Content-Type, Accept, Authorization',
            'Access-Control-Allow-Credentials': 'true',
            'Access-Control-Max-Age': str(MAX_AGE),
        })
        log.debug("CORS headers will be in the response")

    # set the function above to be called for each response, where we'll set the CORS headers
    log.debug("set request /response event - CORS headers")
    event.request.add_response_callback(cors_headers)
{'fraction_non_alphanumeric': 0.11504095309009679, 'fraction_numerical': 0.01563663440059568, 'mean_word_length': 3.3549432739059966, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '5267170', 'n_tokens_mistral': 836, 'n_tokens_neox': 788, 'n_words': 196}