def getChildWithDefault(self, path, request): if request.prepath != ['public'] and request.prepath != ['favicon.ico'] and request.prepath != ['']: return Resource.getChildWithDefault(self, path, request) #forward to whever was requested #try: #return Resource.getChildWithDefault(self, path, request) #except AttributeError: return Resource.getChildWithDefault(self, path, request)
def test_staticChildren(self): """ L{Resource.putChild} adds a I{static} child to the resource. That child is returned from any call to L{Resource.getChildWithDefault} for the child's path. """ resource = Resource() child = Resource() sibling = Resource() resource.putChild(b"foo", child) resource.putChild(b"bar", sibling) self.assertIdentical( child, resource.getChildWithDefault(b"foo", DummyRequest([])))
def getChildWithDefault(self, path, request): resource = Resource.getChildWithDefault(self, path, request) request.logger = logging.getLogger(resource.__class__.__module__) log_str = request.method + " " + request.get_path_and_query() if request.user: log_str += " " + request.user.username request.logger.info(log_str) if isinstance(resource, NoResource): raise PageNotFound() return resource
def test_staticChildPathType(self): """ Test that passing the wrong type to putChild results in a warning, and a failure in Python 3 """ resource = Resource() child = Resource() sibling = Resource() resource.putChild("foo", child) warnings = self.flushWarnings([self.test_staticChildPathType]) self.assertEqual(len(warnings), 1) self.assertIn("Path segment must be bytes", warnings[0]["message"]) # We expect an error here because "foo" != b"foo" on Python 3+ self.assertIsInstance( resource.getChildWithDefault(b"foo", DummyRequest([])), ErrorPage) resource.putChild(None, sibling) warnings = self.flushWarnings([self.test_staticChildPathType]) self.assertEqual(len(warnings), 1) self.assertIn("Path segment must be bytes", warnings[0]["message"])
def getChildWithDefault(self, pathEl, request): # Maps /index.html to / if request.uri == self._mount_point_root: return self._index_content return Resource.getChildWithDefault(self, pathEl, request)
def getChildWithDefault(self, path, request): request.setHeader('content-type', self.content_type) request = inject_allow_control_headers(request) request.__dict__['user'] = User(request.getUser()) return TwistedResource.getChildWithDefault(self, path, request)
def getChildWithDefault(self, path, request): if path == 'blobs' and len(request.postpath) == 2: blob_id = "{}{}".format(self.prefix, str(self.blob_id)) request.postpath[1] = blob_id self.blob_id += 1 return Resource.getChildWithDefault(self, path, request)
def getChildWithDefault(self, path, request): return Resource.getChildWithDefault(self, path, request)