Differences between revisions 1 and 2
Revision 1 as of 2003-07-03 02:29:01
Size: 865
Editor: dsl-203-113-207-144
Comment:
Revision 2 as of 2003-07-03 02:33:07
Size: 875
Editor: dsl-203-113-207-144
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
You can run the same Albatross script as a CGI or from mod_python with the following trick: You can run the same Albatross script as a CGI or from mod_python, or even from the command line, with the following trick:
Line 3: Line 3:
        from albatross import SimpleSessionFileApp, SessionFileAppContext
Line 4: Line 5:
            os.environ['GATEWAY_INTERFACE']             from albatross.cgiapp import Request # This will fail if we are not inside mod_python
            cgi = 0
        except ImportError:
            from albatross.apacheapp import Request
Line 6: Line 10:
        except:
            cgi = 0
    
        from albatross import SimpleSessionFileApp, SessionFileAppContext
        if cgi:
            from albatross.cgiapp import Request
        else:
            from albatross.apacheapp import Request

You can run the same Albatross script as a CGI or from mod_python, or even from the command line, with the following trick:

        from albatross import SimpleSessionFileApp, SessionFileAppContext
        try:
            from albatross.cgiapp import Request # This will fail if we are not inside mod_python
            cgi = 0
        except ImportError:
            from albatross.apacheapp import Request
            cgi = 1

        # Page classes, application/context objects, etc here

        app = App()

        def handler(req):
           '''Called from mod_python - turn a mod_python req into an Albatross Request'''
            return do_handler(Request(req))

        def do_handler(r):
           '''Called with an Albatross Request object'''
            return app.run(r)

        if cgi:
            do_handler(Request())

None: CGI_and_mod_python (last edited 2011-02-15 06:05:18 by localhost)