def setUp(self): application = WSGISimpleRouter() for i in range(10): application.map('/hello/%d' % i, WSGISimpleMessage("Hello World %d" % i)) class WSGISleeper(WSGISimpleMessage): def __call__(self, environ, start_response): sleep_seconds = int(environ['QUERY_STRING']) Tasklet.sleep(sleep_seconds) self.response = 'slept %d' % sleep_seconds return WSGISimpleMessage.__call__(self, environ, start_response) class WSGIPOSTSaver(WSGISimpleMessage): def __call__(self, environ, start_response): self.environ = environ f = environ['wsgi.input'] self.body = f.read(int(environ['HTTP_CONTENT_LENGTH'])) return WSGISimpleMessage.__call__(self, environ, start_response) self.saver = WSGIPOSTSaver('ok') application.map('/sleep', WSGISleeper('zzz...')) application.map('/post', self.saver) self.server = WSGIServer(application) self.socket_server = self.server.serve(('0.0.0.0', SERVER_PORT))
def main(): application = WSGISimpleRouter() from wsgiref.validate import validator application.map('/form', validator(show_form)) application.map('/upload', upload_form) application.map('/process', process_form) server = WSGIServer(application) server.serve(('localhost', 8080))