index.cgi
changeset 140 6db2527b67cf
parent 139 9c7769850195
child 141 65c98c9e1716
equal deleted inserted replaced
139:9c7769850195 140:6db2527b67cf
     1 #!/usr/bin/python2.5
       
     2 
       
     3 """
       
     4     CGI mode using qmsk.web.cgi
       
     5 """
       
     6 
       
     7 def error () :
       
     8     """
       
     9         Dumps out a raw traceback of the current exception to stdout, call from except.
       
    10 
       
    11         Used for low-level ImportError's
       
    12     """
       
    13     
       
    14     # if this import fails, we're doomed
       
    15     import sys, error
       
    16     
       
    17     # format info
       
    18     status, content_type, body = error.build_error()
       
    19     
       
    20     # HTTP headers+body
       
    21     sys.stdout.write('Status: %s\r\n' % status)
       
    22     sys.stdout.write('Content-type: %s\r\n' % content_type)
       
    23     sys.stdout.write('\r\n')
       
    24     sys.stdout.write(body)
       
    25     
       
    26 def main () :
       
    27     """
       
    28         Build our wsgi.Application and run
       
    29     """
       
    30 
       
    31     try :
       
    32         from qmsk.web import cgi_main
       
    33         import wsgi
       
    34 
       
    35         # create app
       
    36         app = wsgi.Application()
       
    37         
       
    38         # run once
       
    39         cgi_main.run(app)
       
    40 
       
    41     except :
       
    42         # display error on stdout
       
    43         error()
       
    44     
       
    45 if __name__ == '__main__' :
       
    46     main()
       
    47