Part of the advantage, and perhaps a lot of the problem, with Python web development, is that there are a lot of web frameworks to choose from. You might be interested in googling on WSGI, which is an attempt to provide a standard to build these frameworks on top of.
Returning to your program, it's impressive, but I think you're reinventing the wheel a little. Why use raw sockets, when the standard Python library includes a BaseHTTPServer module for you to use? The advantages to using BaseHTTPServer are twofold: firstly, it's easier, and secondly you know that it adheres to HTTP specifications, which can be something of a minefield to do manually.
from BaseHTTPServer import *
pages = {}
def expose(function):
pages["/" + function.__name__] = function
if function.__name__ == 'index':
pages["/"] = function
return function
class HTTPHandler(BaseHTTPRequestHandler):
def do_GET(self):
page_contents = pages[self.path]()
self.send_response(200)
self.send_header("Content-type", "text/html")
self.wfile.write(page_contents)
@expose
def index():
return """<html>
<head><title>Test</title><head>
<body>Hello World</body>
</html>"""
if __name__ == '__main__':
httpd = HTTPServer(('', 8000), HTTPHandler)
httpd.serve_forever() I believe CherryPy uses BaseHTTPServer, too.