All pastes #22730 Raw Edit

locateSiblingResourc

public python v1 · immutable
#22730 ·published 2005-09-12 18:02 UTC
rendered paste body
    def locateSiblingResource(self, ctx, uri):        """        Look up a resource on the same server with the given URI.        """        request = IRequest(ctx)            #        # Parse the URI        #            (scheme, host, path,         params, querystring, fragment) = urlparse.urlparse(uri, "http")            # Request hostname and destination hostname have to be the same.        if host and host != request.headers.getHeader("host"):            raise ValueError("URI is not on this site (%s): %s"                             % (request.headers.getHeader("host"), uri))            segments = path.split("/")        if segments[0]:            raise AssertionError("URI path didn't begin with '/': %s" % (path,))        segments = segments[1:]            #        # Find the resource with the given path.        #            #        # FIXME: site isn't in the IRequest interface, and there needs to be an        # ISite interface.        #        # FIXME: How do I get params, querystring, and fragment passed down to        # the new resource?  Insert them to segments?        #        sibling = request.site.resource        while segments and segments is not StopTraversal:                    sibling, segments = sibling.locateChild(ctx, segments)        return sibling