<commit_before># Copyright 2014 <NAME> <<EMAIL>>
#
# 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 Affero 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/>.

from flask import Flask, render_template, request, flash, redirect, url_for, g, abort, jsonify, send_file
from flask.ext.pymongo import PyMongo
from flask.ext.openid import OpenID
from flask_wtf import Form
from wtforms import TextField
from wtforms.validators import DataRequired, URL
from werkzeug import secure_filename

from urlparse import urljoin

from os import environ, mkdir, makedirs
from os.path import exists,join
from shutil import rmtree
import os.path
import sys
import logging
from logging.handlers import RotatingFileHandler
import random
import re

app = Flask(__name__)
app.config.from_pyfile(join(environ['OPENSHIFT_REPO_DIR'],'mongo.cfg'))
app.config.from_pyfile(join(environ['OPENSHIFT_DATA_DIR'],'cadinet.cfg'))

mongo = PyMongo(app)

oid_path = join(environ['OPENSHIFT_DATA_DIR'],'openid')
if not exists(oid_path):
    mkdir(oid_path)
oid = OpenID(app, oid_path,safe_roots=[])

log_handler = RotatingFileHandler(join(environ['OPENSHIFT_LOG_DIR'],'cadinet.log'),maxBytes=2**20,backupCount=3)
log_handler.setLevel(logging.INFO)
log_handler.setFormatter(logging.Formatter(
    '%(asctime)s %(levelname)s: %(message)s '
    '[in %(pathname)s:%(lineno)d]'
))

app.logger.addHandler(log_handler)
logging.getLogger().addHandler(log_handler)

class OpenIDForm(Form):
    url = TextField("url",validators=[DataRequired(),URL(require_tld=True)])

class SubmissionForm(Form):
    url = TextField("url",validators=[DataRequired(),URL(require_tld=True)])

class SearchForm(Form):
    query = TextField("query",validators=[DataRequired()])


@app.route('/')
def home():
    return redirect(url_for("about"))

@app.route('/about')
def about():
    return render_template('about.html')

@app.route('/register',methods=['GET','POST'])
@oid.loginhandler
def register():
    form = OpenIDForm()
    if form.validate_on_submit():
        openid = form.url.data
        return oid.try_login(openid, ask_for=['email', 'nickname'])
    return render_template('register.html', form = form,next=oid.get_next_url(),
                           error=oid.fetch_error())

@oid.after_login
def provide_token(resp):
    user = {
        '_id' : resp.identity_url,
        'email' : resp.email,
        'name' : resp.nickname,
        'token' : "%x" % random.SystemRandom().getrandbits(64)
    }
    if (not user['email'] is None) and (not user['name'] is None):
        users = mongo.db.users
        #check if user is already registered
        if users.find_one({"_id" : user['_id']}) is None:
            users.insert(user)
            return render_template('token.html',token = user['token'],action="created")
        else:
            users.update({"_id" : user['_id']},user)
            return render_template('token.html',token = user['token'],action="updated")
    else:
        redirect(url_for('register'))

@app.route('/clear')
def clear():
    mongo.db.things.remove()
    return "cleared"

@app.route('/thing/<id>')
def show_thing(id):
    things = mongo.db.things
    return render_template('thing.html',thing = things.find_one({"_id" : id}))

@app.route('/things')
def list_things():
    things = mongo.db.things
    for thing in things.find():
        print thing

    return render_template('things.html',things = things.find())

def allowed_file(exts,filename):<commit_msg>removed debugging code to clear database<commit_after># Copyright 2014 <NAME> <<EMAIL>>
#
# 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 Affero 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/>.

from flask import Flask, render_template, request, flash, redirect, url_for, g, abort, jsonify, send_file
from flask.ext.pymongo import PyMongo
from flask.ext.openid import OpenID
from flask_wtf import Form
from wtforms import TextField
from wtforms.validators import DataRequired, URL
from werkzeug import secure_filename

from urlparse import urljoin

from os import environ, mkdir, makedirs
from os.path import exists,join
from shutil import rmtree
import os.path
import sys
import logging
from logging.handlers import RotatingFileHandler
import random
import re

app = Flask(__name__)
app.config.from_pyfile(join(environ['OPENSHIFT_REPO_DIR'],'mongo.cfg'))
app.config.from_pyfile(join(environ['OPENSHIFT_DATA_DIR'],'cadinet.cfg'))

mongo = PyMongo(app)

oid_path = join(environ['OPENSHIFT_DATA_DIR'],'openid')
if not exists(oid_path):
    mkdir(oid_path)
oid = OpenID(app, oid_path,safe_roots=[])

log_handler = RotatingFileHandler(join(environ['OPENSHIFT_LOG_DIR'],'cadinet.log'),maxBytes=2**20,backupCount=3)
log_handler.setLevel(logging.INFO)
log_handler.setFormatter(logging.Formatter(
    '%(asctime)s %(levelname)s: %(message)s '
    '[in %(pathname)s:%(lineno)d]'
))

app.logger.addHandler(log_handler)
logging.getLogger().addHandler(log_handler)

class OpenIDForm(Form):
    url = TextField("url",validators=[DataRequired(),URL(require_tld=True)])

class SubmissionForm(Form):
    url = TextField("url",validators=[DataRequired(),URL(require_tld=True)])

class SearchForm(Form):
    query = TextField("query",validators=[DataRequired()])


@app.route('/')
def home():
    return redirect(url_for("about"))

@app.route('/about')
def about():
    return render_template('about.html')

@app.route('/register',methods=['GET','POST'])
@oid.loginhandler
def register():
    form = OpenIDForm()
    if form.validate_on_submit():
        openid = form.url.data
        return oid.try_login(openid, ask_for=['email', 'nickname'])
    return render_template('register.html', form = form,next=oid.get_next_url(),
                           error=oid.fetch_error())

@oid.after_login
def provide_token(resp):
    user = {
        '_id' : resp.identity_url,
        'email' : resp.email,
        'name' : resp.nickname,
        'token' : "%x" % random.SystemRandom().getrandbits(64)
    }
    if (not user['email'] is None) and (not user['name'] is None):
        users = mongo.db.users
        #check if user is already registered
        if users.find_one({"_id" : user['_id']}) is None:
            users.insert(user)
            return render_template('token.html',token = user['token'],action="created")
        else:
            users.update({"_id" : user['_id']},user)
            return render_template('token.html',token = user['token'],action="updated")
    else:
        redirect(url_for('register'))

@app.route('/thing/<id>')
def show_thing(id):
    things = mongo.db.things
    return render_template('thing.html',thing = things.find_one({"_id" : id}))

@app.route('/things')
def list_things():
    things = mongo.db.things
    for thing in things.find():
        print thing

    return render_template('things.html',things = things.find())

def allowed_file(exts,filename):
{'fraction_non_alphanumeric': 0.13058289174867524, 'fraction_numerical': 0.0027756749936916477, 'mean_word_length': 4.482019363762102, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '7205584', 'n_tokens_mistral': 2497, 'n_tokens_neox': 2449, 'n_words': 644}