This is a simple wsgi python server that outputs Hello guys!!!to 0.0.0.0:8080.
from wsgiref.simple_server import make_server
content = 'Hello guys!!!'
def application(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
return [content]
server = make_server('0.0.0.0', 8080, application)
server.serve_forever()
When considering this code, several questions arise:
How does a function make_serverwork only with a function name application? I do not see how this does anything else, and then returns a string "<function application at 0x7f71686286e0>"(of application.__repr__() methoda function object).
Why environdoes an application function definition be defined as an argument when it is not used inside this function and is not even set in a function call applicationlater?
, , start_response , , , make_server. ? ( , , )
: environ , start_response, , , start_response application .
, os.environ - , , python. environ , , , (environ), , . " , " , , .
- Ned , , make_server('0.0.0.0', 8080, application) WSGIServer, wsgiref.simple_server.WSGIServer((host, port), handler_class)). , , BaseServer. BaseServer server_address RequestHandlerClass .
application application WSGIServer.
, application - python. ( , WSGIServer) - , ? , .