<commit_before>import glob
import inspect
import os.path

from gunicorn.app.wsgiapp import WSGIApplication
from gunicorn.config import make_settings

from greins.router import Router

hook_proxy_template = """\
def proxy{spec}:
    for handler in greins._hooks[name]['handlers']:
        handler{spec}
"""

class GreinsApplication(WSGIApplication):

    def init(self, parser, opts, args):
        if len(args) != 1:
            parser.error("No configuration directory specified.")
        if not os.path.isdir(args[0]):
            parser.error("APP_DIR must refer to an existing directory.")

        self.app_dir = os.path.abspath(args[0])
        self._mounts = {}
        self._hooks = {}

        """
        Set up server hook proxies

        Rather than explicitly referring to defined Gunicorn server hooks,
        which may change in future versions of Gunicorn, take configuration
        settings from gunicorn.config.make_settings().

        For each setting in the "Server Hooks" category, create a proxy
        function (with matching arity in order to pass validation), which
        calls the hook for every loaded app that defines it.
        """
        for name, obj in make_settings().items():
            if obj.section == "Server Hooks":
                self._hooks[name] = {
                    "handlers": [],
                    "validator": obj.validator
                }
                # Grab the arg spec from the default handler<commit_msg>proc title<commit_after>import glob
import inspect
import os.path

from gunicorn.app.wsgiapp import WSGIApplication
from gunicorn.config import make_settings

from greins.router import Router

hook_proxy_template = """\
def proxy{spec}:
    for handler in greins._hooks[name]['handlers']:
        handler{spec}
"""

class GreinsApplication(WSGIApplication):

    def init(self, parser, opts, args):
        if len(args) != 1:
            parser.error("No configuration directory specified.")
        if not os.path.isdir(args[0]):
            parser.error("APP_DIR must refer to an existing directory.")

        self.cfg.set("default_proc_name", parser.get_prog_name())
        self.app_dir = os.path.abspath(args[0])

        self._mounts = {}
        self._hooks = {}

        """
        Set up server hook proxies

        Rather than explicitly referring to defined Gunicorn server hooks,
        which may change in future versions of Gunicorn, take configuration
        settings from gunicorn.config.make_settings().

        For each setting in the "Server Hooks" category, create a proxy
        function (with matching arity in order to pass validation), which
        calls the hook for every loaded app that defines it.
        """
        for name, obj in make_settings().items():
            if obj.section == "Server Hooks":
                self._hooks[name] = {
                    "handlers": [],
                    "validator": obj.validator
                }
                # Grab the arg spec from the default handler
{'fraction_non_alphanumeric': 0.08813783962889331, 'fraction_numerical': 0.0019880715705765406, 'mean_word_length': 2.3396017699115044, 'pattern_counts': {'":': 6, '<': 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': '6559809', 'n_tokens_mistral': 800, 'n_tokens_neox': 771, 'n_words': 268}