<commit_before>"""
"""
import atexit
import inspect
import os

from lwr.manager_factory import build_managers
from lwr.persistence import PersistedJobStore
from lwr.framework import RoutingApp
import lwr.routes


def app_factory(global_conf, **local_conf):
    """
    Returns the LWR WSGI application.
    """
    webapp = LwrApp(global_conf=global_conf, **local_conf)
    atexit.register(webapp.shutdown)
    return webapp


class LwrApp(RoutingApp):
    """
    Central application logic for LWR server.
    """

    def __init__(self, **conf):
        RoutingApp.__init__(self)
        self.private_key = None
        self.staging_directory = os.path.abspath(conf['staging_directory'])
        self.__setup_private_key(conf.get("private_key", None))
        self.persisted_job_store = PersistedJobStore(**conf)
        self.managers = build_managers(self, conf.get("job_managers_config", None))
        self.__setup_routes()

    def shutdown(self):
        for manager in self.managers.values():
            try:
                manager.shutdown()
            except:
                pass

    def __setup_routes(self):
        for func_name, func in inspect.getmembers(lwr.routes, lambda x: getattr(x, '__controller__', False)):
            self.__add_route_for_function(func)

    def __add_route_for_function(self, function):
        route_suffix = '/%s' % function.__name__<commit_msg>Specify default `staging_directory` if one is not set in the code.<commit_after>"""
"""
import atexit
import inspect
import os

from lwr.manager_factory import build_managers
from lwr.persistence import PersistedJobStore
from lwr.framework import RoutingApp
import lwr.routes


def app_factory(global_conf, **local_conf):
    """
    Returns the LWR WSGI application.
    """
    webapp = LwrApp(global_conf=global_conf, **local_conf)
    atexit.register(webapp.shutdown)
    return webapp


class LwrApp(RoutingApp):
    """
    Central application logic for LWR server.
    """

    def __init__(self, **conf):
        RoutingApp.__init__(self)
        self.private_key = None
        self.staging_directory = os.path.abspath(conf.get('staging_directory', "lwr_staging"))
        self.__setup_private_key(conf.get("private_key", None))
        self.persisted_job_store = PersistedJobStore(**conf)
        self.managers = build_managers(self, conf.get("job_managers_config", None))
        self.__setup_routes()

    def shutdown(self):
        for manager in self.managers.values():
            try:
                manager.shutdown()
            except:
                pass

    def __setup_routes(self):
        for func_name, func in inspect.getmembers(lwr.routes, lambda x: getattr(x, '__controller__', False)):
            self.__add_route_for_function(func)

    def __add_route_for_function(self, function):
        route_suffix = '/%s' % function.__name__
{'fraction_non_alphanumeric': 0.10104895104895105, 'fraction_numerical': 0.0, 'mean_word_length': 3.1705539358600583, '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': '1909410', 'n_tokens_mistral': 880, 'n_tokens_neox': 863, 'n_words': 188}