On 20/08/2006, at 11:22 AM, Graham Dumpleton wrote:

FYI. Part 1 of some information about new module importer in 3.3.

Part 2 of information about changes to new importer.

Next lot of changes that have been made are that a number of internal
functions used by the new importer have been exposed as part of public
API for mod_python. Note that if the old importer is being used, these
functions will not exist.

The new functions are:

apache.handler_root() - Will return the path name of the directory for
which the handler directive was specified. If called where there is no
directory associated with the context the handler was specified for, will
return None.

This is basically the same as req.hlist.directory or filter.dir, but can be called at any time without having access to the req or filter objects. In
other words, it can be called at global scope within a module when it
is being imported. It would thus be possible to do the following:

  from mod_python import apache
  __mp_path__.append(apache.handler_root())

  import _config

The result of this will be that if '_config' is located in the root directory for which the handler was specified, it will be imported from that directory.

apache.get_current_config() - Will return the currently active mod_python
config object.

If this is called from within a module being imported using PythonImport, it will return the same thing as having called apache.main_server.get_config(). If called from a module being imported due to a request, will return the same
as if the 'req' object was available and req.get_config() was called.

Like apache.handler_root() this can be called at global scope within a
module.

apache.get_current_options() - Will return the currently active mod_python
options object.

If this is called from within a module being imported using PythonImport, it will return the same thing as having called apache.main_server.get_options(). If called from a module being imported due to a request, will return the same
as if the 'req' object was available and req.get_options() was called.

With this it would be possible to do the following:

  from mod_python import apache
  __mp_path__.append(apache.get_current_options()["CONFIG_DIR"])

  import _config

In this case where the configuration directory is would need to be specified
by a PythonOption in Apache configuration file.

  PythonOption CONFIG_DIR /some/path/config

Because the options object will be that relevant to a request, this means that the option could have been set in a .htaccess pertinent to the part of the URL
namespace the request targeted.

Although all of the above are useful, like the PythonPath directive, they can
be misused as well and cause problems.

Where one can cause problems is if this is used in a common set of modules used by two distinct applications and each application isn't running in a separate interpreter. If an option is accessed from global scope, that from the application which first loads module will be used and the other will be
overridden if not the same.

Thus, if used on common modules, make sure applications run in different
interpreters. Otherwise only use where modules live in document tree of the
one application and nothing else uses them.

apache.modules_graph() - Returns a string contain data for a DOT formatted graph showing relationships between all modules currently held in the module cache. This data could be written out to a file and then read by a program such as Graphviz for the Mac, or it could be converted to an image or postscript by various DOT tools. If one is tricky, one could write a handler that converts it to an image on the fly and returns that as the response to the request.

apache.request_modules_graph() - Similar to apache.modules_graph(), but
returns only data relevant to modules which needed to be loaded to satisfy the
current request.

For both of these graph functions, they take an optional argument which defaults to 0. This indicates a simple graph showing only the names of the files for each module. When argument is 1 (True), then additional information about cache generation, mtime, ctime, atime, direct hits, indirects hits and embedded value
of __mp_path__ will be shown as well.

Part 3 in another email.

Graham

Reply via email to