index.cgi
changeset 133 088aa2da1340
parent 125 45e56cbf9086
child 134 fbccc1648d79
equal deleted inserted replaced
132:0e857c4a67de 133:088aa2da1340
     2 
     2 
     3 """
     3 """
     4     CGI mode using qmsk.web.cgi
     4     CGI mode using qmsk.web.cgi
     5 """
     5 """
     6 
     6 
       
     7 def error () :
       
     8     """
       
     9         Dumps out a raw traceback of the current exception to stdout, call from except
       
    10     """
       
    11 
       
    12     import traceback, sys
       
    13     
       
    14     # HTTP headers
       
    15     sys.stdout.write('Status: 500 Internal Server Error\r\n')
       
    16     sys.stdout.write('Content-type: text/html\r\n')
       
    17     sys.stdout.write('\r\n')
       
    18     sys.stdout.write("""\
       
    19 <html><head><title>500 Internal Server Error</title></head><body>
       
    20 <h1>Oops!</h1>
       
    21 <p>
       
    22     An error occured, which was not logged, and will not be reported to anybody. It might be your fault, or it might be
       
    23     the programmer's, but it's probably not mine. If you think you really care, you can try poking the administrator of
       
    24     this site to see if they respond. 
       
    25 </p>
       
    26 <p>
       
    27     If you do so, please include the following information:
       
    28 </p>
       
    29 <h2>Details:</h2>
       
    30 <pre>%(traceback)s</pre>
       
    31 </body></html>
       
    32 """ % dict(traceback=traceback.format_exc()))
       
    33     
     7 def main () :
    34 def main () :
     8     """
    35     """
     9         Build our wsgi.Application and run
    36         Build our wsgi.Application and run
    10     """
    37     """
    11 
    38 
    19         # run once
    46         # run once
    20         cgi_main.run(app)
    47         cgi_main.run(app)
    21 
    48 
    22     except :
    49     except :
    23         # display error on stdout
    50         # display error on stdout
    24         cgi_main.error()
    51         error()
    25     
    52     
    26 if __name__ == '__main__' :
    53 if __name__ == '__main__' :
    27     main()
    54     main()
    28 
    55