Skip to content

Instantly share code, notes, and snippets.

@petrblahos
Created December 6, 2012 19:31
Show Gist options
  • Save petrblahos/4227564 to your computer and use it in GitHub Desktop.
Save petrblahos/4227564 to your computer and use it in GitHub Desktop.
Slightly less tiny webob app
import time
from webob import Request, Response
from webob import exc
def slow_generator():
yield "<html><body><h1>Starting</h1>\n"
for i in range(10):
yield("%s: Hello!!! Hello!!! Hello!!! Hello!!! Hello!!! Hello!!!<br>\n" % (i+1))
time.sleep(0.4)
yield("Finito")
yield("</body></html>")
class TinyApp(object):
def slowtest(self):
resp = Response()
resp.app_iter = slow_generator()
return resp
def index(self):
resp = Response()
resp.body = """<html><body><h1>WSGI WebOb Test</h1>
<a href="slowtest">Click here</a> to try a slow generator.<br>
</body></html>
"""
return resp
def __call__(self, environ, start_response):
req = Request(environ)
resp = {
"/": self.index,
"/slowtest": self.slowtest,
}.get(req.path_info, exc.HTTPNotFound)
return resp()(environ, start_response)
if __name__ == '__main__':
from wsgiref.simple_server import make_server
server_ip = ""
server_port = 8080
make_server(server_ip, server_port, TinyApp()).serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment