<commit_before>"""Initialize Mercator ACM."""
from pyramid.events import ApplicationCreated
from pyramid.request import Request
from substanced.util import get_acl
from adhocracy_core.authorization import acm_to_acl
from adhocracy_core.utils import set_acl
from adhocracy_mercator.resources.mercator import mercator_acm
# import transaction


def _application_created_subscriber(event):
    """Called when the Pyramid application is started."""
    app = event.app
    root = _get_root(app)
    _set_permissions(root, app.registry)


def _get_root(app):
    request = Request.blank('/path-is-meaningless-here')
    request.registry = app.registry
    root = app.root_factory(request)
    return root


def _set_permissions(root, registry):
    acl = get_acl(root)
    mercator_acl = acm_to_acl(mercator_acm, registry)
    new_acl = mercator_acl + acl
    set_acl(root, new_acl, registry)
    #    transaction.commit()  # otherwise mercator permission get discarded?!


def includeme(config):
    """Register subscribers."""
    config.add_subscriber(_application_created_subscriber, ApplicationCreated)<commit_msg>fix mercator functional test<commit_after>"""Initialize Mercator ACM."""
from pyramid.events import ApplicationCreated
from pyramid.request import Request
from substanced.util import get_acl
from adhocracy_core.authorization import acm_to_acl
from adhocracy_core.utils import set_acl
from adhocracy_mercator.resources.mercator import mercator_acm
import transaction


def _application_created_subscriber(event):
    """Called when the Pyramid application is started."""
    app = event.app
    root = _get_root(app)
    _set_permissions(root, app.registry)


def _get_root(app):
    request = Request.blank('/path-is-meaningless-here')
    request.registry = app.registry
    root = app.root_factory(request)
    return root


def _set_permissions(root, registry):
    acl = get_acl(root)
    mercator_acl = acm_to_acl(mercator_acm, registry)
    new_acl = mercator_acl + acl
    set_acl(root, new_acl, registry)
    transaction.commit()  # otherwise mercator permission get discarded?!


def includeme(config):
    """Register subscribers."""
    config.add_subscriber(_application_created_subscriber, ApplicationCreated)
{'fraction_non_alphanumeric': 0.08407871198568873, 'fraction_numerical': 0.0, 'mean_word_length': 5.062330623306233, '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': '937635', 'n_tokens_mistral': 690, 'n_tokens_neox': 660, 'n_words': 162}