quetz-mod_python-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Stoufer <MCStou...@lbl.gov>
Subject Re: Clarification on example provided
Date Thu, 07 Dec 2006 22:23:17 GMT


Graham Dumpleton wrote:
> Martin Stoufer wrote ..
>   
>> Graham,
>>     After pouring over the comments sent by you and Jim regarding my 
>> session/class examples, I have a better feel for what is expected in 
>> good coding models. Could you make some clarifications on one of the 
>> examples you provided:
>>
>> class SessionEnabled:
>>     def __init__(self, target):
>>       self.__target = target
>>     def __call__(self):
>>       if not hasattr(req, 'session'):
>>          req.session = Session.Session(req)
>>       return util.apply_fs_data(self.__target, req.form)
>>
>>   def _function(req, a, b):
>>     return a,b
>>
>>   function = SessionEnabled(_function)
>>
>> Was the 'req' arg left off the __call__ method by mistake?
>>
>> I'm still a bit fuzzy about how the apply_fs_data() properly passes the
>> req object down into the target function. My sandbox working example for
>> this keeps complaining that no arguments are being provided to the function.
>>     
>
> Yes, missed 'req' argument.
>
>      def __call__(self, req):
>        if not hasattr(req, 'session'):
>           req.session = Session.Session(req)
>        return util.apply_fs_data(self.__target, req.form)
>
> Note, this works on basis that mod_python.publisher has already read in form
> input and cached form object as req.form.
>
> Graham
>   
Storing the form as an object makes sense, it was the functionality on 
how _function is passed the 'req' object. Looking at the apply_fs_data 
code, I determined that I needed to add req explicitly to work:

return util.apply_fs_data(self.__target, req.form, req=req)

This obviously isn't a bug; I just need to chew on it some more to be 
fully comfortable with it.

-- 
* Martin C. Stoufer              *
* DST/DIDC/ITG                   *
* Lawrence Berkeley National Lab *
* MS 50B-2239 510-486-8662       *


Mime
View raw message