<commit_before># Copyright 2014 <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from flask import Flask, g
from inspect import getmembers, isfunction
from happymongo import HapPyMongo
from flask.ext import restful
from config import config
from adminbp import bp as admin_bp


import context_functions
import template_filters
import views
import re


def create_app(testing=None):
    app = Flask(__name__)
    if testing:
        config.TESTING = True
        m = re.search('_test', config.MONGO_DATABASE)
        if not m:
            config.MONGO_DATABASE = '%s_test' % config.MONGO_DATABASE

        config.ADMIN = 'rusty.shackelford'

    app.config.from_object(config)
    app.register_blueprint(admin_bp, url_prefix='/admin')
    mongo, db = HapPyMongo(config)
    api = restful.Api(app)
    custom_filters = {
        name: function for name, function in getmembers(template_filters)
        if isfunction(function)
    }
    app.jinja_env.filters.update(custom_filters)
    app.context_processor(context_functions.utility_processor)

    @app.before_request
    def before_request():
        g.db = db

    views.BaseView.register(app)
    views.LookupView.register(app)
    views.ManagementView.register(app)

    api.add_resource(
        views.AccountAPI,
        '/account/<account_id>/<region>',
        endpoint='account'
    )
    api.add_resource(views.TaskAPI, '/task/<task_id>', endpoint='task')
    api.add_resource(
        views.ServerAPI,
        '/account/<account_id>/<region>/server/<server_id>',
        endpoint='server'
    )
    return app, db<commit_msg>Setup auth and admin extension and add logging in setup<commit_after># Copyright 2014 <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from flask import Flask, g
from flask.ext.cloudadmin import Admin
from flask.ext.cloudauth import CloudAuth
from inspect import getmembers, isfunction
from happymongo import HapPyMongo
from datetime import timedelta
from flask.ext import restful
from config import config


import context_functions
import template_filters
import defaults
import logging
import views
import re


def create_app(db_name=None):
    app = Flask(__name__)
    app.config.from_object(config)
    if db_name:
        config.MONGO_DATABASE = db_name

    Admin(app)
    mongo, db = HapPyMongo(config)
    api = restful.Api(app)
    app.permanent_session_lifetime = timedelta(hours=2)
    auth = CloudAuth(app, db)

    custom_filters = {
        name: function for name, function in getmembers(template_filters)
        if isfunction(function)
    }
    app.jinja_env.filters.update(custom_filters)
    app.context_processor(context_functions.utility_processor)

    @app.before_first_request
    def logger():
        if not app.debug:
            app.logger.addHandler(logging.StreamHandler())
            app.logger.setLevel(logging.INFO)

    @app.before_request
    def before_request():
        g.db, g.auth = db, auth

    defaults.application_initialize(db, app)
    views.BaseView.register(app)
    views.LookupView.register(app)
    views.ManagementView.register(app)

    api.add_resource(
        views.AccountAPI,
        '/account/<account_id>/<region>',
        endpoint='account'
    )
    api.add_resource(views.TaskAPI, '/task/<task_id>', endpoint='task')
    api.add_resource(
        views.ServerAPI,
        '/account/<account_id>/<region>/server/<server_id>',
        endpoint='server'
    )
    if db_name:
        return app, db
    else:
        return app
{'fraction_non_alphanumeric': 0.0873440285204991, 'fraction_numerical': 0.003787878787878788, 'mean_word_length': 3.418307086614173, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3597298', 'n_tokens_mistral': 1333, 'n_tokens_neox': 1299, 'n_words': 386}