<commit_before>"""Setup pyramid wsgi app."""
from pyramid.config import Configurator
from pyramid_zodbconn import get_connection
from pyramid.authorization import ACLAuthorizationPolicy
from substanced.evolution import mark_unfinished_as_finished as markunf
import transaction

from adhocracy.authentication import TokenHeaderAuthenticationPolicy
from adhocracy.resources.root import IRootPool


def root_factory(request, t=transaction, g=get_connection,
                 mark_unfinished_as_finished=False):
    """ A function which can be used as a Pyramid ``root_factory``.

    It accepts a request and returns an instance of the ``Root`` content type.

    """
    # FIXME: Fix substanced bug: mark_unfinished_as_finished keyword
    # is not working
    # Ee don't get the root object if the request alread have one.
    # Workaround to make the subrequests in adhocracy.rest.batchview work.
    if getattr(request, 'root', False):
        return request.root
    conn = g(request)
    zodb_root = conn.root()
    if 'app_root' not in zodb_root:
        registry = request.registry
        app_root = registry.content.create(IRootPool.__identifier__)<commit_msg>Gardening<commit_after>"""Setup pyramid wsgi app."""
from pyramid.config import Configurator
from pyramid_zodbconn import get_connection
from pyramid.authorization import ACLAuthorizationPolicy
from substanced.evolution import mark_unfinished_as_finished as markunf
import transaction

from adhocracy.authentication import TokenHeaderAuthenticationPolicy
from adhocracy.resources.root import IRootPool


def root_factory(request, t=transaction, g=get_connection,
                 mark_unfinished_as_finished=False):
    """ A function which can be used as a Pyramid ``root_factory``.

    It accepts a request and returns an instance of the ``Root`` content type.

    """
    # FIXME: Fix substanced bug: mark_unfinished_as_finished keyword
    # is not working.
    # Don't get the root object if the request already has one.
    # Workaround to make the subrequests in adhocracy.rest.batchview work.
    if getattr(request, 'root', False):
        return request.root
    conn = g(request)
    zodb_root = conn.root()
    if 'app_root' not in zodb_root:
        registry = request.registry
        app_root = registry.content.create(IRootPool.__identifier__)
{'fraction_non_alphanumeric': 0.06743986254295532, 'fraction_numerical': 0.0, 'mean_word_length': 4.141280353200883, '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': '5507796', 'n_tokens_mistral': 657, 'n_tokens_neox': 628, 'n_words': 214}