Apache Configuration Directives



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, in which case they will be called sequentially, from left to right.

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. Only one uninstantiated class is allowed in the path.

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.

Example:

PythonAuthzHandler mypackage.mymodule::checkallowed

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 sequetially 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..


PythonPath

Syntax: PythonPath path
Context: server config, virtual host, directory, htaccess
Override: not None
Module: mod_python.c

PythonPath directive sets the PythonPath. The path must be specified in Python list notation, e.g.

 PythonPath "['/usr/local/lib/python1.5', '/usr/local/lib/site_python', '/some/other/place']".
The path specified in this directive will replace the path, not add to it. Note that this directive should not be used as a security measure since the Python path is easily manipulated from within the scripts.

PythonInterpreter

Syntax: PythonInterpreter name
Context: server config, virtual host, directory, htaccess
Override: not None
Module: mod_python.c

Forces the subinterpreter name to be name, instead of the name assigned by mod_python. Mod_python names subinterpreters by using full path of a directory thereby guaranteeing uniqueness. By using this directive, scripts located in different directories and that would by default be executed in different subinterpreters, can be forced to execute in the same subinterpreter.


PythonInterpPerDirectory

Syntax: PythonInterpPerDirectory
Context: server config, virtual host, directory, htaccess
Override: not None
Module: mod_python.c

Instructs mod_python to name subinterpreters using the directory of the file in the request (request_rec->filename) rather than the directory in which the Python*Handler directive currently in effect was encountered. This means that scripts in different directories will execute in different subinterpreters as opposed to the default policy where scripts effected by the same Handler directive execute in the same subinterpreter, even if they are in different directories.

Let's say you have a /directory/subdirectory. /directory has an .htaccess file with a PythonHandler directive. /directory/subdirectory doesn't have an .htacess. By default, scripts in /directory and /directory/subdirectory would execute in the same interpreter based on the directory where PythonHandler was encountered. With PythonInterpPerDirectory, there would be two different interpreters, one for each directory.


PythonDebug

Syntax: PythonDebug
Context: server config, virtual host, directory, htaccess
Override: not None
Module: mod_python.c

Normally, the traceback output resulting from uncaught Python errors is sent to the error log. With PythonDebug directive specified, the output will be sent to the client, except when the error is IOError while writing, in which case it will go to the error log.

A consequence of this directive being specified is that when multiple handlers are involved in processing the request, the processing will

This directive is very usefull during the development process. It is recommended that you do not use it production environment as it may reveal to the client sensitive security information.


PythonNoReload

Syntax: PythonNoReload
Context: server config, virtual host, directory, htaccess
Override: not None
Module: mod_python.c

Instructs mod_python not to check the modification date of the module file. By default, mod_python checks the timestamp of the file and reloads the module if the module's file modification date is later than the last import or reload.

This options is useful in production environment where the modules do not change, it will save some processing time and give a small performance gain.


PythonOption

Syntax: PythonOption key value
Context: server config, virtual host, directory, htaccess
Override: not None
Module: mod_python.c

Assigns a key value pair to a table that can be later retrieved by the request.get_options() function. This is useful to pass information between the apache configuration files (httpd.conf, .htaccess, etc) and the Python programs.


PythonPostReadRequestHandler

Syntax: Python*Handler syntax
Default: None
Context: server config, virtual host, directory, htaccess
Override: not None
Module: mod_python.c

This routine is called after the request has been read but before any other phases have been processed. This is useful to make decisions based upon the input header fields.


PythonTransHandler

Syntax: Python*Handler syntax
Default: None
Context: server config, virtual host, directory, htaccess
Override: not None
Module: mod_python.c

This routine gives allows for an opportunity to translate the URI into an actual filename, before the server's default rules (Alias directives and the like) are followed.


PythonHeaderParserHandler

Syntax: Python*Handler syntax
Default: None
Context: server config, virtual host, directory, htaccess
Override: not None
Module: mod_python.c

This handler is called to give the module a chance to look at the request headers and take any appropriate specific actions early in the processing sequence.


PythonAccessHandler

Syntax: Python*Handler syntax
Default: None
Context: server config, virtual host, directory, htaccess
Override: not None
Module: mod_python.c

This routine is called to check for any module-specific restrictions placed upon the requested resource.

For example, this can be used to restrict access by IP numer. To do so, you would return HTTP_FORBIDDEN or some such to indicate that access is not allowed.


PythonAuthenHandler

Syntax: Python*Handler syntax
Default: None
Context: server config, virtual host, directory, htaccess
Override: not None
Module: mod_python.c

This routine is called to check the authentication information sent with the request (such as looking up the user in a database and verifying that the [encrypted] password sent matches the one in the database).


PythonAuthzHandler

Syntax: Python*Handler syntax
Default: None
Context: server config, virtual host, directory, htaccess
Override: not None
Module: mod_python.c

This routine is called to check to see if the resource being requested requires authorization.


PythonTypeHandler

Syntax: Python*Handler syntax
Default: None
Context: server config, virtual host, directory, htaccess
Override: not None
Module: mod_python.c

This routine is called to determine and/or set the various document type information bits, like Content-type (via r->content_type), language, et cetera.


PythonFixupHandler

Syntax: Python*Handler syntax
Default: None
Context: server config, virtual host, directory, htaccess
Override: not None
Module: mod_python.c

This routine is called to perform any module-specific fixing of header fields, et cetera. It is invoked just before any content-handler.


PythonHandler

Syntax: Python*Handler syntax
Default: None
Context: server config, virtual host, directory, htaccess
Override: not None
Module: mod_python.c

This is the main request handler. 99.99% of your applications will only provide this one handler.


PythonLogHandler

Syntax: Python*Handler syntax
Default: None
Context: server config, virtual host, directory, htaccess
Override: not None
Module: mod_python.c

This routine is called to perform any module-specific logging activities over and above the normal server things.


Last modified: Thu May 11 18:25:37 EDT 2000