Mercurial > hg > python
diff wsgi_test.py @ 2:e07789816ca5
adding more python files from lib/python on origen
author | Henry Thompson <ht@markup.co.uk> |
---|---|
date | Mon, 09 Mar 2020 16:48:09 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wsgi_test.py Mon Mar 09 16:48:09 2020 +0000 @@ -0,0 +1,25 @@ +from wsgiref.simple_server import make_server + +# Every WSGI application must have an application object - a callable +# object that accepts two arguments. For that purpose, we're going to +# use a function (note that you're not limited to a function, you can +# use a class for example). The first argument passed to the function +# is a dictionary containing CGI-style envrironment variables and the +# second variable is the callable object (see PEP 333). +n = 0 +def hello_world_app(environ, start_response): + global n + status = '200 OK' # HTTP Status + headers = [('Content-type', 'text/plain')] # HTTP Headers + start_response(status, headers) + + # The returned object is going to be printed + n=n+1 + return ["Hello World %s"%n] + +httpd = make_server('', 8000, hello_world_app) +print "Serving on port 8000..." + +# Serve until process is killed +httpd.serve_forever() +f