index.cgi
author Tero Marttila <terom@fixme.fi>
Mon, 16 Feb 2009 03:25:00 +0200
changeset 137 a25d1bf758e6
parent 134 fbccc1648d79
permissions -rwxr-xr-x
moar pimping of the error page... at this point, error messages are becoming more of a feature than a bug
#!/usr/bin/python2.5

"""
    CGI mode using qmsk.web.cgi
"""

def error () :
    """
        Dumps out a raw traceback of the current exception to stdout, call from except.

        Used for low-level ImportError's
    """
    
    # if this import fails, we're doomed
    import sys, error
    
    # format info
    status, content_type, body = error.build_error()
    
    # HTTP headers+body
    sys.stdout.write('Status: %s\r\n' % status)
    sys.stdout.write('Content-type: %s\r\n' % content_type)
    sys.stdout.write('\r\n')
    sys.stdout.write(body)
    
def main () :
    """
        Build our wsgi.Application and run
    """

    try :
        from qmsk.web import cgi_main
        import wsgi

        # create app
        app = wsgi.Application()
        
        # run once
        cgi_main.run(app)

    except :
        # display error on stdout
        error()
    
if __name__ == '__main__' :
    main()