Automatic construction of handler class.
----------------------------------------

                 Key: MODPYTHON-208
                 URL: http://issues.apache.org/jira/browse/MODPYTHON-208
             Project: mod_python
          Issue Type: Improvement
          Components: core
    Affects Versions: 3.2.10, 3.3
            Reporter: Graham Dumpleton


When defining a mod_python handler, it is possible to supply a dotted path for 
the actual handler function to be used. Ie:

  PythonHandler module::instance.function

when determing the handler to execute, it will use the dotted path to traverse 
any object hierarchy. Thus the above will execute "function()" of the object 
instance called "instance" in the module called "module".

If instead one provides:

  PythonHandler module::class.function

where 'class' is the name of a class type, then referencing 'function' within 
that type will result in an instance of the class automatically being created 
just for the current request, with "function()' then being called on that 
transient instance of the class.

For an instance of the class to be created in this way, one must access a 
member function of the class type. If an instance of the class is callable in 
its own right, ie., has a __call__() method, it is not however possible to say:

  PythonHandler module::class

To get that to work, you instead have to use:

  PythonHandler module::class.__call__

First change should be that if a class is callable through having a __call__() 
method, then it should not be necessary to reference the __call__() method 
explicitly, instead, referencing the class type itself should be enough. Ie., 
using

  PythonHandler module::class

should work.

Note that the code will have to be smart enough to handle both new and old 
style classes.

The next issue with this automatic initialisation of a class type is that 
although the __call__() method needs to accept the 'req' argument, the 
constructor has to as well if it is being created automatically. The code 
should allow for the case where the class doesn't want to have to deal with the 
'req' object as an argument to the constructor. Ie., it should be optional for 
the constructor, although always still required for the actual function of the 
class instance being called.

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

        

Reply via email to