<commit_before># coding: utf-8

from flask import Flask, request, render_template, g, session
from flaskext.babel import Babel

from .extensions import db, mail, celery, pages, github
from .gitauth import gitauth
from .frontend import frontend
from .project import project
from .settings import settings

# For import *
__all__ = ['create_app']

def create_app(app_name=__name__):

    app = Flask(app_name)
    app.register_blueprint(gitauth)
    app.register_blueprint(frontend)
    app.register_blueprint(settings)

    # keep it last
    app.register_blueprint(project)

    extensions_fabrics(app)
    error_pages(app)
    gvars(app)
    register_filters(app)

    return app

def extensions_fabrics(app):
    db.init_app(app)
    mail.init_app(app)
    babel = Babel(app)
    pages.init_app(app)
    # github.init_app(app)

    @babel.localeselector
    def get_locale():
        accept_languages = app.config.get('ACCEPT_LANGUAGES')
        return request.accept_languages.best_match(accept_languages)

    celery.config_from_object(app.config)

def error_pages(app):

    @app.errorhandler(403)
    def forbidden_page(error):
        return render_template("misc/403.html"), 403

    @app.errorhandler(404)
    def page_not_found(error):
        return render_template("misc/404.html"), 404

    @app.errorhandler(500)
    def server_error_page(error):
        return render_template("misc/500.html"), 500


def gvars(app):
    from gitauth.models import User

    @app.before_request
    def before_request():
        g.user = None
        if 'user_id' in session:
            if session['user_id']:
                g.user = User.query.get(session['user_id'])<commit_msg>space kill<commit_after># coding: utf-8

from flask import Flask, request, render_template, g, session
from flaskext.babel import Babel

from .extensions import db, mail, celery, pages, github
from .gitauth import gitauth
from .frontend import frontend
from .project import project
from .settings import settings

# For import *
__all__ = ['create_app']

def create_app(app_name=__name__):

    app = Flask(app_name)
    app.register_blueprint(gitauth)
    app.register_blueprint(frontend)
    app.register_blueprint(settings)

    # keep it last
    app.register_blueprint(project)

    extensions_fabrics(app)
    error_pages(app)
    gvars(app)
    register_filters(app)

    return app

def extensions_fabrics(app):
    db.init_app(app)
    mail.init_app(app)
    babel = Babel(app)
    pages.init_app(app)
    # github.init_app(app)

    @babel.localeselector
    def get_locale():
        accept_languages = app.config.get('ACCEPT_LANGUAGES')
        return request.accept_languages.best_match(accept_languages)

    celery.config_from_object(app.config)

def error_pages(app):
    # define error pages

    @app.errorhandler(403)
    def forbidden_page(error):
        return render_template("misc/403.html"), 403

    @app.errorhandler(404)
    def page_not_found(error):
        return render_template("misc/404.html"), 404

    @app.errorhandler(500)
    def server_error_page(error):
        return render_template("misc/500.html"), 500

def gvars(app):
    from gitauth.models import User

    @app.before_request
    def before_request():
        g.user = None
        if 'user_id' in session:
            if session['user_id']:
                g.user = User.query.get(session['user_id'])
{'fraction_non_alphanumeric': 0.09967465246968353, 'fraction_numerical': 0.016563146997929608, 'mean_word_length': 3.455862977602108, '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': '4687038', 'n_tokens_mistral': 1167, 'n_tokens_neox': 1077, 'n_words': 233}