-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_wsgi.py
70 lines (57 loc) · 2.15 KB
/
simple_wsgi.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
def hello_page(env, start_response):
start_response('200 OK', [('Content-Type', 'text/html')])
return [b"""
<html><h1>Help</h1>
<p>Hello world!</p>
<ul>
<li>
<a href="/">Main page</a>
</li>
<li>
<a href="/hello/help">Help for Hello world</a>
</li>
</ul>
</html>"""
]
def help_page(env, start_response):
start_response('200 OK', [('Content-Type', 'text/html')])
return [b"""
<html><h1>Help</h1>
<p>Help page for Hello world</p>
<ul>
<li>
<a href="/">Main page</a>
</li>
<li>
<a href="/hello">Hello world</a>
</li>
</ul>
</html>"""
]
def main_page(env, start_response):
start_response('200 OK', [('Content-Type', 'text/html')])
return [b"""
<html><h1>Main</h1>
<p>The main page</p>
<a href="/hello">Hello world</a>
</html>"""
]
def not_found(env, start_response):
start_response('404 Not Found', [('content-type', 'text/html')])
return [b"""
<html><h1>Page not Found</h1>
<p>
This url is not supported.
Return to the <a href="/">Main page</a>
</p>
</html>"""
]
routes = [('/hello', hello_page),
('/hello/help', help_page),
('/', main_page)
]
def application(env, start_response):
for path, app in routes:
if env['PATH_INFO'].endswith(path):
return app(env, start_response)
return not_found(env, start_response)