Esempio n. 1
0
def cgi_runscript(conn):
    """Run a python script in a CGI environment.

    This function does not attach stdio; that has to be done at the
    C++ level (i.e., via the AttachStdio config directive).

    """

    url = conn.request.url
    pageroot = Ns.PageRoot(conn.Server())

    #  Bah!  It's not that easy.  To wit, from the
    #  AOLserver nscgi sources we learn:
    #
    #  1. Path is UrlToFile up to the URL prefix.
    #  2. SCRIPTNAME is the URL prefix
    #  3. PATH_INFO is everything past SCRIPT_NAME
    ns_setup.setup_cgi_env(url)
    Ns.Log(Ns.Debug, '++++ start python: ' + os.environ['SCRIPT_NAME'])
    try:
        # see if file exists:
        os.stat(pageroot + os.environ['SCRIPT_NAME'])
    except OSError:
        conn.ReturnNotFound()
    else:
        # Error handling is done in the function who called us.
        execfile(pageroot + os.environ['SCRIPT_NAME'])

    Ns.Log(Ns.Debug, '++++ done python: ' + os.environ['SCRIPT_NAME'])
Esempio n. 2
0
def fulfill_cgi_request():
    conn = Ns.GetConn()
    url = conn.request.url
    pageroot = Ns.PageRoot(conn.Server())

    #
    #  Bah!  It's not that easy.  To wit, from the
    #  AOLserver nscgi sources we learn:
    #
    #  1. Path is UrlToFile up to the URL prefix.
    #  2. SCRIPTNAME is the URL prefix
    #  3. PATH_INFO is everything past SCRIPT_NAME
    ns_setup.setup_cgi_env(url)
    Ns.Log(Ns.Debug, '++++ start python: ' + os.environ['SCRIPT_NAME'])
    try:
        # see if file exists:
        os.stat(pageroot + os.environ['SCRIPT_NAME'])
    except OSError:
        conn.ReturnNotFound()
    else:
        # let python do its own error handling
        prepare_and_runscript(conn, pageroot + os.environ['SCRIPT_NAME'], url)

    Ns.Log(Ns.Debug, '++++ done python: ' + os.environ['SCRIPT_NAME'])