It is impossible to answer your question without more information. If you are implementing a CGI HTTP server you should reference the following module, which may already provide some of the functions you're looking for:
http://docs.python.org/library/cgihttpserver.html#module-CGIHTTPServer