# Our tutorial's WSGI server from wsgiref.simple_server import make_server
defapplication(environ, start_response):
# Sorting and stringifying the environment key, value pairs response_body = ['%s: %s' % (key, value) for key, value insorted(environ.items())] response_body = '\n'.join(response_body)
# Instantiate the WSGI server. # It will receive the request, pass it to the application # and send the application's response to the client httpd = make_server( 'localhost', # The host name. 8051, # A port number where to wait for the request. application # Our application object name, in this case a function. )
# Wait for a single request, serve it and quit. httpd.handle_request()