Nicolas Lehuen
nicolas.lehuen at gmail.com
Mon May 30 16:51:20 EDT 2005
Hi Lee, Unfortunately the answer is not as simple as it seems. Try doing this in xmlhandler.py : from mod_python import apache from os.path import dirname this_directory = dirname(__file__) site_setup = apache.import_module("site_setup",path=[this_directory]) check = str(dir()) def handler(req): ... req.write(req.interpreter + '<br />') req.write(check) ... return apache.OK We use apache.import_module to import the site_setup module, looking in the current directory for site_setup.py[cd]. Regards, Nicolas 2005/5/30, Lee Brown <administrator at leebrown.org>: > Greetings! > > 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: > > Platform: > > 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 > PythonPath > "sys.path+['c:/projects/webdev/sites/crashtest/config','c:/projects/webdev/s > ites/crashtest/home/xmltest']" > PythonImport site_setup.py crashtest > ... > > In the 'vhost' section of httpd.conf: > > <VirtualHost *:80> > ServerName crashtest.leebrown.org > ... > PythonInterpreter crashtest > PythonDebug On > ... > <Directory > "C:/Projects/webdev/sites/crashtest/home/xmltest"> > ... > PythonHandler xmlhandler > DirectoryIndex xmlhandler.py > ... > </Directory> > ... > </VirtualHost> > > 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 />') > req.write(check) > ... > return apache.OK > > A user agent request to the local URL 'crashtest.leebrown.org/xmltest' > returns the following: > > crashtest > ['__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) > > _______________________________________________ > Mod_python mailing list > Mod_python at modpython.org > http://mailman.modpython.org/mailman/listinfo/mod_python >
|