#! /usr/bin/python import sys import cgi import os import cgitb cgitb.enable() # parse the request path and delegate to the given file def main(argv): if len(argv) > 1: path = argv[1] elif 'PATH_INFO' in os.environ: path = os.environ['PATH_INFO'] elif 'QUERY_STRING' in os.environ: path = os.environ['QUERY_STRING'] else: path = "/" showpath(path, sys.stdout) def handler(req): from mod_python import apache # should use the built-in URI parsing but currently # we expect to parse the query string ourselves scrpath = req.parsed_uri[apache.URI_PATH] #if scrpath[0:9] == "index.py/": scrpath = scrpath[9:] if req.parsed_uri[apache.URI_QUERY] != None: scrpath = scrpath + "?" + req.parsed_uri[apache.URI_QUERY] req.content_type = "text/html"; showpath(scrpath, req) return apache.OK def showpath(path, web): path, u1, query = path.partition('?') if query != None: query = cgi.parse_qs(query) path = path.lstrip('/') if path == "": page = 'main' elif path == 'share': page = 'share' elif path == 'book': page = 'book' elif path == 'about': page = 'about' elif path == 'browse': page = 'browse' elif path == 'sample': page = 'sample' else: raise Exception('bad path %s' % path) exec "import page_" + page exec "page_" + page + ".showpage(web, path, query)" if __name__ == "__main__": main(sys.argv)