<commit_before># -*- coding: utf-8 -*-
"""WSGI middleware initialization for the pyforge application."""

from webob import exc
from tg import redirect
from paste.deploy.converters import asbool

import ew
import ming

from pyforge.config.app_cfg import base_config
from pyforge.config.environment import load_environment
from pyforge.config.app_cfg import ForgeConfig
from pyforge.lib.custom_middleware import StatsMiddleware, SSLMiddleware, StaticFilesMiddleware

__all__ = ['make_app']

# Use base_config to setup the necessary PasteDeploy application factory. 
# make_base_app will wrap the TG2 app with all the middleware it needs. 
make_base_app = base_config.setup_tg_wsgi_app(load_environment)


def make_app(global_conf, full_stack=True, **app_conf):
    return _make_core_app('root', global_conf, full_stack, **app_conf)

def make_tool_test_app(global_conf, full_stack=True, **app_conf):
    return _make_core_app('test', global_conf, full_stack, **app_conf)

def _make_core_app(root, global_conf, full_stack=True, **app_conf):
    """
    Set pyforge up with the settings found in the PasteDeploy configuration
    file used.

    :param root: The controller module containing the TG root
    :param global_conf: The global settings for pyforge (those
        defined under the ``[DEFAULT]`` section).
    :type global_conf: dict
    :param full_stack: Should the whole TG2 stack be set up?
    :type full_stack: str or bool
    :return: The pyforge application with all the relevant middleware
        loaded.
    
    This is the PasteDeploy factory for the pyforge application.
    
    ``app_conf`` contains all the application-specific settings (those defined
    under ``[app:main]``.
    
   
    """
    # Create base app
    base_config = ForgeConfig(root)
    load_environment = base_config.make_load_environment()
    make_base_app = base_config.setup_tg_wsgi_app(load_environment)
    app = make_base_app(global_conf, full_stack=True, **app_conf)

    # Configure MongoDB
    ming.configure(**app_conf)

    # Wrap your base TurboGears 2 application with custom middleware here
    # app = MingMiddleware(app)
    if app_conf.get('stats.sample_rate', '0.25') != '0':
        stats_config = dict(global_conf, **app_conf)
        app = StatsMiddleware(app, stats_config)

    if asbool(app_conf.get('auth.method', 'local')=='sfx'):
        app = SSLMiddleware(app)

    app = ew.ResourceMiddleware(
        app,
        compress=not asbool(global_conf['debug']),
        script_name=app_conf.get('ew.script_name', '/_ew_resources/'),
        url_base=app_conf.get('ew.url_base', '/_ew_resources/'))

    app = StaticFilesMiddleware(app, app_conf.get('static.script_name'))

    return app
    
<commit_msg>Make sure we don't redirect static resources http<=>https<commit_after># -*- coding: utf-8 -*-
"""WSGI middleware initialization for the pyforge application."""

from webob import exc
from tg import redirect
from paste.deploy.converters import asbool

import ew
import ming

from pyforge.config.app_cfg import base_config
from pyforge.config.environment import load_environment
from pyforge.config.app_cfg import ForgeConfig
from pyforge.lib.custom_middleware import StatsMiddleware, SSLMiddleware, StaticFilesMiddleware

__all__ = ['make_app']

# Use base_config to setup the necessary PasteDeploy application factory. 
# make_base_app will wrap the TG2 app with all the middleware it needs. 
make_base_app = base_config.setup_tg_wsgi_app(load_environment)


def make_app(global_conf, full_stack=True, **app_conf):
    return _make_core_app('root', global_conf, full_stack, **app_conf)

def make_tool_test_app(global_conf, full_stack=True, **app_conf):
    return _make_core_app('test', global_conf, full_stack, **app_conf)

def _make_core_app(root, global_conf, full_stack=True, **app_conf):
    """
    Set pyforge up with the settings found in the PasteDeploy configuration
    file used.

    :param root: The controller module containing the TG root
    :param global_conf: The global settings for pyforge (those
        defined under the ``[DEFAULT]`` section).
    :type global_conf: dict
    :param full_stack: Should the whole TG2 stack be set up?
    :type full_stack: str or bool
    :return: The pyforge application with all the relevant middleware
        loaded.
    
    This is the PasteDeploy factory for the pyforge application.
    
    ``app_conf`` contains all the application-specific settings (those defined
    under ``[app:main]``.
    
   
    """
    # Create base app
    base_config = ForgeConfig(root)
    load_environment = base_config.make_load_environment()
    make_base_app = base_config.setup_tg_wsgi_app(load_environment)
    app = make_base_app(global_conf, full_stack=True, **app_conf)

    # Configure MongoDB
    ming.configure(**app_conf)

    # Wrap your base TurboGears 2 application with custom middleware here
    # app = MingMiddleware(app)
    if app_conf.get('stats.sample_rate', '0.25') != '0':
        stats_config = dict(global_conf, **app_conf)
        app = StatsMiddleware(app, stats_config)

    app = ew.ResourceMiddleware(
        app,
        compress=not asbool(global_conf['debug']),
        script_name=app_conf.get('ew.script_name', '/_ew_resources/'),
        url_base=app_conf.get('ew.url_base', '/_ew_resources/'))

    app = StaticFilesMiddleware(app, app_conf.get('static.script_name'))

    if asbool(app_conf.get('auth.method', 'local')=='sfx'):
        app = SSLMiddleware(app)

    return app
    

{'fraction_non_alphanumeric': 0.09348854128774099, 'fraction_numerical': 0.0029101491451436886, 'mean_word_length': 4.168233082706767, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '232071', 'n_tokens_mistral': 1739, 'n_tokens_neox': 1679, 'n_words': 469}