-
Notifications
You must be signed in to change notification settings - Fork 131
/
wsgi_1.py
42 lines (33 loc) · 1 KB
/
wsgi_1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python
import datetime
default = "No Value Set"
body = """<html>
<head>
<title>Lab 3 - WSGI experiments</title>
</head>
<body>
<p>Hey there, this page has been generated by {software}, running at {path}</p>
<p>Today is {month} {date}, {year}.</p>
<p>This page was requested by IP Address {client_ip}</p>
</body>
</html>"""
def application(environ, start_response):
import pprint
pprint.pprint(environ)
response_body = body.format(
software=environ.get('SERVER_SOFTWARE', default),
path="aaaa",
month="bbbb",
date="cccc",
year="dddd",
client_ip="eeee"
)
status = '200 OK'
response_headers = [('Content-Type', 'text/html'),
('Content-Length', str(len(response_body)))]
start_response(status, response_headers)
return [response_body.encode('utf8')]
if __name__ == '__main__':
from wsgiref.simple_server import make_server
srv = make_server('localhost', 8080, application)
srv.serve_forever()