Apache Mod-Python - Clarification on example provided

This is Interesting: Free IT Magazines  
Home > Archive > Apache Mod-Python > December 2006 > Clarification on example provided





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Clarification on example provided
Martin Stoufer

2006-12-07, 7:14 pm

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.

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


Graham Dumpleton

2006-12-07, 7:14 pm

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

Martin Stoufer

2006-12-07, 7:14 pm



Graham Dumpleton wrote:
> Martin Stoufer wrote ..
>
>
> 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 *


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com