<commit_before>import logging

from glob import glob
from os import getenv
from os.path import basename, join, splitext

from routes import Mapper
from routes.route import Route

CONF_D = getenv('GREINS_CONF_D') or "/etc/greins/conf.d"

class Router(object):
    def __init__(self):
        self.map = Mapper()
        self.defaults = {}

        for cf in glob(join(CONF_D, '*.py')):
            namespace = '/' + splitext(basename(cf))[0]
            routes = []
            try:
                execfile(cf, {}, {'routes': routes})
            except:
                logging.exception("Exception loading config for %s" % cf)
                continue
            self.map.extend(
                (Route(name, url,
                       **dict(self.defaults.items() + kwargs.items()))
                 for name, url, kwargs in routes), namespace)

    def __call__(self, environ, start_response):
        match = self.map.routematch(environ=environ)
        if not match:
            start_response('404 Not Found', {})
            return []
        return match[0]['app'](environ, start_response)

router = Router()
<commit_msg>No use for named routes with how we do config<commit_after>import logging

from glob import glob
from os import getenv
from os.path import basename, join, splitext

from routes import Mapper
from routes.route import Route

CONF_D = getenv('GREINS_CONF_D') or "/etc/greins/conf.d"

class Router(object):
    def __init__(self):
        self.map = Mapper()
        self.defaults = {}

        for cf in glob(join(CONF_D, '*.py')):
            namespace = '/' + splitext(basename(cf))[0]
            routes = []
            try:
                execfile(cf, {}, {'routes': routes})
            except:
                logging.exception("Exception loading config for %s" % cf)
                continue
            self.map.extend(
                (Route(None, url,
                       **dict(self.defaults.items() + kwargs.items()))
                 for kwargs in routes), namespace)

    def __call__(self, environ, start_response):
        match = self.map.routematch(environ=environ)
        if not match:
            start_response('404 Not Found', {})
            return []
        return match[0]['app'](environ, start_response)

router = Router()

{'fraction_non_alphanumeric': 0.11641137855579868, 'fraction_numerical': 0.00437636761487965, 'mean_word_length': 2.056149732620321, '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': '571982', 'n_tokens_mistral': 652, 'n_tokens_neox': 647, 'n_words': 177}