<commit_before># coding:utf-8

# from past.builtins import basestring
# __all__ = ['Empty']

from flask import Flask, render_template
import logging

basestring = getattr(__builtins__, 'basestring', str)


def _import_variable(blueprint_path, module, variable_name):
    path = '.'.join(blueprint_path.split('.') + [module])
    mod = __import__(path, fromlist=[variable_name])
    return getattr(mod, variable_name)


class Empty(Flask):

    def configure(self, config):
        """
        Loads configuration class into flask app.
        If environment variable available, overwrites class config.

        """
        self.config.update(config)
        # could/should be available in server environment
        self.config.from_envvar("APP_CONFIG", silent=True)

    def add_blueprint(self, name, kw):
        blueprint = _import_variable(name, 'views', 'app')
        self.register_blueprint(blueprint, **kw)

    def add_blueprint_list(self, bp_list):
        for blueprint_config in bp_list:
            name, kw = None, {}

            if isinstance(blueprint_config, basestring):
                name = blueprint_config
            elif isinstance(blueprint_config, (list, tuple)):
                name = blueprint_config[0]
                kw.update(blueprint_config[1])
            else:
                print("Error in BLUEPRINTS setup in config.py")
                print("Please, verify if each blueprint setup is either a string or a tuple.")
                exit(1)

            self.add_blueprint(name, kw)

    def setup(self):
        self.configure_logger()
        self.configure_error_handlers()
        self.configure_database()
        self.configure_context_processors()
        self.configure_template_extensions()
        self.configure_template_filters()
        self.configure_extensions()
        self.configure_before_request()
        self.configure_views()

    def configure_logger(self):
        try:
            log_filename = self.config['LOG_FILENAME']

            # Create a file logger since we got a logdir
            log_file = logging.FileHandler(filename=log_filename)
            formatter = logging.Formatter(self.config['LOG_FORMAT'])
            log_file.setFormatter(formatter)
            log_file.setLevel(self.config['LOG_LEVEL'])
            self.logger.addHandler(log_file)
            self.logger.info("Logger started")
        except Exception:
            pass
            # print("Could not configure logger, using defaults.")
            
    def configure_error_handlers(self):

        errorhandler = self.errorhandler
        
        @errorhandler(403)
        def forbidden_page(error):
            """
            The server understood the request, but is refusing to fulfill it.
            Authorization will not help and the request SHOULD NOT be repeated.
            If the request method was not HEAD and the server wishes to make public
            why the request has not been fulfilled, it SHOULD describe the reason for
            the refusal in the entity. If the server does not wish to make this
            information available to the client, the status code 404 (Not Found)
            can be used instead.
            """
            return render_template("http/access_forbidden.html"), 403

        @errorhandler(404)
        def page_not_found(error):<commit_msg>remove obnoxious logging<commit_after># coding:utf-8

# from past.builtins import basestring
# __all__ = ['Empty']

from flask import Flask, render_template
import logging

basestring = getattr(__builtins__, 'basestring', str)


def _import_variable(blueprint_path, module, variable_name):
    path = '.'.join(blueprint_path.split('.') + [module])
    mod = __import__(path, fromlist=[variable_name])
    return getattr(mod, variable_name)


class Empty(Flask):

    def configure(self, config):
        """
        Loads configuration class into flask app.
        If environment variable available, overwrites class config.

        """
        self.config.update(config)
        # could/should be available in server environment
        self.config.from_envvar("APP_CONFIG", silent=True)

    def add_blueprint(self, name, kw):
        blueprint = _import_variable(name, 'views', 'app')
        self.register_blueprint(blueprint, **kw)

    def add_blueprint_list(self, bp_list):
        for blueprint_config in bp_list:
            name, kw = None, {}

            if isinstance(blueprint_config, basestring):
                name = blueprint_config
            elif isinstance(blueprint_config, (list, tuple)):
                name = blueprint_config[0]
                kw.update(blueprint_config[1])
            else:
                print("Error in BLUEPRINTS setup in config.py")
                print("Please, verify if each blueprint setup is either a string or a tuple.")
                exit(1)

            self.add_blueprint(name, kw)

    def setup(self):
        self.configure_logger()
        self.configure_error_handlers()
        self.configure_database()
        self.configure_context_processors()
        self.configure_template_extensions()
        self.configure_template_filters()
        self.configure_extensions()
        self.configure_before_request()
        self.configure_views()

    def configure_logger(self):
        try:
            log_filename = self.config['LOG_FILENAME']

            # Create a file logger since we got a logdir
            log_file = logging.FileHandler(filename=log_filename)
            formatter = logging.Formatter(self.config['LOG_FORMAT'])
            log_file.setFormatter(formatter)
            log_file.setLevel(self.config['LOG_LEVEL'])
            self.logger.addHandler(log_file)
            # self.logger.info("Logger started")
        except Exception:
            pass
            # print("Could not configure logger, using defaults.")
            
    def configure_error_handlers(self):

        errorhandler = self.errorhandler
        
        @errorhandler(403)
        def forbidden_page(error):
            """
            The server understood the request, but is refusing to fulfill it.
            Authorization will not help and the request SHOULD NOT be repeated.
            If the request method was not HEAD and the server wishes to make public
            why the request has not been fulfilled, it SHOULD describe the reason for
            the refusal in the entity. If the server does not wish to make this
            information available to the client, the status code 404 (Not Found)
            can be used instead.
            """
            return render_template("http/access_forbidden.html"), 403

        @errorhandler(404)
        def page_not_found(error):
{'fraction_non_alphanumeric': 0.08170858758743861, 'fraction_numerical': 0.004762613484149427, 'mean_word_length': 2.3667334669338675, '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': '3657641', 'n_tokens_mistral': 1803, 'n_tokens_neox': 1715, 'n_words': 497}