金字塔遍历的资源基类
kalpa的Python项目详细描述
kalpa为金字塔中的资源遍历提供了一个起点。它提供了
有两个类,aBranch
和aLeaf
,它们允许您
创建没有样板的任意资源树。
另外还有一个Root
类,它可以接受
初始化期间请求。这可以用来为
金字塔的横贯。
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`. """