def getChildForRequest(resource, request): # originally taken from twisted.web.resource """ Traverse resource tree to find who will handle the request. """ while request.postpath and not resource.isLeaf: pathElement = request.postpath.pop(0) request.prepath.append(pathElement) retval = resource.getChildWithDefault(pathElement, request) if isinstance(retval, defer.Deferred): resource = yield retval else: resource = retval defer.returnValue(resource)
def _getResource(self, args=None, headers=None, path=()): """ Generalized GET for a particular resource. """ headers = headers or correctAcceptHeaders request = _FakeRequest(args=args, requestHeaders=headers) resource = self.resource for childName in path: resource = resource.getChildWithDefault(childName, request) d = self._makeRequest(resource, request) @d.addCallback def verify(_): self._checkContentType() self._decodeResponse() return d
def getChildWithDefault(self, name, request): d = defer.succeed(self.default) resource = util.DeferredResource(d) return resource.getChildWithDefault(name, request)
def _getChild(self, resource, path, request): return resource.getChildWithDefault(path, request)