<commit_before>import asyncio

from aiohttp import web

from . import dataaccess
import urllib


async def get_toggle_states_for_env(request):
    params = urllib.parse.parse_qs(request.query_string)

    env = request.match_info['name']
    features = params.get('feature', None)
    if not features:
        return web.json_response({'Message': "No features provided"},
                                 status=400)
    if env == 'dev':
        result = {feature: True for feature in features}
    else:
        result = await dataaccess.get_toggle_states_for_env(env, features)
        for f in features:
            if f not in result.keys():
                # Everything not in the database is assumed off,
                # even if it doesn't exist
                result[f] = False
    return web.json_response(result)


async def set_toggle_state(request):
    body = await request.json()
    toggle = body.get('toggle', None)
    if not toggle:
        return web.json_response({'Message': "No toggle provided"},
                                 status=400)

    env = toggle.get('env', None)
    feature = toggle.get('feature', None)
    state = toggle.get('state', None)
<commit_msg>Add cors header<commit_after>import asyncio

from aiohttp import web

from . import dataaccess
import urllib


async def get_toggle_states_for_env(request):
    params = urllib.parse.parse_qs(request.query_string)

    env = request.match_info['name']
    features = params.get('feature', None)
    if not features:
        return web.json_response({'Message': "No features provided"},
                                 status=400)
    if env == 'dev':
        result = {feature: True for feature in features}
    else:
        result = await dataaccess.get_toggle_states_for_env(env, features)
        for f in features:
            if f not in result.keys():
                # Everything not in the database is assumed off,
                # even if it doesn't exist
                result[f] = False
    return web.json_response(result,
                             headers={'Access-Control-Allow-Origin': '*'})


async def set_toggle_state(request):
    body = await request.json()
    toggle = body.get('toggle', None)
    if not toggle:
        return web.json_response({'Message': "No toggle provided"},
                                 status=400)

    env = toggle.get('env', None)
    feature = toggle.get('feature', None)
    state = toggle.get('state', None)

{'fraction_non_alphanumeric': 0.10028420625253756, 'fraction_numerical': 0.0048721071863581, 'mean_word_length': 2.2985274431057565, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5768511', 'n_tokens_mistral': 695, 'n_tokens_neox': 670, 'n_words': 199}