[mod_python] Accessing objects loaded with PythonImport

Lee Brown administrator at leebrown.org
Mon May 30 15:19:59 EDT 2005


I am trying to use the PythonImport directive to perform some initialization
routines for each vhost on server startup and then have my request handler
for that vhost access data and/or objects from those initial routines.
Unfortunately, I cannot for the life of me find the namespace in which these
objects reside from within the handler.  Here is what's going on:


	Apache/2.0.52 (Win32) mod_python/3.1.3 Python/2.3.4 

In the 'main' section of httpd.conf:

	AddHandler mod_python .py
	PythonImport site_setup.py crashtest

In the 'vhost' section of httpd.conf:

	<VirtualHost *:80>
		ServerName crashtest.leebrown.org
		PythonInterpreter crashtest
		PythonDebug On
        		PythonHandler xmlhandler
        		DirectoryIndex xmlhandler.py

File site_setup.py (in its entirety):

	magic_string = 'Ooggaa-Booggaa!'

Finally, the file xml_handler.py:

	from mod_python import apache

	check = str(dir())

	def handler(req):
    		req.write(req.interpreter + '<br />')
    		return apache.OK

A user agent request to the local URL 'crashtest.leebrown.org/xmltest'
returns the following:

	['__builtins__', '__doc__', '__file__', '__mtime__', '__name__',
'apache', 'check', 'handler']

'crashtest' is the interpreter name I expected to get, however neither
'site_setup' nor 'magic_string' seems to be available to my handler
function.  I've explored around using the dir() function with magic_string,
site_setup.magic_string, __name__, etc., etc. without success.

I suspect that the answer is dirt simple, but I'll be horn-swaggled if I can
find it.

Best Regards,
Lee E. Brown
(leebrown at leebrown.org)

More information about the Mod_python mailing list