<commit_before>"""
Module to contain all the project's Flask server plumbing.
"""

from json import dumps

from flask import Flask, make_response, render_template, request

from bitshift import assets
from bitshift.database import Database
from bitshift.query import parse_query, QueryParseException

app = Flask(__name__)
app.config.from_object("bitshift.config")

app_env = app.jinja_env
app_env.line_statement_prefix = "="
app_env.globals.update(assets=assets)

database = Database()

@app.route("/")
def index():
    return render_template("index.html", typeahead_languages=languages.LANGS)

@app.route("/search.json")
def search():
    def reply(json):
        resp = make_response(dumps(json))
        resp.mimetype = "application/json"
        return resp

    query, page = request.args.get("q"), request.args.get("p", 1)
    if not query:
        return reply({"error": "No query given"})
    try:
        tree = parse_query(query)
    except QueryParseException as exc:
        return reply({"error": exc.args[0]})
    try:
        page = int(page)
    except ValueError:
        return reply({"error": u"Invalid page number: %s" % page})
    count, codelets = database.search(tree, page)
    results = [clt.serialize() for clt in codelets]
    return reply({"count": count, "results": results})

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

@app.route("/developers")
def developers():
    return render_template("developers.html")

if __name__ == "__main__":
    app.run(debug=True)
<commit_msg>Fix missing import.<commit_after>"""
Module to contain all the project's Flask server plumbing.
"""

from json import dumps

from flask import Flask, make_response, render_template, request

from bitshift import assets
from bitshift.database import Database
from bitshift.languages import LANGS
from bitshift.query import parse_query, QueryParseException

app = Flask(__name__)
app.config.from_object("bitshift.config")

app_env = app.jinja_env
app_env.line_statement_prefix = "="
app_env.globals.update(assets=assets)

database = Database()

@app.route("/")
def index():
    return render_template("index.html", typeahead_languages=LANGS)

@app.route("/search.json")
def search():
    def reply(json):
        resp = make_response(dumps(json))
        resp.mimetype = "application/json"
        return resp

    query, page = request.args.get("q"), request.args.get("p", 1)
    if not query:
        return reply({"error": "No query given"})
    try:
        tree = parse_query(query)
    except QueryParseException as exc:
        return reply({"error": exc.args[0]})
    try:
        page = int(page)
    except ValueError:
        return reply({"error": u"Invalid page number: %s" % page})
    count, codelets = database.search(tree, page)
    results = [clt.serialize() for clt in codelets]
    return reply({"count": count, "results": results})

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

@app.route("/developers")
def developers():
    return render_template("developers.html")

if __name__ == "__main__":
    app.run(debug=True)

{'fraction_non_alphanumeric': 0.1316382362407467, 'fraction_numerical': 0.001287415513356936, 'mean_word_length': 4.045454545454546, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 3, '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': '3323234', 'n_tokens_mistral': 965, 'n_tokens_neox': 953, 'n_words': 254}