[albatross-users] Handy mod_python hint

Dave Cole djc at object-craft.com.au
Mon Dec 23 15:14:14 EST 2002


> 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
> 
> 	# 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())

That is seriously cool :-)

- Dave

-- 
http://www.object-craft.com.au




More information about the Albatross-users mailing list