[Zope-dev] [IDEA] ZopeRoot and SiteRoot

Lennart Regebro lennart@regebro.nu
Mon, 17 Dec 2001 19:56:24 +0100


From: "Chris McDonough" <chrism@zope.com>
> Hmm... no, I dont think there's a call to get the virtual root.
> Although I imagine it would be pretty simple to add.

Yes it is.

This works with SiteAccessEnhanced (where EASY_VHM has to be the name if the
host monster)

    security.declarePublic('getVirtualRootPath')
    def getVirtualRootPath(self):
        req = self.REQUEST
        rpp = req.get('VirtualRootPhysicalPath', None)
        if rpp is None:
            vhm = getattr(self, EASY_VHM, None)
            if vhm is None:
                return ('',)
            else:
                rules = vhm.display_rules()
                physical_path = self.getPhysicalPath()
                best_match = ('',)
                for domain,path in rules:
                    match_path = path = split(path,'/')
                    if len(path)<=len(physical_path):
                        index = 0
                        for pid in path:
                            if physical_path[index]!=pid:
                                match_path = None
                                break
                            index = index + 1
                        if match_path != None:
                            if len(match_path) > len(best_match):
                                best_match = match_path
                return tuple(best_match)
        return rpp

And when you have the path you can get the object.