<commit_before>"""Frontend view and simple pyramid app configurations."""
from urllib.parse import urlparse
import os

from pyramid.config import Configurator
from pyramid.request import Request
from pyramid.response import FileResponse


def config_view(request):
    """Return the frontend configuration."""
    settings = request.registry.settings or {}
    config = {}
    internal_ws_url = settings.get('adhocracy.ws_url', '')
    if 'adhocracy.frontend.ws_url' in settings:
        public_ws_url = settings.get('adhocracy.frontend.ws_url')
    else:
        public_ws_url = _build_ws_url(request, internal_ws_url)
    config['ws_url'] = public_ws_url
    config['pkg_path'] = settings.get('adhocracy.frontend.pkg_path',
                                      '/frontend_static/js/Packages')
    config['root_path'] = '/' + settings.get('adhocracy.platform_id',
                                             'adhocracy')
    return config


def root_view(request):
    """Return the embeddee HTML."""
    here = os.path.dirname(__file__)
    path = os.path.join(here, 'static', 'root.html')
    return FileResponse(path, request=request)


def _build_ws_url(request: Request, url: str) -> str:
    url_parsed = urlparse(url)
    ws_domain = request.domain
    ws_port = url_parsed.port or '80'
    ws_scheme = 'wss' if url_parsed.scheme == 'https' else 'ws'
    return '{}://{}:{}'.format(ws_scheme, ws_domain, ws_port)


def includeme(config):
    """Add routing and static view to deliver the frontend application."""
    config.add_static_view('frontend_static', 'adhocracy.frontend:static')
    config.add_route('embed', 'embed/{directive}')
    config.add_view(root_view, route_name='embed', renderer='html')
    config.add_route('register', 'register')
    config.add_view(root_view, route_name='register', renderer='html')
    config.add_route('config_json', 'frontend_config.json')
    config.add_view(config_view, route_name='config_json', renderer='json')


def main(global_config, **settings):
    """ Return a Pyramid WSGI application to serve the frontend application."""
    config = Configurator(settings=settings)
    includeme(config)
    return config.make_wsgi_app()<commit_msg>disable http caching for all static views<commit_after>"""Frontend view and simple pyramid app configurations."""
from urllib.parse import urlparse
import os

from pyramid.config import Configurator
from pyramid.request import Request
from pyramid.response import FileResponse


def config_view(request):
    """Return the frontend configuration."""
    settings = request.registry.settings or {}
    config = {}
    internal_ws_url = settings.get('adhocracy.ws_url', '')
    if 'adhocracy.frontend.ws_url' in settings:
        public_ws_url = settings.get('adhocracy.frontend.ws_url')
    else:
        public_ws_url = _build_ws_url(request, internal_ws_url)
    config['ws_url'] = public_ws_url
    config['pkg_path'] = settings.get('adhocracy.frontend.pkg_path',
                                      '/frontend_static/js/Packages')
    config['root_path'] = '/' + settings.get('adhocracy.platform_id',
                                             'adhocracy')
    return config


def root_view(request):
    """Return the embeddee HTML."""
    here = os.path.dirname(__file__)
    path = os.path.join(here, 'static', 'root.html')
    return FileResponse(path, request=request)


def _build_ws_url(request: Request, url: str) -> str:
    url_parsed = urlparse(url)
    ws_domain = request.domain
    ws_port = url_parsed.port or '80'
    ws_scheme = 'wss' if url_parsed.scheme == 'https' else 'ws'
    return '{}://{}:{}'.format(ws_scheme, ws_domain, ws_port)


def includeme(config):
    """Add routing and static view to deliver the frontend application."""
    config.add_static_view('frontend_static', 'adhocracy.frontend:static',
                           cache_max_age=0)
    config.add_route('embed', 'embed/{directive}')
    config.add_view(root_view, route_name='embed', renderer='html',
                    http_cache=0)
    config.add_route('register', 'register')
    config.add_view(root_view, route_name='register', renderer='html',
                    http_cache=0)
    config.add_route('config_json', 'frontend_config.json')
    config.add_view(config_view, route_name='config_json', renderer='json',
                    http_cache=0)


def main(global_config, **settings):
    """ Return a Pyramid WSGI application to serve the frontend application."""
    config = Configurator(settings=settings)
    includeme(config)
    return config.make_wsgi_app()
{'fraction_non_alphanumeric': 0.12374289462177525, 'fraction_numerical': 0.0017490161783996502, 'mean_word_length': 3.5841683366733466, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '967996', 'n_tokens_mistral': 1430, 'n_tokens_neox': 1357, 'n_words': 297}