How to use the urlpath.relpath function in urlpath

To help you get started, we’ve selected a few urlpath examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github miracle2k / webassets / src / webassets / filter / cssrewrite / __init__.py View on Github external
else:
                            replacement = urlpath.relpathto(self.env.directory, self.output_path, asset_path)

                    if replacement is None:
                        url = urlpath.relpath(self.output_url,
                            urlparse.urljoin(self.source_url, url))
                    else:
                        url = replacement

            else:
                # Default mode: auto correct relative urls
                # If path is an absolute one, keep it
                if not self._is_abs_url(url):
                    # rewritten url: relative path from new location (output)
                    # to location of referenced file (source + current url)
                    url = urlpath.relpath(self.output_url,
                        urlparse.urljoin(self.source_url, url))

        return url
github miracle2k / webassets / src / webassets / filter / cssrewrite / __init__.py View on Github external
if asset_path is not None:
                        if self.env.url:
                            # see if it's a complete url (rather than a folder)
                            # otherwise we want a relative path in the CSS
                            if self.env.url.startswith('http://')\
                                or self.env.url.startswith('https://')\
                                or self.env.url.startswith('//'):
                                replacement = urlparse.urljoin(self.env.url, asset_path)
                            else:
                                replacement = urlpath.relpathto(self.env.directory, self.output_path, self.env.absurl(asset_path))
                        else:
                            replacement = urlpath.relpathto(self.env.directory, self.output_path, asset_path)

                    if replacement is None:
                        url = urlpath.relpath(self.output_url,
                            urlparse.urljoin(self.source_url, url))
                    else:
                        url = replacement

            else:
                # Default mode: auto correct relative urls
                # If path is an absolute one, keep it
                if not self._is_abs_url(url):
                    # rewritten url: relative path from new location (output)
                    # to location of referenced file (source + current url)
                    url = urlpath.relpath(self.output_url,
                        urlparse.urljoin(self.source_url, url))

        return url

urlpath

Object-oriented URL from `urllib.parse` and `pathlib`

Python-2.0
Latest version published 2 years ago

Package Health Score

52 / 100
Full package analysis