[mod_python] 3.X equivalent of 2.X req.get_dirs()

Graham Dumpleton grahamd at dscpl.com.au
Thu Oct 7 00:04:01 EDT 2004

Todays hard question. :-)

Is there an equivalent in mod_python 3.X to the req.get_dirs() method
that appears in mod_python 2.X? Ie., in 2.X it would for example return:

{'PythonHandler': '/usr/local/etc/httpd/htdocs/projects/vampire/',
 'PythonDebug': '/usr/local/etc/httpd/htdocs/projects/vampire/'}

That is, the directory in the hierarchy where the Apache directives such
as PythonHandler were defined.

Previously I asked about a way to more or less determine exactly this.
That is, the directory in the hierarchy where PythonHandler was defined
for the currently active content handler.

When I asked that time, the only solution proposed was to use sys.path
by looking at the first entry in it. It actually had to be a bit smarter
than that, as sys.path could be modified by other things and so one
had to look for the directory in sys.path which was the longest match
for the start of req.filename.

The problem with using sys.path for what I was doing is that if PythonPath
is set explicitly as a directive, the directory in the document hierarchy may
not end up being put in sys.path.

The req.get_dirs() method turns out instead to be exactly what I wanted
in the first place, but it dissappeared in 3.X. Is there some way of getting
the same information in 3.X?

Other possibilities for doing what I want are to require that the directive
PythonInterpPerDirective be specified in the same spot as the directive
for PythonHandler. In 3.X you can then at least use req.interpreter, which
for this option will then be set to the directory where PythonHandler was

Under 2.X there is no req.interpreter or equivalent that I could find,
although one can still use req.get_dirs() in that case to see where it
was that either PythonHandler or PythonInterPerDirective was set.

The only issue for what I want is that if someone uses PythonInterpreter
to override the interpreter name, it will no longer be the directory where
the PythonHandler was set.

Anyone else got any thoughts on an equivalent to req.get_dirs() in 3.X?
I haven't dug into the 3.X code base enough to see how this stores it,
but it doesn't look as simple any more and certainly doesn't seem to be
able to be queried.

Graham Dumpleton (grahamd at dscpl.com.au)

More information about the Mod_python mailing list