Exemplo n.º 1
0
    def make_relative(self, url):
        """
        Given a URL path return it as a relative URL,
        given the context of the current page.
        """
        if self.force_abs_urls:
            abs_url = '%s/%s' % (self.base_path.rstrip('/'), utils.path_to_url(url.lstrip('/')))
            return abs_url.rstrip('/')

        suffix = '/' if (url.endswith('/') and len(url) > 1) else ''
        # Workaround for bug on `os.path.relpath()` in Python 2.6
        if self.base_path == '/':
            if url == '/':
                # Workaround for static assets
                return '.'
            return url.lstrip('/')
        # Under Python 2.6, relative_path adds an extra '/' at the end.
        relative_path = os.path.relpath(url, start=self.base_path)
        relative_path = relative_path.rstrip('/') + suffix

        return utils.path_to_url(relative_path)
Exemplo n.º 2
0
    def make_relative(self, url):
        """
        Given a URL path return it as a relative URL,
        given the context of the current page.
        """
        if self.force_abs_urls:
            abs_url = '%s/%s' % (self.base_path.rstrip('/'),
                                 utils.path_to_url(url.lstrip('/')))
            return abs_url.rstrip('/')

        suffix = '/' if (url.endswith('/') and len(url) > 1) else ''
        # Workaround for bug on `os.path.relpath()` in Python 2.6
        if self.base_path == '/':
            if url == '/':
                # Workaround for static assets
                return '.'
            return url.lstrip('/')
        # Under Python 2.6, relative_path adds an extra '/' at the end.
        relative_path = os.path.relpath(url, start=self.base_path)
        relative_path = relative_path.rstrip('/') + suffix

        return utils.path_to_url(relative_path)