<commit_before># This file is part of victims-web.
#
# Copyright (C) 2013 The Victims Project
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""
Module which results with a ready to use wsgi application.
"""

import logging.config
import os

from flask import Flask, render_template
from flask.ext.mongoengine import MongoEngine, MongoEngineSessionInterface
from flask.ext.seasurf import SeaSurf

from victims_web.admin import administration_setup
from victims_web.blueprints.service_v1 import v1
from victims_web.blueprints.service_v2 import v2, SUBMISSION_ROUTES
from victims_web.blueprints.ui import ui
from victims_web.blueprints.auth import auth

from victims_web.cache import cache
from victims_web.handlers.security import setup_security
from victims_web.handlers.sslify import VSSLify

# Set up the application
app = Flask('victims_web')

# SSLify
sslify = VSSLify(app)

# CSRF protection
csrf = SeaSurf(app)

# configuration
app.config.from_object('victims_web.config')

# logging
logging.basicConfig(
    filename=os.path.join(app.config.get('LOG_FOLDER'), 'server.log'),
    format='%(asctime)s - %(levelname)s: %(message)s',
    datefmt='%a %b %d %Y %H:%M:%S %Z',
    level=app.config['LOG_LEVEL'],
)
app._logger = app.config.get('LOGGER')

# debug enhancements
if app.debug and not app.testing:
    try:
        from flask_debugtoolbar import DebugToolbarExtension
        toolbar = DebugToolbarExtension(app)
    except Exception as e:
        # Helpful for debugging but not needed
        app.logger.debug('Skipping Debug Toolbar')
        pass

# mongodb and sessions
app.db = MongoEngine(app)
app.session_interface = MongoEngineSessionInterface(app.db)

# cache
cache.init_app(app)

# admin setup
administration_setup(app)

# CSRF exemptions
for submit in SUBMISSION_ROUTES:
    csrf.exempt(submit)

<commit_msg>Application configuration should happen after database is setup<commit_after># This file is part of victims-web.
#
# Copyright (C) 2013 The Victims Project
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""
Module which results with a ready to use wsgi application.
"""

import logging.config
import os

from flask import Flask, render_template
from flask.ext.mongoengine import MongoEngine, MongoEngineSessionInterface
from flask.ext.seasurf import SeaSurf


# Set up the application
app = Flask('victims_web')

# configuration
app.config.from_object('victims_web.config')

# CSRF protection
csrf = SeaSurf(app)

# logging
logging.basicConfig(
    filename=os.path.join(app.config.get('LOG_FOLDER'), 'server.log'),
    format='%(asctime)s - %(levelname)s: %(message)s',
    datefmt='%a %b %d %Y %H:%M:%S %Z',
    level=app.config['LOG_LEVEL'],
)
app._logger = app.config.get('LOGGER')

# debug enhancements
if app.debug and not app.testing:
    try:
        from flask_debugtoolbar import DebugToolbarExtension
        toolbar = DebugToolbarExtension(app)
    except Exception as e:
        # Helpful for debugging but not needed
        app.logger.debug('Skipping Debug Toolbar')
        pass

# mongodb and sessions
app.db = MongoEngine(app)
app.session_interface = MongoEngineSessionInterface(app.db)

# victims_web setup
# this happens after basic setup to facilitate database availability
from victims_web.admin import administration_setup
from victims_web.blueprints.service_v1 import v1
from victims_web.blueprints.service_v2 import v2, SUBMISSION_ROUTES
from victims_web.blueprints.ui import ui
from victims_web.blueprints.auth import auth

from victims_web.cache import cache
from victims_web.handlers.security import setup_security
from victims_web.handlers.sslify import VSSLify

# Custom SSLify
sslify = VSSLify(app)

# cache
cache.init_app(app)

# admin setup
administration_setup(app)

# CSRF exemptions
for submit in SUBMISSION_ROUTES:
    csrf.exempt(submit)


{'fraction_non_alphanumeric': 0.07979253939756632, 'fraction_numerical': 0.003590664272890485, 'mean_word_length': 4.6527621195039455, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7635306', 'n_tokens_mistral': 1503, 'n_tokens_neox': 1464, 'n_words': 525}