Skip to content

Commit cdf042b

Browse files
committed
Lots of reorganizing
1 parent fd06099 commit cdf042b

21 files changed

Lines changed: 362 additions & 303 deletions

File tree

web-server/00-hello-web/server.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import BaseHTTPServer
22

3+
#-------------------------------------------------------------------------------
4+
35
class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
46
'''Handle HTTP requests by returning a fixed 'page'.'''
57

@@ -20,7 +22,7 @@ def do_GET(self):
2022
self.end_headers()
2123
self.wfile.write(self.Page)
2224

23-
#----------------------------------------------------------------------
25+
#-------------------------------------------------------------------------------
2426

2527
if __name__ == '__main__':
2628
serverAddress = ('', 8080)

web-server/01-echo-request-info/server.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import BaseHTTPServer
22

3+
#-------------------------------------------------------------------------------
4+
35
class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
46
'''Respond to HTTP requests with info about the request.'''
57

@@ -45,7 +47,7 @@ def send_page(self, page):
4547
self.end_headers()
4648
self.wfile.write(page)
4749

48-
#----------------------------------------------------------------------
50+
#-------------------------------------------------------------------------------
4951

5052
if __name__ == '__main__':
5153
serverAddress = ('', 8080)

web-server/02-serve-static/server-status-code.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import sys, os, BaseHTTPServer
22

3+
#-------------------------------------------------------------------------------
4+
35
class ServerException(Exception):
46
'''For internal error reporting.'''
57
pass
68

9+
#-------------------------------------------------------------------------------
10+
711
class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
812
'''
913
If the requested path maps to a file, that file is served.
@@ -66,7 +70,7 @@ def send_content(self, content, status=200):
6670
self.end_headers()
6771
self.wfile.write(content)
6872

69-
#----------------------------------------------------------------------
73+
#-------------------------------------------------------------------------------
7074

7175
if __name__ == '__main__':
7276
serverAddress = ('', 8080)

web-server/02-serve-static/server.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import sys, os, BaseHTTPServer
22

3+
#-------------------------------------------------------------------------------
4+
35
class ServerException(Exception):
46
'''For internal error reporting.'''
57
pass
68

9+
#-------------------------------------------------------------------------------
10+
711
class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
812
'''
913
If the requested path maps to a file, that file is served.
@@ -66,7 +70,7 @@ def send_content(self, content):
6670
self.end_headers()
6771
self.wfile.write(content)
6872

69-
#----------------------------------------------------------------------
73+
#-------------------------------------------------------------------------------
7074

7175
if __name__ == '__main__':
7276
serverAddress = ('', 8080)

web-server/03-handlers/server-index-page.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import sys, os, BaseHTTPServer
22

3+
#-------------------------------------------------------------------------------
4+
35
class ServerException(Exception):
46
'''For internal error reporting.'''
57
pass
68

9+
#-------------------------------------------------------------------------------
10+
711
class case_no_file(object):
812
'''File or directory does not exist.'''
913

@@ -13,6 +17,8 @@ def test(self, handler):
1317
def act(self, handler):
1418
raise ServerException("'%s' not found" % handler.path)
1519

20+
#-------------------------------------------------------------------------------
21+
1622
class case_existing_file(object):
1723
'''File exists.'''
1824

@@ -22,6 +28,8 @@ def test(self, handler):
2228
def act(self, handler):
2329
handler.handle_file(handler.full_path)
2430

31+
#-------------------------------------------------------------------------------
32+
2533
class case_directory_index_file(object):
2634
'''Serve index.html page for a directory.'''
2735

@@ -35,6 +43,8 @@ def test(self, handler):
3543
def act(self, handler):
3644
handler.handle_file(self.index_path(handler))
3745

46+
#-------------------------------------------------------------------------------
47+
3848
class case_always_fail(object):
3949
'''Base case if nothing else worked.'''
4050

@@ -44,6 +54,8 @@ def test(self, handler):
4454
def act(self, handler):
4555
raise ServerException("Unknown object '%s'" % handler.path)
4656

57+
#-------------------------------------------------------------------------------
58+
4759
class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
4860
'''
4961
If the requested path maps to a file, that file is served.
@@ -105,7 +117,7 @@ def send_content(self, content, status=200):
105117
self.end_headers()
106118
self.wfile.write(content)
107119

108-
#----------------------------------------------------------------------
120+
#-------------------------------------------------------------------------------
109121

110122
if __name__ == '__main__':
111123
serverAddress = ('', 8080)

web-server/03-handlers/server-no-index-page.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import sys, os, BaseHTTPServer
22

3+
#-------------------------------------------------------------------------------
4+
35
class ServerException(Exception):
46
'''For internal error reporting.'''
57
pass
68

9+
#-------------------------------------------------------------------------------
10+
711
class case_no_file(object):
812
'''File or directory does not exist.'''
913

@@ -13,6 +17,8 @@ def test(self, handler):
1317
def act(self, handler):
1418
raise ServerException("'%s' not found" % handler.path)
1519

20+
#-------------------------------------------------------------------------------
21+
1622
class case_existing_file(object):
1723
'''File exists.'''
1824

@@ -22,6 +28,8 @@ def test(self, handler):
2228
def act(self, handler):
2329
handler.handle_file(handler.full_path)
2430

31+
#-------------------------------------------------------------------------------
32+
2533
class case_directory_index_file(object):
2634
'''Serve index.html page for a directory.'''
2735

@@ -35,6 +43,8 @@ def test(self, handler):
3543
def act(self, handler):
3644
handler.handle_file(self.index_path(handler))
3745

46+
#-------------------------------------------------------------------------------
47+
3848
class case_directory_no_index_file(object):
3949
'''Serve listing for a directory without an index.html page.'''
4050

@@ -48,6 +58,8 @@ def test(self, handler):
4858
def act(self, handler):
4959
handler.list_dir(handler.full_path)
5060

61+
#-------------------------------------------------------------------------------
62+
5163
class case_always_fail(object):
5264
'''Base case if nothing else worked.'''
5365

@@ -57,6 +69,8 @@ def test(self, handler):
5769
def act(self, handler):
5870
raise ServerException("Unknown object '%s'" % handler.path)
5971

72+
#-------------------------------------------------------------------------------
73+
6074
class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
6175
'''
6276
If the requested path maps to a file, that file is served.
@@ -140,7 +154,7 @@ def send_content(self, content, status=200):
140154
self.end_headers()
141155
self.wfile.write(content)
142156

143-
#----------------------------------------------------------------------
157+
#-------------------------------------------------------------------------------
144158

145159
if __name__ == '__main__':
146160
serverAddress = ('', 8080)

web-server/03-handlers/server.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import sys, os, BaseHTTPServer
22

3+
#-------------------------------------------------------------------------------
4+
35
class ServerException(Exception):
46
'''For internal error reporting.'''
57
pass
68

9+
#-------------------------------------------------------------------------------
10+
711
class case_no_file(object):
812
'''File or directory does not exist.'''
913

@@ -13,6 +17,8 @@ def test(self, handler):
1317
def act(self, handler):
1418
raise ServerException("'%s' not found" % handler.path)
1519

20+
#-------------------------------------------------------------------------------
21+
1622
class case_existing_file(object):
1723
'''File exists.'''
1824

@@ -22,6 +28,8 @@ def test(self, handler):
2228
def act(self, handler):
2329
handler.handle_file(handler.full_path)
2430

31+
#-------------------------------------------------------------------------------
32+
2533
class case_always_fail(object):
2634
'''Base case if nothing else worked.'''
2735

@@ -31,6 +39,8 @@ def test(self, handler):
3139
def act(self, handler):
3240
raise ServerException("Unknown object '%s'" % handler.path)
3341

42+
#-------------------------------------------------------------------------------
43+
3444
class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
3545
'''
3646
If the requested path maps to a file, that file is served.
@@ -91,7 +101,7 @@ def send_content(self, content, status=200):
91101
self.end_headers()
92102
self.wfile.write(content)
93103

94-
#----------------------------------------------------------------------
104+
#-------------------------------------------------------------------------------
95105

96106
if __name__ == '__main__':
97107
serverAddress = ('', 8080)

web-server/04-cgi/index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<html>
2+
<head>
3+
<title>Index Page</title>
4+
</head>
5+
<body>
6+
<h1>Index Page</h1>
7+
<p>Welcome to our directory.</p>
8+
</body>
9+
</html>
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<html>
22
<head>
3-
<title>Nitinat Plain Page</title>
3+
<title>Plain Page</title>
44
</head>
55
<body>
6-
<h1>Nitinat Plain Page</h1>
6+
<h1>Plain Page</h1>
77
<p>Nothin' but HTML.</p>
88
</body>
99
</html>

0 commit comments

Comments
 (0)