<commit_before># -*- coding: utf-8 -*-
"""
    longboxed.factory
    ~~~~~~~~~~~~~~~~~

    longboxed factory module

"""
import os
import json

import logging
import logging.config

from celery import Celery
from flask import Flask
from flask.ext.security import SQLAlchemyUserDatastore
from flask.ext.social.datastore import SQLAlchemyConnectionDatastore
from flask.ext.security.forms import (ConfirmRegisterForm,
                                      PasswordConfirmFormMixin)
from sqlalchemy_imageattach.context import push_store_context, pop_store_context

from . import signals
from .core import db, mail, security, store, social
from .helpers import register_blueprints
from .middleware import HTTPMethodOverrideMiddleware
from .models import Connection, User, Role
from .settings import config


class ExtendedConfirmRegisterForm(ConfirmRegisterForm,
                                  PasswordConfirmFormMixin):
    pass


def create_app(package_name, package_path, config_name, debug_override=None,
               register_security_blueprint=True):
    """Returns a :class:`Flask` application instance configured with common
    functionality for the Longboxed platform.

    :param package_name: application package name
    :param package_path: application package path
    :param settings_override: a dictionary of settings to override
    :param debug_overide: :class:`Bool` value that overrides the debug settings
    """
    app = Flask(package_name, instance_relative_config=True)

    # #: Register custom Jinja2 filters
    # app.jinja_env.filters['pretty_date'] = pretty_date

    app.config.from_object(config[config_name])
    app.config.from_pyfile('settings.cfg', silent=True)
    if debug_override is not None:
        app.debug = debug_override

    #: Additional Settings setup
    config[config_name].init_app(app, store=store)

    #: Setup Flask Extentions
    db.init_app(app)
    mail.init_app(app)
    #: Setup Flask-Security
    security.init_app(app, SQLAlchemyUserDatastore(db, User, Role),
                      register_blueprint=register_security_blueprint,
                      confirm_register_form=ExtendedConfirmRegisterForm)

    app.social = social.init_app(
            app,<commit_msg>added the cache class to the app<commit_after># -*- coding: utf-8 -*-
"""
    longboxed.factory
    ~~~~~~~~~~~~~~~~~

    longboxed factory module

"""
import os
import json

import logging
import logging.config

from celery import Celery
from flask import Flask
from flask.ext.security import SQLAlchemyUserDatastore
from flask.ext.social.datastore import SQLAlchemyConnectionDatastore
from flask.ext.security.forms import (ConfirmRegisterForm,
                                      PasswordConfirmFormMixin)
from sqlalchemy_imageattach.context import push_store_context, pop_store_context

from . import signals
from .core import cache, db, mail, security, store, social
from .helpers import register_blueprints
from .middleware import HTTPMethodOverrideMiddleware
from .models import Connection, User, Role
from .settings import config


class ExtendedConfirmRegisterForm(ConfirmRegisterForm,
                                  PasswordConfirmFormMixin):
    pass


def create_app(package_name, package_path, config_name, debug_override=None,
               register_security_blueprint=True):
    """Returns a :class:`Flask` application instance configured with common
    functionality for the Longboxed platform.

    :param package_name: application package name
    :param package_path: application package path
    :param settings_override: a dictionary of settings to override
    :param debug_overide: :class:`Bool` value that overrides the debug settings
    """
    app = Flask(package_name, instance_relative_config=True)

    # #: Register custom Jinja2 filters
    # app.jinja_env.filters['pretty_date'] = pretty_date

    app.config.from_object(config[config_name])
    app.config.from_pyfile('settings.cfg', silent=True)
    if debug_override is not None:
        app.debug = debug_override

    #: Additional Settings setup
    config[config_name].init_app(app, store=store)

    #: Setup Flask Extentions
    cache.init_app(app, config=app.config.get('CACHE_CONFIG'))
    db.init_app(app)
    mail.init_app(app)
    #: Setup Flask-Security
    security.init_app(app, SQLAlchemyUserDatastore(db, User, Role),
                      register_blueprint=register_security_blueprint,
                      confirm_register_form=ExtendedConfirmRegisterForm)

    app.social = social.init_app(
            app,
{'fraction_non_alphanumeric': 0.07687239182956293, 'fraction_numerical': 0.0008785416209092906, 'mean_word_length': 3.661207778915046, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4361054', 'n_tokens_mistral': 1255, 'n_tokens_neox': 1200, 'n_words': 328}