On May 1, 2009, at 12:45 AM, Marius Gedminas wrote:
>
> It's tricky, but not too tricky, if you only accept keyword  
> arguments in
> to @jsonify():

Yep, but I definitely don't want to keep it working both ways going  
forward (1.0). It'd be a good stopgap.

>
>    def jsonify(fn=None, arg1=value1, arg2=value2):
>        if fn is None:
>            # this is @jsonify(arg1=...), so return a decorator
>            return functools.partial(jsonify, arg1=arg1, arg2=arg2)
>        @functools.wraps
>        def wrapped(*a, **kw):
>            # do stuff
>            retval = fn(*a, **kw)
>            return simplejson.dumps(retval, arg1=arg1, arg2=arg2)
>        return wrapped


functools.wraps here isn't enough because it doesn't maintain the  
method argspec -- we need the decorator module magic. Pylons needs the  
argspec maintained to know what routing args to pass along.

--
Philip Jenvey


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to pylons-discuss@googlegroups.com
To unsubscribe from this group, send email to 
pylons-discuss+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to