<commit_before>import flask
import json
import os
from werkzeug import secure_filename

#DEBUGGING
import glob

from donut.modules.uploads import blueprint, helpers


@blueprint.route('/lib/<path:url>')
def display(url):
    page = helpers.readPage(url.lower())

    return flask.render_template('page.html', page=page, title=url)


@blueprint.route('/uploads', methods=['GET', 'POST'])
def uploads():
    if flask.request.method == 'POST':
        if 'file' not in flask.request.files:
            flask.flash('No file part')
            return flask.render_template('uploads.html')
        file = flask.request.files['file']

        if file.filename == '':
            flask.flash('No selected file')
            return flask.redirect(request.url)
        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            file.save(
                os.path.join(flask.current_app.config['UPLOAD_FOLDER'],
                             filename))
            return flask.redirect(
                flask.url_for('uploads.uploaded_file', filename=filename))
    return flask.render_template('uploads.html')


@blueprint.route('/uploaded_file/<filename>', methods = ['GET'])
def uploaded_file(filename):
    print(filename)
    print(flask.current_app.config['UPLOAD_FOLDER'])
    print(glob.glob(flask.current_app.config['UPLOAD_FOLDER']+'/*'))
    return flask.send_from_directory(flask.current_app.config['UPLOAD_FOLDER'],
    filename, as_attachment= True)

ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])

@blueprint.route('/uploaded_list')
def uploadedList():
    links = glob.glob(flask.current_app.config['UPLOAD_FOLDER']+'/*')
    for i in range(links):
        links[i] = (flask.url_for('uploads.uploaded_file', filename=links[i]), links[i])
    flask.render_template('uploaded_list.html', links=links)

def allowed_file(filename):
    return '.' in filename and \
           filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS


@blueprint.route('/_uploader', methods=['POST'])
def upload_file():
    if request.method == 'POST':<commit_msg>Added error message for unsupported file extension<commit_after>import flask
import json
import os
from werkzeug import secure_filename

#DEBUGGING
import glob

from donut.modules.uploads import blueprint, helpers


@blueprint.route('/lib/<path:url>')
def display(url):
    page = helpers.readPage(url.lower())

    return flask.render_template('page.html', page=page, title=url)


@blueprint.route('/uploads', methods=['GET', 'POST'])
def uploads():
    if flask.request.method == 'POST':
        if 'file' not in flask.request.files:
            flask.flash('No file part')
            return flask.render_template('uploads.html')
        file = flask.request.files['file']

        if file.filename == '':
            flask.flash('No selected file')
            return flask.redirect(request.url)
        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            file.save(os.path.join(flask.current_app.config['UPLOAD_FOLDER'],
                             filename))
            return flask.redirect(
                flask.url_for('uploads.uploaded_file', filename=filename))
        else:
            flask.flash('Unsupported filetype')
    return flask.render_template('uploads.html')


@blueprint.route('/uploaded_file/<filename>', methods = ['GET'])
def uploaded_file(filename):
    print(filename)
    print(flask.current_app.config['UPLOAD_FOLDER'])
    print(glob.glob(flask.current_app.config['UPLOAD_FOLDER']+'/*'))
    return flask.send_from_directory(flask.current_app.config['UPLOAD_FOLDER'],
                                     filename, as_attachment=True)

ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])

@blueprint.route('/uploaded_list')
def uploadedList():
    links = glob.glob(flask.current_app.config['UPLOAD_FOLDER']+'/*')
    for i in range(links):
        links[i] = (flask.url_for('uploads.uploaded_file', filename=links[i]), links[i])
    flask.render_template('uploaded_list.html', links=links)

def allowed_file(filename):
    return '.' in filename and \
           filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS


@blueprint.route('/_uploader', methods=['POST'])
def upload_file():
    if request.method == 'POST':
{'fraction_non_alphanumeric': 0.14613970588235295, 'fraction_numerical': 0.0009191176470588235, 'mean_word_length': 3.450920245398773, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5372282', 'n_tokens_mistral': 1381, 'n_tokens_neox': 1350, 'n_words': 248}