On 9/6/06, Krys <[EMAIL PROTECTED]> wrote:
>
> Diez B. Roggisch wrote:
> >
> > Sounds like a metaclass problem to me - create a metaclass that will take
> > all
> > (or some specially decorated) methods of a class and add a jsonified
> > version,
> > under a special name like <methodname>_json.
> >
> > Diez
>
> As a hack, you could use:
>
> def base_method(decorated_method):
> """Returns the undecorated original method.
>
> This is useful for overriding exposed methods to get the dictionary
> of
> return values.
>
> """
> return decorated_method.__dict__['__composition__'][0]
>
> which "un-decorates" a method or function.
>
> But the metaclass idea is better, though.
>
> Just a thought.
> Krys
Thank you both, I actually solved this quite simply.
Since all the methods on my class had "@expose('json')" - I did the
following: I removed the @expose decorator from all the methods and
added one @exposed method callapi:
@expose("json")
def callapi(self, method, *args, **kwargs):
try:
m = getattr(self, method)
return m(*args, **kwargs)
except (AttributeError, TypeError):
raise cherrypy.NotFound()
and changed my Rotes connect from
m.connect('api/pe/:jobno/:pagename/:action', controller='pageeditor')
to
m.connect('api/pe/:jobno/:pagename/:method', controller='pageeditor',
action='callapi')
Now my api methods can happily call each other without problem since
all web requests go through callapi.
Arnar
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" 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/turbogears
-~----------~----~----~----~------~----~------~--~---