11import sys , os , BaseHTTPServer
22
3+ #-------------------------------------------------------------------------------
4+
35class ServerException (Exception ):
46 '''For internal error reporting.'''
57 pass
68
9+ #-------------------------------------------------------------------------------
10+
711class 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+
1622class 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+
2533class 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+
3848class 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+
5163class 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+
6074class 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
145159if __name__ == '__main__' :
146160 serverAddress = ('' , 8080 )
0 commit comments