index.cgi
changeset 66 d2ce81dd5e5d
parent 46 54c5f5f340de
--- a/index.cgi	Thu Feb 12 23:03:17 2009 +0200
+++ b/index.cgi	Sat Feb 14 18:40:21 2009 +0200
@@ -1,45 +1,29 @@
 #!/usr/bin/python2.5
-# :set filetype=py encoding=utf8
 
 """
-    Sample CGI implementation
+    Sample CGI main() function.
+
+    This example runs site.SiteModuleCollection('sites')
 """
 
-# CGI handler for WSGI
-import wsgiref.handlers
-
-def cgi_error () :
-    """
-        Dumps out a raw traceback of the current exception to stdout, intended for use from except
+def main () :
     """
-
-    import traceback, sys
-
-    print 'Status: 500 Internal Server Error\r'
-    print 'Content-type: text/plain\r'
-    print '\r'
-
-    traceback.print_exc(100, sys.stdout)
-
-def cgi_main () :
-    """
-        Run in CGI mode
+        Build our wsgi.Application and run
     """
 
     try :
-        from qmsk.web import wsgi, site
-
-        # create handler
-        cgi_handler = wsgiref.handlers.CGIHandler()
+        from qmsk.web import wsgi, cgi_main, site
 
         # create app
         app = wsgi.Application(site.SiteModuleCollection('sites'))
         
         # run once
-        cgi_handler.run(app)
+        cgi_main.run(app)
 
     except :
-        cgi_error()
+        # display error on stdout
+        cgi_main.error()
     
 if __name__ == '__main__' :
-    cgi_main()
+    main()
+