<commit_before>import os
import re
from socket import inet_aton
import sys
from urllib import unquote

import dateutil.parser
from redis import ConnectionError
from werkzeug.wrappers import Request, Response
from werkzeug.routing import Map, Rule
from werkzeug.exceptions import HTTPException, NotFound
from werkzeug.datastructures import Headers

from . import __version__
from api import participate, convert

from config import CONFIG as cfg
from metrics import init_statsd
from utils import to_bool

try:
    import db
except ConnectionError:
    print "Redis is currently unavailable or misconfigured"
    sys.exit()

from models import Experiment, Client
from utils import service_unavailable_on_connection_error, json_error, json_success


class CORSMiddleware(object):
    """Add Cross-origin resource sharing headers to every request."""

    def __init__(self, app, origin=None):
        self.app = app
        self.redis = self.app.redis
        self.statsd = self.app.statsd
        self.config = self.app.config

        self.origin = origin or cfg.get("cors_origin")
        self.origin_regexp = re.compile(self.origin.replace("*", "(.*)")) \
            if self.origin != '*' else None<commit_msg>fix: be less cute about in-place logic. Closes #279<commit_after>import os
import re
from socket import inet_aton
import sys
from urllib import unquote

import dateutil.parser
from redis import ConnectionError
from werkzeug.wrappers import Request, Response
from werkzeug.routing import Map, Rule
from werkzeug.exceptions import HTTPException, NotFound
from werkzeug.datastructures import Headers

from . import __version__
from api import participate, convert

from config import CONFIG as cfg
from metrics import init_statsd
from utils import to_bool

try:
    import db
except ConnectionError:
    print "Redis is currently unavailable or misconfigured"
    sys.exit()

from models import Experiment, Client
from utils import service_unavailable_on_connection_error, json_error, json_success


class CORSMiddleware(object):
    """Add Cross-origin resource sharing headers to every request."""

    def __init__(self, app, origin=None):
        self.app = app
        self.redis = self.app.redis
        self.statsd = self.app.statsd
        self.config = self.app.config

        self.origin = origin or cfg.get("cors_origin")
        self.origin_regexp = None
        if self.origin != '*':
            self.origin_regexp = re.compile(self.origin.replace("*", "(.*)"))
{'fraction_non_alphanumeric': 0.07243460764587525, 'fraction_numerical': 0.0012072434607645875, 'mean_word_length': 3.903353057199211, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6841335', 'n_tokens_mistral': 702, 'n_tokens_neox': 701, 'n_words': 241}