<commit_before>import os

from flask import Flask, redirect, url_for, request, flash, render_template, current_app
from flask_login import current_user
from flask_babel import Babel
from jinja2 import StrictUndefined
from werkzeug.datastructures import ImmutableDict

from hades_logs import HadesLogs
from pycroft.helpers.i18n import gettext
from pycroft.model import session
from . import template_filters
from . import template_tests
from .blueprints import (
    finance, infrastructure, properties, user, facilities, login)
from .blueprints.login import login_manager
from .templates import page_resources


class PycroftFlask(Flask):
    """
    Extend the Flask class to set Jinja options.
    """
    jinja_options = ImmutableDict(
        Flask.jinja_options,
        undefined=StrictUndefined
    )

    def __init__(self, *a, **kw):
        super().__init__(*a, **kw)
        # config keys to support:
        self.maybe_add_config_from_env([
            'HADES_CELERY_APP_NAME',
            'HADES_BROKER_URI',
            'HADES_RESULT_BACKEND_URI',
            'HADES_TIMEOUT',
            'HADES_ROUTING_KEY',
        ])

    def maybe_add_config_from_env(self, keys):
        """Write keys from the environment to the app's config

        If a key does not exist in the environment, it will just be
        skipped.

        :param keys: An iterable of strings
        """
        for key in keys:
            try:
                self.config[key] = os.environ[key]<commit_msg>Enable Jinja2 do and loopcontrols extensions<commit_after>import os

import jinja2.ext
from flask import Flask, redirect, url_for, request, flash, render_template, current_app
from flask_login import current_user
from flask_babel import Babel
from jinja2 import StrictUndefined
from werkzeug.datastructures import ImmutableDict

from hades_logs import HadesLogs
from pycroft.helpers.i18n import gettext
from pycroft.model import session
from . import template_filters
from . import template_tests
from .blueprints import (
    finance, infrastructure, properties, user, facilities, login)
from .blueprints.login import login_manager
from .templates import page_resources


class PycroftFlask(Flask):
    """
    Extend the Flask class to set Jinja options.
    """
    jinja_options = ImmutableDict(
        Flask.jinja_options,
        extensions=[
            jinja2.ext.autoescape,
            jinja2.ext.do,
            jinja2.ext.loopcontrols,
            jinja2.ext.with_,
        ],
        undefined=StrictUndefined
    )

    def __init__(self, *a, **kw):
        super().__init__(*a, **kw)
        # config keys to support:
        self.maybe_add_config_from_env([
            'HADES_CELERY_APP_NAME',
            'HADES_BROKER_URI',
            'HADES_RESULT_BACKEND_URI',
            'HADES_TIMEOUT',
            'HADES_ROUTING_KEY',
        ])

    def maybe_add_config_from_env(self, keys):
        """Write keys from the environment to the app's config

        If a key does not exist in the environment, it will just be
        skipped.

        :param keys: An iterable of strings
        """
        for key in keys:
            try:
                self.config[key] = os.environ[key]
{'fraction_non_alphanumeric': 0.07102628285356696, 'fraction_numerical': 0.0037546933667083854, 'mean_word_length': 2.7479484173505275, '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': '7335222', 'n_tokens_mistral': 973, 'n_tokens_neox': 939, 'n_words': 275}