From: karim hamidou Date: Tue, 15 May 2012 19:20:56 +0000 (+0200) Subject: working on basic routin X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=937c478a410c3653908e8046366eefa550f3df6f;p=miniwsgi.git working on basic routin --- diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..d0db2a0 --- /dev/null +++ b/__init__.py @@ -0,0 +1,17 @@ +from wsgiref.simple_server import make_server, demo_app + +urls = {} + +def handle_requests(environ, start_response): + method = environ['REQUEST_METHOD'].upper() # get the request method + path = environ['PATH_INFO'] + + # then, lookup if there's a matching route: + if path in urls: + start_response('200 OK', [('content-type', 'text/html')]) + return urls["GET"][path]() + +def run(urls): + httpd = make_server('', 8000, handle_requests) + print "Serving HTTP on http://localhost:8000" + httpd.serve_forever()