<commit_before>from flask import (
    abort,
    Blueprint,
    redirect,
    render_template,
    url_for
)

from PyPaste.forms import NewPaste
from PyPaste.models.pastes import Paste

public = Blueprint('public', __name__, template_folder='templates')


@public.route('/', methods=['GET', 'POST'])
def index():
    form = NewPaste()
    if form.validate_on_submit():
        # WTForms passes '' for empty text values,
        # this lamba switches them to None
        f = lambda s: s if s != '' else None
        vals = {
            'text': form.text.data,
            'title': f(form.title.data),
            'language': f(form.language.data),
            'password': f(<PASSWORD>),
            'unlisted': f(form.unlisted.data)
        }
        paste = Paste.new(**vals)
        if paste is None:
            return redirect(url_for('public.index'))
        else:
            url = url_for('public.view_paste', paste_id=paste['id'])
            return redirect(url)

    return render_template('index.html', form=form)


@public.route('/p/<int:paste_id>')
def view_paste(paste_id):
    paste = Paste.by_id(paste_id)
    if paste is None:
        abort(404)<commit_msg>Don't allow unlisted pastes to be accessed via id<commit_after>from flask import (
    abort,
    Blueprint,
    redirect,
    render_template,
    url_for
)

from PyPaste.forms import NewPaste
from PyPaste.models.pastes import Paste

public = Blueprint('public', __name__, template_folder='templates')


@public.route('/', methods=['GET', 'POST'])
def index():
    form = NewPaste()
    if form.validate_on_submit():
        # WTForms passes '' for empty text values,
        # this lamba switches them to None
        f = lambda s: s if s != '' else None
        vals = {
            'text': form.text.data,
            'title': f(form.title.data),
            'language': f(form.language.data),
            'password': f(<PASSWORD>.password.data),
            'unlisted': f(form.unlisted.data)
        }
        paste = Paste.new(**vals)
        if paste is None:
            return redirect(url_for('public.index'))
        else:
            url = url_for('public.view_paste', paste_id=paste['id'])
            return redirect(url)

    return render_template('index.html', form=form)


@public.route('/p/<int:paste_id>')
def view_paste(paste_id):
    paste = Paste.by_id(paste_id)
    if paste is None or paste['unlisted']:
        abort(404)
{'fraction_non_alphanumeric': 0.13165497317375155, 'fraction_numerical': 0.0024762690879075525, 'mean_word_length': 2.507959479015919, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2246922', 'n_tokens_mistral': 780, 'n_tokens_neox': 745, 'n_words': 183}