Graham Dumpleton commented on MODPYTHON-164:

Change made, but require argument to functions be the actual callable object, 
no module reference allowed as suggested originally. Thus can write:

from mod_python import apache

def uppercase(filter):
    s = filter.read()
    while s:
        s = filter.read()
    if s is None:

def handler(req):
    req.content_type = 'text/plain'
    return apache.OK

def fixuphandler(req):
    req.handler = 'mod_python'
    req.register_output_filter("UPPERCASE", uppercase)
    req.add_handler('PythonHandler', handler)
    return apache.OK

where Apache configuration just defines the fixup handler. For example:

PythonFixupHandler handlers

The speed increase is significant, as it avoids having to perform additional 
module lookups when string reference used.

This whole feature is very promising, as it would allow quite powerful dispatch 
mechanisms to be implemented where the decisions are made in the fixup handler 
phase rather than the response handler itself. All in all, provides more 
flexibility by doing it this way.

> Allow req.add_handler()/req.register_*_filter() to take module/function for 
> handler.
> ------------------------------------------------------------------------------------
>                 Key: MODPYTHON-164
>                 URL: http://issues.apache.org/jira/browse/MODPYTHON-164
>             Project: mod_python
>          Issue Type: New Feature
>          Components: core
>            Reporter: Graham Dumpleton
>         Assigned To: Graham Dumpleton
> Currently, the:
>   req.add_handler(phase, handler, dir)
>   req.register_input_filter(filter_name, filter, dir)
>   req.register_output_filter(filter_name, filter, dir)
> functions require the handler/filter to be a string. This string identifies 
> the module that should be imported and which contains the necessary function, 
> plus optionally, an alternate named function to the default for the phase or 
> filter type. For example:
>   req.add_handler("PythonHandler", "mymodule::myhandler")
> It would be simpler if the handler/filter argument could be overloaded and 
> instead supplied an actual module reference or callable object reference. For 
> example:
>   import mymodule
>   def myhandler(req):
>     ...
>   def fixuphandler(req):
>     req.add_handler("PythonHandler", mymodule)
>     req.add_handler("PythonHandler", mymodule.myhandler)
>     req.add_handler("PythonHandler", myhandler)
>     return apache.OK
> This would be easier than having to construct a string module/function 
> reference when you have direct access to the handler function.
> In the main the "dir" argument would be irrelevant. The only circumstance 
> where it would matter is where PythonInterpPerDirective was used as it could 
> be used to control the interpreter the code executed within. If not supplied, 
> it could be argued that the directory where the supplied module/function is 
> defined in should be used as "dir".

This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators: 
For more information on JIRA, see: http://www.atlassian.com/software/jira


Reply via email to