def get_homepage(req, res): return vilo.escfmt( """ <h2>TestBin: In-Memory Pastebin</h2> <p> Visit <a href="/compose">/compose</a> to compose a new paste. </p> <p> Go to /paste/{Paste-ID-here} to view a paste. </p> <pre>Paste IDs: %s</pre> """, json.dumps(list(pasteMap.keys()), indent=4))
def post_echo(req, res): tpldata = { "foo": req.fdata.get("foo") or "", "bar": req.fdata.get("bar") or "", } pprint.pprint(req.fdata) return vilo.escfmt( """ Foo: %(foo)s<br><br> Bar: %(bar)s<br><br> <a href="javascript: history.back();">< Back</a> """, tpldata)
def get_paste(req, res): pid = req.wildcards[0] if not (pid.isdigit() and int(pid) in pasteMap): raise vilo.error("<h2>No such paste.</h2>", 404) paste = pasteMap[int(pid)] return vilo.escfmt( """ <pre>Paste ID: %(id)s</pre> <h1>%(title)s</h1> <pre>%(body)s</h1> <hr> <br> <p><a href="/">< Home</a></p> """, paste)
def get_echo(req, res): tpldata = { "foo": req.qdata.get("foo") or "", "bar": req.qdata.get("bar") or "", } return vilo.escfmt( """ <h2>Echo Form</h2> <form method="POST" enctype="multipart/form-data"> <input type="text" name="foo" value="%(foo)s" placeholder="Foo"><br> <input type="text" name="bar" value="%(bar)s" placeholder="Bar"><br> <input type="file" name="fup"><br> <button>Submit</button> <hr> </form> <h3> Foo: %(foo)s<br><br> Bar: %(bar)s<br><br> <a href="javascript: history.back();">< Back</a> """, tpldata)
def post_compose(req, res): title = req.fdata.get("title") or "(Blank Title)" body = req.fdata.get("body") or "(Blank Body)" pasteId = len(pasteMap) + 1 pasteMap[pasteId] = vilo.dotsi.fy({ "id": pasteId, "title": title, "body": body, }) assert len(pasteMap) == pasteId return vilo.escfmt( """ <h3>Paste Created!</h3> <p> Visit <a href="/paste/%s">/paste/%s</a> to view your paste, or <a href="/compose">/compose</a> to compose another. </p> <hr> <br> <p><a href="/">< Home</a></p> """, [pasteId, pasteId])
def get_foo(req, res): return vilo.escfmt("<code>%s</code>", repr(req.wildcards[0]))
def get_setCookie(req, res): name, val = req.matched.groups() res.setCookie(name, val) return vilo.escfmt("Set cookie:<br>%s = %s", (name, val))
def get_hello_name(req, res): name = req.matched.groups()[0] print("name = ", name) return vilo.escfmt("Hello, %s!", name.title())
def get_hi(req, res): fname, lname = req.wildcards fullName = "%s %s" % (fname, lname) return vilo.escfmt("Hello, %s!", fullName.title())