<commit_before>"""Here we define the Morepath application class:
:class:`morepath.App`. The application class makes available the
directives to the developer. When instantiated it is a WSGI_
application that can be hooked into WSGI servers.

Because it is a :class:`dectate.App` subclass, the class object has
two special class attributes: :attr:`dectate.App.dectate`, which
contains Dectate internals, and :attr:`dectate.App.config` which
contains the actual configurations.

To actually serve requests it uses :func:`morepath.publish.publish`.

.. _WSGI: https://www.python.org/dev/peps/pep-3333

Entirely documented in :class:`morepath.App` in the public API.
"""

import dectate
import reg
from webob.exc import HTTPNotFound

from .request import Request
from . import compat
from .reify import reify
from .path import PathInfo
from .error import LinkError


def cached_key_lookup(key_lookup):
    return reg.CachingKeyLookup(key_lookup, 1000, 1000, 1000)


def dispatch_method(*predicates, **kw):
    kw.setdefault('get_key_lookup', cached_key_lookup)
    return reg.dispatch_method(*predicates, **kw)<commit_msg>Ensure the app is committed the first time a dispatch_method is invoked.<commit_after>"""Here we define the Morepath application class:
:class:`morepath.App`. The application class makes available the
directives to the developer. When instantiated it is a WSGI_
application that can be hooked into WSGI servers.

Because it is a :class:`dectate.App` subclass, the class object has
two special class attributes: :attr:`dectate.App.dectate`, which
contains Dectate internals, and :attr:`dectate.App.config` which
contains the actual configurations.

To actually serve requests it uses :func:`morepath.publish.publish`.

.. _WSGI: https://www.python.org/dev/peps/pep-3333

Entirely documented in :class:`morepath.App` in the public API.
"""

import dectate
import reg
from webob.exc import HTTPNotFound

from .request import Request
from . import compat
from .reify import reify
from .path import PathInfo
from .error import LinkError


def cached_key_lookup(key_lookup):
    return reg.CachingKeyLookup(key_lookup, 1000, 1000, 1000)


def commit_if_needed(app):
    if not app.is_committed():
        app.commit()


def dispatch_method(*predicates, **kw):
    kw.setdefault('get_key_lookup', cached_key_lookup)
    kw.setdefault('first_invocation_hook', commit_if_needed)
    return reg.dispatch_method(*predicates, **kw)
{'fraction_non_alphanumeric': 0.08904390644234715, 'fraction_numerical': 0.013130898645876077, 'mean_word_length': 5.219387755102041, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '297620', 'n_tokens_mistral': 758, 'n_tokens_neox': 710, 'n_words': 252}