示例#1
0
def main():
    args = sys.argv[1:]

    if args:
        if args[0] == "init_db":
            Base.metadata.create_all(engine)

        if args[0] == "add":
            paste = Paste("<html>hi</html>", lexer="html", expiry=timedelta(seconds=5))

            session.add(paste)
            session.commit()

        if args[0] == "remove":
            paste = session.query(Paste).filter(Paste.id == int(args[1])).first()

            session.delete(paste)
            session.commit()

        if args[0] == "list":
            for paste in session.query(Paste).all():
                print(paste)

        if args[0] == "reap":
            pastes = session.query(Paste).filter(Paste.exp_date < datetime.utcnow()).all()

            for paste in pastes:
                session.delete(paste)
            session.commit()

            print("Reaped {} expired pastes".format(len(pastes)))
示例#2
0
文件: web.py 项目: gandaro/pinnwand
def paste_json():
    lexer  = request.form["lexer"]
    raw    = request.form["code"]
    expiry = request.form["expiry"]

    try:
        paste = do_paste(raw, lexer, expiry, "json")
    except ValidationException:
        return "it didn't validate", 500

    session.add(paste)
    session.commit()

    response = make_response(json.dumps({"paste_id": paste.paste_id,
                                         "removal_id": paste.removal_id}))
    response.headers["content-type"] = "application/json"

    return response
示例#3
0
文件: web.py 项目: nosklo/pinnwand
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