-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlocalhost.py
More file actions
50 lines (40 loc) · 1.01 KB
/
localhost.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
from wsgiref.simple_server import make_server
def fib(n):
if n < 2:
return n
else:
return fib(n-1) + fib(n-2)
def format(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(lambda n: ('<span>%s,</span>' % n), mylist))
return (template % content)
# A relatively simple WSGI application. It's going to print out the
# first 10 Fibonacci numbers
def simple_app(environ, start_response):
status = '200 OK'
headers = [('Content-type', 'text/html')]
start_response(status, headers)
out = []
for i in range(1, 10):
out.append(fib(i))
return format(out)
httpd = make_server('', 8000, simple_app)
print "Serving on port 8000..."
httpd.serve_forever()