index.cgi
changeset 66 d2ce81dd5e5d
parent 46 54c5f5f340de
equal deleted inserted replaced
65:9c85c06ba7d5 66:d2ce81dd5e5d
     1 #!/usr/bin/python2.5
     1 #!/usr/bin/python2.5
     2 # :set filetype=py encoding=utf8
       
     3 
     2 
     4 """
     3 """
     5     Sample CGI implementation
     4     Sample CGI main() function.
       
     5 
       
     6     This example runs site.SiteModuleCollection('sites')
     6 """
     7 """
     7 
     8 
     8 # CGI handler for WSGI
     9 def main () :
     9 import wsgiref.handlers
       
    10 
       
    11 def cgi_error () :
       
    12     """
    10     """
    13         Dumps out a raw traceback of the current exception to stdout, intended for use from except
    11         Build our wsgi.Application and run
    14     """
       
    15 
       
    16     import traceback, sys
       
    17 
       
    18     print 'Status: 500 Internal Server Error\r'
       
    19     print 'Content-type: text/plain\r'
       
    20     print '\r'
       
    21 
       
    22     traceback.print_exc(100, sys.stdout)
       
    23 
       
    24 def cgi_main () :
       
    25     """
       
    26         Run in CGI mode
       
    27     """
    12     """
    28 
    13 
    29     try :
    14     try :
    30         from qmsk.web import wsgi, site
    15         from qmsk.web import wsgi, cgi_main, site
    31 
       
    32         # create handler
       
    33         cgi_handler = wsgiref.handlers.CGIHandler()
       
    34 
    16 
    35         # create app
    17         # create app
    36         app = wsgi.Application(site.SiteModuleCollection('sites'))
    18         app = wsgi.Application(site.SiteModuleCollection('sites'))
    37         
    19         
    38         # run once
    20         # run once
    39         cgi_handler.run(app)
    21         cgi_main.run(app)
    40 
    22 
    41     except :
    23     except :
    42         cgi_error()
    24         # display error on stdout
       
    25         cgi_main.error()
    43     
    26     
    44 if __name__ == '__main__' :
    27 if __name__ == '__main__' :
    45     cgi_main()
    28     main()
       
    29