[albatross-users] Handy mod_python hint

Gregory Bond gnb at itga.com.au
Fri Jan 10 12:55:11 EST 2003


I wrote:

> You can run a single Albatross program either as a normal CGI, as a native
> mod_python script, or as a CGI under mod_python using mod_python's cgihandler
> ,
> with a trick like this:
> 
> 	try:
> 	    os.environ['GATEWAY_INTERFACE']
> 	    cgi = 1
> 	except:
> 	    cgi = 0
>     
> 	from albatross import SimpleSessionFileApp, SessionFileAppContext
> 	if cgi:
> 	    from albatross.cgiapp import Request
> 	else:
> 	    from albatross.apacheapp import Request

[rest snipped]

This part can all be simplified and also made to work from the command line 
(for simpler testing) by changing the above to:

	from albatross import SimpleSessionFileApp, SessionFileAppContext
	try:
	    from albatross.apacheapp import Request
	    cgi = 0
	except ImportError:
	    cgi = 1
	    from albatross.cgiapp import Request

This depends on the fact that albatross.apacheapp imports mod_python, and this 
will always fail unless this script is being imported by mod_python inside a 
running apache process.

Greg.




More information about the Albatross-users mailing list