<commit_before>from bottle import Bottle, hook, HTTPResponse, redirect, request, route, run, TEMPLATE_PATH, jinja2_template as template, static_file, debug
from beaker.middleware import SessionMiddleware
from cork import Cork
from cork.backends import MongoDBBackend
from gunicorn.app.base import Application
from libraries.utils import JSONHelper, strToId, CSVHelper
from models.address import AddressModel
import logging
import os

logging.basicConfig(format='localhost - - [%(asctime)s] %(message)s', level=logging.DEBUG)
log = logging.getLogger(__name__)
debug(True)

MODULEPATH = os.path.dirname(__file__)
TEMPLATE_PATH.append(os.path.join(MODULEPATH,"views"))
LOGIN_PATH = '/login'
CHANGE_PASSWORD_PATH = '/change_password'
VALIDATE_REGISTRATION_PATH = '/validate_registration'
MONGO_URL = os.environ.get('MONGOHQ_URL')
MONGO_DB = os.environ.get('MONGOHQ_DB')
EMAIL_PASS = os.environ.get('EMAIL_PASSWORD')

mb = MongoDBBackend(MONGO_DB, MONGO_URL)
loginPlugin = Cork(backend=mb, email_sender='<EMAIL>', smtp_url='starttls://<EMAIL>:' + EMAIL_PASS + '@smtp.gmail.com:587')

class AddressServer(Application):
    """Strongly borrowed from:  http://damianzaremba.co.uk/2012/08/running-a-wsgi-app-via-gunicorn-from-python/"""

    def __init__(self, options={}):
        self.usage = None
        self.callable = None
        self.prog = None
        self.options = options
        self.do_load_config()
        super(AddressServer, self).__init__()
        self.app = Bottle()
        self.add_routes()
        self.add_middleware()

    def add_middleware(self):
        session_opts = {
            'session.cookie_expires': True,
            'session.encrypt_key': 'please use a random key and keep it secret!',
            'session.httponly': True,
            'session.timeout': 3600 * 24,  # 1 day
            'session.type': 'cookie',
            'session.validate_key': True,
        }
        self.app = SessionMiddleware(self.app, session_opts)

    def add_routes(self):
        self.app.route(LOGIN_PATH, 'GET', callback=get_login)
        self.app.route(LOGIN_PATH, 'POST', callback=post_login)
        self.app.route('/logout', 'GET', callback=logout)
        self.app.route('/register', 'POST', callback=post_register)
        self.app.route(VALIDATE_REGISTRATION_PATH + '/<registration_code>', 'GET', callback=validate_registration)
        self.app.route(CHANGE_PASSWORD_PATH + '/<reset_code>', 'GET', callback=get_change_password)
        self.app.route(CHANGE_PASSWORD_PATH + , 'POST', callback=post_change_password)

        self.app.route('/', 'GET', callback=index, apply=check_login)
        self.app.route('/addresses', 'GET', callback=get_addresses, apply=check_login)
        self.app.route('/addresses', 'POST', callback=post_addresses, apply=check_login)
        self.app.route('/addresses', 'PUT', callback=put_addresses, apply=check_login)
        self.app.route('/addresses/<deleteId>', 'DELETE', callback=delete_addresses, apply=check_login)
        self.app.route('/csv', 'GET', callback=csv_export, apply=check_login)
        self.app.route('/importcsv', 'GET', callback=csv_import, apply=check_login)

        self.app.route('/js/<filename>', 'GET', callback=js_static)
        self.app.route('/css/<filename>', 'GET', callback=css_static)

    def init(self, *args):
        cfg = {}
        for k,v in self.options.items():
            if k.lower() in self.cfg.settings and v is not None:
                cfg[k.lower()] = v
        return cfg

    def load(self):
        return self.app
<commit_msg>Fix path mistake<commit_after>from bottle import Bottle, hook, HTTPResponse, redirect, request, route, run, TEMPLATE_PATH, jinja2_template as template, static_file, debug
from beaker.middleware import SessionMiddleware
from cork import Cork
from cork.backends import MongoDBBackend
from gunicorn.app.base import Application
from libraries.utils import JSONHelper, strToId, CSVHelper
from models.address import AddressModel
import logging
import os

logging.basicConfig(format='localhost - - [%(asctime)s] %(message)s', level=logging.DEBUG)
log = logging.getLogger(__name__)
debug(True)

MODULEPATH = os.path.dirname(__file__)
TEMPLATE_PATH.append(os.path.join(MODULEPATH,"views"))
LOGIN_PATH = '/login'
CHANGE_PASSWORD_PATH = '/change_password'
VALIDATE_REGISTRATION_PATH = '/validate_registration'
MONGO_URL = os.environ.get('MONGOHQ_URL')
MONGO_DB = os.environ.get('MONGOHQ_DB')
EMAIL_PASS = os.environ.get('EMAIL_PASSWORD')

mb = MongoDBBackend(MONGO_DB, MONGO_URL)
loginPlugin = Cork(backend=mb, email_sender='<EMAIL>', smtp_url='starttls://<EMAIL>:' + EMAIL_PASS + '@smtp.gmail.com:587')

class AddressServer(Application):
    """Strongly borrowed from:  http://damianzaremba.co.uk/2012/08/running-a-wsgi-app-via-gunicorn-from-python/"""

    def __init__(self, options={}):
        self.usage = None
        self.callable = None
        self.prog = None
        self.options = options
        self.do_load_config()
        super(AddressServer, self).__init__()
        self.app = Bottle()
        self.add_routes()
        self.add_middleware()

    def add_middleware(self):
        session_opts = {
            'session.cookie_expires': True,
            'session.encrypt_key': 'please use a random key and keep it secret!',
            'session.httponly': True,
            'session.timeout': 3600 * 24,  # 1 day
            'session.type': 'cookie',
            'session.validate_key': True,
        }
        self.app = SessionMiddleware(self.app, session_opts)

    def add_routes(self):
        self.app.route(LOGIN_PATH, 'GET', callback=get_login)
        self.app.route(LOGIN_PATH, 'POST', callback=post_login)
        self.app.route('/logout', 'GET', callback=logout)
        self.app.route('/register', 'POST', callback=post_register)
        self.app.route(VALIDATE_REGISTRATION_PATH + '/<registration_code>', 'GET', callback=validate_registration)
        self.app.route(CHANGE_PASSWORD_PATH + '/<reset_code>', 'GET', callback=get_change_password)
        self.app.route(CHANGE_PASSWORD_PATH, 'POST', callback=post_change_password)

        self.app.route('/', 'GET', callback=index, apply=check_login)
        self.app.route('/addresses', 'GET', callback=get_addresses, apply=check_login)
        self.app.route('/addresses', 'POST', callback=post_addresses, apply=check_login)
        self.app.route('/addresses', 'PUT', callback=put_addresses, apply=check_login)
        self.app.route('/addresses/<deleteId>', 'DELETE', callback=delete_addresses, apply=check_login)
        self.app.route('/csv', 'GET', callback=csv_export, apply=check_login)
        self.app.route('/importcsv', 'GET', callback=csv_import, apply=check_login)

        self.app.route('/js/<filename>', 'GET', callback=js_static)
        self.app.route('/css/<filename>', 'GET', callback=css_static)

    def init(self, *args):
        cfg = {}
        for k,v in self.options.items():
            if k.lower() in self.cfg.settings and v is not None:
                cfg[k.lower()] = v
        return cfg

    def load(self):
        return self.app

{'fraction_non_alphanumeric': 0.13573446327683616, 'fraction_numerical': 0.00480225988700565, 'mean_word_length': 3.686300463269358, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '1264672', 'n_tokens_mistral': 2296, 'n_tokens_neox': 2239, 'n_words': 430}