Well done! There are lots of good things in there I never would have
thought of, like the simple alternation of methods and params (much
easier than inventing a new specification language for which is which),
and calling find_handler twice! Brilliant.
Robert Brewer
fuma...@aminus.org
I very much agree will probably be using it where I was using Routes or
Selector previously. Well done.
I know we are careful about getting new code in the trunk but that would
be a nice candidate considering the amount of people asking for that kind
of behavior.
- Sylvain
--
Sylvain Hellegouarch
http://www.defuze.org
Hi, thanks for the feedback. I've added a patch at http://www.cherrypy.org/ticket/897,
so you can play with it. I've included some tests in test_rest.py.
There are a few issues I would like to discuss:
1) I'm thinking that it might be better to add the arguments to kwargs
instead or args, and using the resources part of the URL as key. Thus
a GET on the URL /people/4/phones/ will call the GET method within
Phones with kwargs = { 'people' : 4 }. That would make it possible to
mount the Phones class within several controllers if needed. If would
also fix the second last test /people/phones/5/ringtones which
currently gets wrong since ringtones does not really know who the
argument 5 is really for.
Yeah; I subscribe to cherrypy-tickets. ;)
This is some great work. It'll take me a bit of time to digest the
implications of Yet Another Dispatcher in the distro. I'd like to play
around a bit and see if:
1) perhaps we can separate the dispatching-by-HTTP-method code from the
grabbing-params-code a bit more cleanly. It bugs me that the
MethodDispatcher.__call__ is buried so deep in there. I'd like us to
explore ways to better enable composable graphs of dispatchers instead
of tightly coupling them.
2) contrarily, perhaps your approach, and lakin's recent trunk checkin,
might conflict or need a shootout to be built into the default
dispatcher.
Robert Brewer
fuma...@aminus.org
Lakin,
I've looked over your patch, and I think it's very nice. I had a hard
time trying to use your _cp_dispatch to implement my REST stuff.
But I
finally got it working after making a few changes to MethodDispatcher.
I've added both the solutions to http://www.cherrypy.org/ticket/897 so
you can see the difference. http://www.cherrypy.org/attachment/ticket/897/rest_dispatch-v3.diff.
I've reimplemented test_rest.py with _cp_dispatch called
test_rest_cp_dispatch.py.
Thus I only need to make myself a simple RestController and subclass
it for People, Phones, Ringtones etc. The good thing with this
solution is that mangling with the parameters is moved from CherryPy
and into the application. This is good since the application better
knows how it wants to deal with them.
def _cp_dispatch(self, vpath):
if vpath[0] != 'index':
if hasattr(self, vpath[0]):
return getattr(self, vpath[0])
else:
request.params[self.id_name] = vpath[0]
return self
return None
As for the shootout I think I will throw in the towel at this point.
Your solution is both more flexible and much faster than my solution.
If I can get the few lines into MethodDispatcher I will be happy. If
not I will have to make a MethodWithVerbsDispatcher ;-)
One suggestion is that the _cp_dispatch method could be allowed to
modify the vpath, in order to eat multiple entries from vpath in one
go, or to reorder or insert items to get a custom *args list when the
method is called: resource, new_vpath = dispatch(vpath)
I wouldn't be encline to follow that track. I'm not a big fan of adding
more to the CP namespace but between a _cp_dispatch and this, I actually
the _cp_dispatch.
Damn I accidently the email as they say. Well I prefer _cp_dispatch as
it offers more flexibility and if we add something to the CP namespace,
it might as well be flexible.
- Sylvain