index.cgi
changeset 134 fbccc1648d79
parent 133 088aa2da1340
equal deleted inserted replaced
133:088aa2da1340 134:fbccc1648d79
     4     CGI mode using qmsk.web.cgi
     4     CGI mode using qmsk.web.cgi
     5 """
     5 """
     6 
     6 
     7 def error () :
     7 def error () :
     8     """
     8     """
     9         Dumps out a raw traceback of the current exception to stdout, call from except
     9         Dumps out a raw traceback of the current exception to stdout, call from except.
       
    10 
       
    11         Used for low-level ImportError's
    10     """
    12     """
    11 
       
    12     import traceback, sys
       
    13     
    13     
    14     # HTTP headers
    14     # if this import fails, we're doomed
    15     sys.stdout.write('Status: 500 Internal Server Error\r\n')
    15     import sys, error
    16     sys.stdout.write('Content-type: text/html\r\n')
    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)
    17     sys.stdout.write('\r\n')
    23     sys.stdout.write('\r\n')
    18     sys.stdout.write("""\
    24     sys.stdout.write(body)
    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     
    25     
    34 def main () :
    26 def main () :
    35     """
    27     """
    36         Build our wsgi.Application and run
    28         Build our wsgi.Application and run
    37     """
    29     """
    38 
    30 
    39     try :
    31     try :
    40         from qmsk.web import wsgi, cgi_main
    32         from qmsk.web import cgi_main
    41         import urls
    33         import wsgi
    42 
    34 
    43         # create app
    35         # create app
    44         app = wsgi.Application(urls.mapper)
    36         app = wsgi.Application()
    45         
    37         
    46         # run once
    38         # run once
    47         cgi_main.run(app)
    39         cgi_main.run(app)
    48 
    40 
    49     except :
    41     except :