Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
render_POST , render_GET will look at self.segments (which are relative paths) and use them for construct the final path.
#
# WARNING: This code does not work / had bugs ... is is just an idea.
#
def getChild(self, name, request):
"""
Return the resource for the request.
It will accumulate segments until we are at the end of the URL and
only then will do the filesystem check and return the final resource.
"""
# We still have segments to traverse.
if request.postpath:
if name == '':
# We have consecutive slashes since this segment is empty.
# but we still have segments to follow.
return self.getResourceNotFound(name, request)
self.segments.append(name)
return self
# Avatar has its own non FilePath filesystem access which suports impersonation
# and is designed to work with segments (list of path elements) instead of a path
# which is a single string.
if not self.avatar.filesystem.exists(self.segments):
return self.getResourceNotFound(name, request)
if self.avatar.filesystem.isFolder(self.segments):
# If we are at the end of the URL then we need a redirection
# since all folder requests should end with a slash.
if not request.postpath:
redirect_path = '/%s/' % ('/'.join(request.prepath))
return RedirectResource(redirect_path)
else:
return self
else:
path = self.avatar.filesystem.getRealPathFromSegments(
self.segments)
# RESTFileShell is just a static.File with impersonation support.
return RESTFileShell(self.avatar, path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.