Third time lucky. Understand this all a bit better now and have found a bug of sorts in mod_python as a result.
These return config/options outside of all configuration containers.
These return config/options for the virtual host overlayed on top of that in req.connection.base_server. If there is no virtual host container would be same as req.connection.base_server.
These return config/options from containers specific to the URL for a request. That is, Location, Directory and Files containers. These overlay those from req.server and req.connection.base_server.
Now, the server object being exposed in the "apache" module should be the same as available to a request handler through req.connection.base_server.
Unfortunately, the server object currently stored as "apache._server" is not necessarily the same as req.connection.base_server. This is because it is set to the server object available at the time the interpreter was initialised. Depending on the situation, this might be either req.connection.base_server or req.server.
The problem arises because in src/mod_python.c, the get_interpreter() function needs to be passed both the interpreter name and a server_rec object.
interpreterdata *get_interpreter(const char *name, server_rec *srv)
Originally the server_rec was used only for ensuring error messages were logged in the correct context, thus whether it equated to the base server or virtual host wasn't too important. When
MODPYTHON-37 was implemented however, the server object was cached in the "apache" module. Again, for what it was being used, it didn't actually matter that which server object was being cached varied.
In coming to make the server object available as a public attribute it does now matter. The server object must be that which equates to req.connection.base_server.
First off therefore, it should be called "apache.base_server" to make the connection obvious.
Secondly, src/mod_python.c should be modified so that the python_init() function caches a pointer to the base server server_rec structure in a global variable. Whenever get_interpreter() is called, this cached server_rec object should be supplied as the argument. Alternatively, the get_interpreter() function shouldn't even take the server_rec object as a second argument and instead should just get it from the global variable populated by the python_init() function.
A bit of a review should also possibly be done about how about server_rec objects are used to direct where logging goes in the mod_python internals. It possibly should be consistent and all go through the base server, rather than randomly through either base server or virtual host server contexts.