Hi Chris,
Isn't the "self" parameter in your newaction function definition an
error? I believe the correct syntax is --
$ ipython
In [1]: def factory(param):
...: def deco(func):
...: def newaction(*args, **kw):
...: print 'do sth. with %s' % param
...: return func(*args, **kw)
...: return newaction
...: return deco
...:
In [2]: class controller:
...: def __init__(self):
...: pass
...: @factory('param1')
...: def action(self):
...: print 'interesting stuff'
...:
In [3]: contrl = controller()
In [4]: contrl.action()
do sth. with param1
interesting stuff
--
Jerry
On Feb 8, 2:14 pm, Chris <[EMAIL PROTECTED]> wrote:
> Hi,
> It is probably something simple, but I'm having some difficulty
> writing a decorator factory for a controller method.
>
> # The decorator stuff
> def factory(param):
> def deco(func):
> def newaction(self, *args, **kw):
> return func(self, *args, **kw)
> return newaction
> return deco
>
> # The controller method
> @factory(param1)
> def action(self):
> return 'interesting stuff'
>
> The error I'm getting is:
> <type 'exceptions.TypeError'>: action() got an unexpected keyword
> argument 'start_response'
>
> I believe this is happening because controller actions can take some
> keyword arguments like: start_response, controller, sub_domain,
> environ, action, etc
> that are somehow implied and only passed in if the method requests
> them. It looks like pylons.controllers.core does the magic of
> figuring that out and I'd rather not duplicate that in my
> decorators.
>
> Any suggestions on how to correctly write a decorator factory for a
> controller method?
>
> Thanks,
> Chris
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---