Exemple #1
0
def do_paste(raw=None, lexer="text", expiry="1week", src="web"):
    lexers = list_languages()
    errors = []

    if not lexer in lexers:
        errors.append("lexer")

    if not raw:
        errors.append("raw")

    expiries = {"1day": timedelta(days=1),
                "1week": timedelta(days=7),
                "1month": timedelta(days=30),
                "never": None}

    if not expiry in expiries:
        errors.append("expiry")
        return template(message="Please don't make up expiry dates.")
    else:
        expiry = expiries[expiry]

    if errors:
        raise ValidationException(errors)
    else:
        return Paste(raw, lexer=lexer, expiry=expiry, src=src)
Exemple #2
0
def paste():
    lexer  = request.form["lexer"]
    raw    = request.form["code"]
    expiry = request.form["expiry"]

    template = partial(render_template, "new.html", lexer=lexer,
            lexers=list_languages(), pagetitle="new")

    try:
        paste = do_paste(raw, lexer, expiry)
    except ValidationException:
        return template(message="It didn't validate!")

    session.add(paste)
    session.commit()

    response = redirect(url_for("show", paste_id=paste.paste_id))
    response.set_cookie("removal", str(paste.removal_id), path=url_for("show", paste_id=paste.paste_id))

    return response
Exemple #3
0
def index(lexer=""):
    return render_template("new.html", lexer=lexer,
               lexers=list_languages(), pagetitle="new")