- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlocalhost.py
More file actions
Latest commit
50 lines (40 loc) · 1.01 KB
/
Copy pathlocalhost.py
File metadata and controls
50 lines (40 loc) · 1.01 KB
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
fromwsgiref.simple_serverimportmake_server
deffib(n):
ifn<2:
returnn
else:
returnfib(n-1) +fib(n-2)
defformat(mylist):
template='''<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<meta name="author" content="myself">
<title>Sample page</title>
<style type="text/css">
div.myblock {
color: green;
}
span {
padding-right: 5px;
}
</style>
</head>
<body>
<div class="myblock">%s</div>
</body>
</html>'''
content=''.join(map(lambdan: ('<span>%s,</span>'%n), mylist))
return (template%content)
# A relatively simple WSGI application. It's going to print out the
# first 10 Fibonacci numbers
defsimple_app(environ, start_response):
status='200 OK'
headers= [('Content-type', 'text/html')]
start_response(status, headers)
out= []
foriinrange(1, 10):
out.append(fib(i))
returnformat(out)
httpd=make_server('', 8000, simple_app)
print"Serving on port 8000..."
httpd.serve_forever()