TGNewTraversal: less broken traversal for TurboGears
I have been massive underwhelmed by the traversal mechanism of CherryPy, which is used in TurboGears.
If you are building a large complex application, you need a lot of control over traversal, and CherryPy just doesn’t give you this. URL components have to be fixed for the normal traversal mechanisms to work. If you want them to be variable, then you need to write some pretty hairy code that depends a lot on CherryPy internals.
In my view this is the major failing in the application, which is otherwise pretty nice. I’ll moan about the lack of daemonisation another time ;)
The other major option is to use Routes. This is lifted from Rails. I gave this a go, but I really dislike pretty much everything about it — I don’t think regular expressions are part of the mix to solve an architectural problem like this.
So, enter TGNewTraversal. I’ve ripped off some of the code from Nevow’s traversal mechanism, which is the best I’ve seen anywhere. I’ve tweaked this slightly to be more friendly in the CherryPy environment. The tiny amount of code required is a testimony to the quality of the traversal concept from Nevow.
It’s working very well on a development project I’m working on right now, and seems ready for an Alpha release at least. It’s released under a BSD license and is in the Cheese Shop. Please give it a shot and let me know what you think.
Comments
Just wanted to say that because lots of readers don't know about it. Although CherryPy 2 was limited in the way you describe above, CherryPy 3 has made an effort to allow more flexibility in that area and if someone fancies using routes it only takes one line in CherryPy 3 to use it in place of the default dispatching mechanism. Moreoever in CP3 adding your own dispatcher is much clearer and avoids relying on the internal behavior of CherryPy itself.
As it seems TG is moving forward with CherryPy 3 and a WSGI components based, I hope you'll feel things get better in the future.
Posted by: Sylvain Hellegouarch | February 28, 2007 02:26 PM
Will this work with cherrypy without turbogears?
Posted by: vineet | February 28, 2007 02:38 PM
Hi Vineet,
I've not tried Cherrypy on it's own, but I can't see any reason why it wouldn't work. If you get it going, let me know the recipe and I'll put it on the wiki.
Posted by: Doug Winter | February 28, 2007 02:46 PM
For reference see:
http://groups.google.co.uk/group/cherrypy-users/browse_thread/thread/379ef1006f2b5d9a
Posted by: Sylvain Hellegouarch | February 28, 2007 05:08 PM
If you haven't seen the routing_args spec, you might want to give it a look. Personally I think object traversal as a URL lookup mechanism is pretty limited, and extending it through lots of hooks and overrides just enables too much complexity. I think it's better to support a jump from object traversal to full pattern matching, than to allow gradual complexity to be added to the traversal.
Posted by: Ian Bicking | March 7, 2007 12:10 AM