<commit_before># -*- coding: utf-8 -*-

"""The base Controller API."""

from tg import TGController, tmpl_context, config
from tg.render import render
from pylons.i18n import _, ungettext, N_
from pylons import c, g
from tw.api import WidgetBunch
import pyforge.model as model

import pkg_resources
from webob import exc
import ming

__all__ = ['BaseController']


class BaseController(TGController):
    """
    Base class for the controllers in the application.

    Your web application should have one of these. The root of
    your application is used to compute URLs used by your app.

    """

    def __call__(self, environ, start_response):
        """This is the basic WSGI callable that wraps and dispatches forge controllers.

        It peforms a number of functions:
          * displays the forge index page
          * sets up and cleans up the Ming/MongoDB Session
          * persists all Ming object changes to Mongo
        """
        environ['wsgi.url_scheme'] = 'https'

        app = self._wsgi_handler(environ)
        if app is None:
            """Invoke the Controller"""
            # TGController.__call__ dispatches to the Controller method
            # the request is routed to. This routing information is
            # available in environ['pylons.routes_dict']
            app = lambda e,s: TGController.__call__(self, e, s)
        try:
            result = app(environ, start_response)
            if not isinstance(result, list):
                return self._cleanup_iterator(result)
            else:
                self._cleanup_request()
                return result
        except exc.HTTPRedirection:
            self._cleanup_request()
            raise
        except:
            ming.orm.ormsession.ThreadLocalORMSession.close_all()
            raise

    def _wsgi_handler(self, environ):
        host = environ['HTTP_HOST'].lower()<commit_msg>[#119] - Make https scheme based on SSL header<commit_after># -*- coding: utf-8 -*-

"""The base Controller API."""

from tg import TGController, tmpl_context, config
from tg.render import render
from pylons.i18n import _, ungettext, N_
from pylons import c, g
from tw.api import WidgetBunch
import pyforge.model as model
from paste.deploy.converters import asbool

import pkg_resources
from webob import exc
import ming

__all__ = ['BaseController']


class BaseController(TGController):
    """
    Base class for the controllers in the application.

    Your web application should have one of these. The root of
    your application is used to compute URLs used by your app.

    """

    def __call__(self, environ, start_response):
        """This is the basic WSGI callable that wraps and dispatches forge controllers.

        It peforms a number of functions:
          * displays the forge index page
          * sets up and cleans up the Ming/MongoDB Session
          * persists all Ming object changes to Mongo
        """
        if asbool(environ.get('HTTP_X_SFINC_SSL', 'false')):
            environ['wsgi.url_scheme'] = 'https'

        app = self._wsgi_handler(environ)
        if app is None:
            """Invoke the Controller"""
            # TGController.__call__ dispatches to the Controller method
            # the request is routed to. This routing information is
            # available in environ['pylons.routes_dict']
            app = lambda e,s: TGController.__call__(self, e, s)
        try:
            result = app(environ, start_response)
            if not isinstance(result, list):
                return self._cleanup_iterator(result)
            else:
                self._cleanup_request()
                return result
        except exc.HTTPRedirection:
            self._cleanup_request()
            raise
        except:
            ming.orm.ormsession.ThreadLocalORMSession.close_all()
            raise

    def _wsgi_handler(self, environ):
        host = environ['HTTP_HOST'].lower()
{'fraction_non_alphanumeric': 0.07504451793436785, 'fraction_numerical': 0.0022894937674891886, 'mean_word_length': 2.3606837606837607, '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': '6690043', 'n_tokens_mistral': 1083, 'n_tokens_neox': 1020, 'n_words': 373}