5.1.1 Python*Handler Directive Syntax

All Python*Handler directives have the following syntax:

Python*Handler handler [handler] ...

Where handler is a callable object (e.g. a function) that accepts a single argument - request object.

Multiple handlers can be specified on a single line, in which case they will be called sequentially, from left to right. Same handler directives can be specified multiple times as well, with the same result - all handlers listed will be executed sequentially, from first to last. If any handler in the sequence returns a value other than apache.OK, then execution of all subsequent handlers is aborted.

A handler has the following syntax:

module[::object] [module::[object]] ...

Where module can be a full module name (package dot notation is accepted), and the optional object is the name of an object inside the module.

Object can also contain dots, in which case it will be resolved from left to right. During resolution, if mod_python encounters an object of type <class>, it will try instantiate it passing it a single argument, a request object.

If no object is specified, then it will default to the directive of the handler, all lower case, with the word "Python"removed. E.g. the default object for PythonAuthenHandler would be authenhandler.


PythonAuthzHandler mypackage.mymodule::checkallowed

For more information on handlers, see Overview of a Handler.

Side note: The "::" was chosen for performance reasons. In order for Python to use objects inside modules, the modules first need to be imported. However, if the separator were simply a ".", it would involve a much more complex process of sequentially evaluating every word to determine whether it is a package, module, class etc. Using the (admittedly un-Python-like) "::" takes the time consuming work of figuring out where the module ends and the object inside of it begins away from mod_python resulting in a modest performance gain..