Kalpa provides a starting point for resource traversal in Pyramid. It provides
two classes for this, a Branch and a Leaf, which allow you to
create arbitrary resource trees without the boilerplate.
There is also a Root class for added convenience that accepts a
request during initialization. This can be used to create a starting point for
Pyramid's traversal.
fromkalpaimportRoot, Node, branchUSERS= {...}
classRoot(Root):
"""Root resource for Pyramid traversal."""users=branch('UserCollection')
classUserCollection(Node):
"""User collection, for listings, or loading single users."""__child_cls__='User'def__load__(self, key):
"""Returns dict with attributes to create a child node from."""return {'user': USERS[key]} # Load user or raise KeyError.classUser(Node):
"""User resource, a single loaded user."""gallery=branch('UserGallery', aliases=['images'])
classUserGallery(Node):
"""Gallery of images posted by a user. Reachable as `/users/:id/gallery` but also `/users/:id/images`. """