Пример #1
0
    def loadURL(self, location, headers=None):
        p = urlparse.urlparse(location)
        if not p.scheme == 'pmr':
            # standard urls.
            return super(PmrUrlOpener, self).loadURL(location, headers=headers)

        # Fragments for the location of the object to be loaded are
        # delimited by colons.  Shouldn't contain any colons in any of
        # them, but the filepath might so we limit splits to two.
        objpath, rev, filepath = p.path.split(':', 2)

        # strip off the leading `/` hint for urljoin.
        filepath = filepath[1:]

        portal = getSite()
        workspace = portal.restrictedTraverse(objpath.split('/'))
        storage = IStorage(workspace)
        storage.checkout(rev)
        pathinfo = storage.pathinfo(filepath)
        if pathinfo.get('external'):
            kws = {}
            kws.update(pathinfo['external'])
            target = external_to_url(kws)
            return self.loadURL(target)
        # Using this instead of contents to ignore directories.
        return storage.file(filepath)