<commit_before>from flask import Flask, render_template, request, redirect, abort, url_for, \
                  make_response

from mmmpaste import db
from mmmpaste.forms import NewPaste

app = Flask(__name__)

@app.teardown_request
def shutdown_session(exception = None):
    db.session.remove()


@app.route("/")
def root():
    return redirect(url_for("new_paste"))


@app.route("/p/<id>")
def get_paste(id):
    paste = db.get_paste(id)

    if paste is None:
        abort(404)

    return render_template("paste.html", paste = paste)


@app.route("/new", methods = ["POST", "GET"])
def new_paste():
    form = NewPaste(request.form)
    if request.method == "POST" and form.validate():
        id = db.new_paste(form.content.data, form.filename.data,
                          form.highlight.data, form.convert_tabs.data)
        return redirect(url_for("get_paste", id = id))

    return render_template("new.html", form = form)


@app.route("/history")
def history():
    pass


@app.route("/about")
def about():
    pass


@app.route("/p/<id>/raw")
def get_raw_paste(id):
    paste = db.get_paste(id)

    if paste is None:
        return abort(404)

    response = make_response(str(paste.content))
    response.mimetype = "text/plain"
    return response


@app.route("/p/<id>/download")
def download_paste(id):
    paste = db.get_paste(id)

    if paste is None:
        return abort(404)

    filename = paste.filename

    if filename is None:
        filename = "paste-%s.txt" % paste.id_b62

    response = make_response(str(paste.content))
    response.headers["Content-Disposition"] = "attachment; filename=%s" % filename
    return response


@app.route("/p/<id>/clone")
def clone_paste(id):
    paste = db.get_paste(id)

    if paste is None:
        return abort(404)

    form = NewPaste()
    form.content.data = str(paste.content)
    return render_template("new.html", form = form)


@app.route("/latest")
def get_latest_paste():
    paste = db.get_paste()
    return render_template("paste.html", paste = paste)<commit_msg>Only import the forms module.<commit_after>from flask import Flask, render_template, request, redirect, abort, url_for, \
                  make_response

from mmmpaste import db
from mmmpaste import forms

app = Flask(__name__)

@app.teardown_request
def shutdown_session(exception = None):
    db.session.remove()


@app.route("/")
def root():
    return redirect(url_for("new_paste"))


@app.route("/p/<id>")
def get_paste(id):
    paste = db.get_paste(id)

    if paste is None:
        abort(404)

    return render_template("paste.html", paste = paste)


@app.route("/new", methods = ["POST", "GET"])
def new_paste():
    form = forms.NewPaste(request.form)
    if request.method == "POST" and form.validate():
        id = db.new_paste(form.content.data, form.filename.data,
                          form.highlight.data, form.convert_tabs.data)
        return redirect(url_for("get_paste", id = id))

    return render_template("new.html", form = form)


@app.route("/history")
def history():
    pass


@app.route("/about")
def about():
    pass


@app.route("/p/<id>/raw")
def get_raw_paste(id):
    paste = db.get_paste(id)

    if paste is None:
        return abort(404)

    response = make_response(str(paste.content))
    response.mimetype = "text/plain"
    return response


@app.route("/p/<id>/download")
def download_paste(id):
    paste = db.get_paste(id)

    if paste is None:
        return abort(404)

    filename = paste.filename

    if filename is None:
        filename = "paste-%s.txt" % paste.id_b62

    response = make_response(str(paste.content))
    response.headers["Content-Disposition"] = "attachment; filename=%s" % filename
    return response


@app.route("/p/<id>/clone")
def clone_paste(id):
    paste = db.get_paste(id)

    if paste is None:
        return abort(404)

    form = forms.NewPaste()
    form.content.data = str(paste.content)
    return render_template("new.html", form = form)


@app.route("/latest")
def get_latest_paste():
    paste = db.get_paste()
    return render_template("paste.html", paste = paste)
{'fraction_non_alphanumeric': 0.14136507165411707, 'fraction_numerical': 0.00680106873937333, 'mean_word_length': 3.180710659898477, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '1251795', 'n_tokens_mistral': 1421, 'n_tokens_neox': 1317, 'n_words': 305}