PK!C  pyramid_resource.pyfrom pyramid.location import lineage class Resource: """ A node on the traversal resource tree. Each node should subclass this class. Chilldren can be defined by overriding ``__children__``. """ request = None __name__ = '' __parent__ = None __children__ = dict() def __init__(self, request, name='', parent=None, **kwargs): self.request = request self.__name__ = name self.__parent__ = parent self._extra = kwargs def __getitem__(self, key): # Invoke customer child lookup resp = self.get_child(key) if resp is not None: if isinstance(resp, tuple): Child, extra = resp elif isinstance(resp, Resource): Child = resp extra = dict() else: raise TypeError('Invalid child type') return Child(self.request, key, self, **extra) # Default child lookup Child = self.__children__.get(key) if Child is not None: return Child(self.request, key, self) # Couldn't find anything raise KeyError def get_child(self, key): """ Override this function to dynamically generate child resources. You can return: * A Resource subclass * A two-tuple of a Resource subclass and a dictionary of extra attributes. * ``None``, to fall back to default child lookup. You can also raise a KeyError to force the tree lookup to stop. """ pass def __getattr__(self, name): for resource in lineage(self): if name in resource._extra: return resource._extra[name] raise AttributeError('Could not find attribute "{}"'.format(name)) PK!X66(pyramid_resource-0.1.0.dist-info/LICENSEThe MIT License (MIT) Copyright (c) 2018 Theron Luhn Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!HnHTU&pyramid_resource-0.1.0.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!H]-)pyramid_resource-0.1.0.dist-info/METADATARN0+V$ Tj wnClJTq!G{gfgy@ MZ`L;G١x.jk2bm,Qb@Zku «N[8N >G (k&wޢ =5QH*+CuM[)%fXt3&P ABфZ`o"~C61wivEѯpџ9vCD_5vU˯#^{F'gQoX|L1dnTF)#59rn:!ZC*+PK!HyGWt'pyramid_resource-0.1.0.dist-info/RECORDvC@}eFb,P$Q"a#.!0wM7 -4Wٙy4g eMrD ؙNN`ؐQ5H`%-C p d0ª-ȇW/i*H>z?gkQ:mీc%wQSM $?Cs}B &MW8iWxol\DJq[c\ 8X /PK!C  pyramid_resource.pyPK!X66(>pyramid_resource-0.1.0.dist-info/LICENSEPK!HnHTU& pyramid_resource-0.1.0.dist-info/WHEELPK!H]-)R pyramid_resource-0.1.0.dist-info/METADATAPK!HyGWt' pyramid_resource-0.1.0.dist-info/RECORDPK8