def canonical_url(url): "Converts a string to a Cargo Canonical URL, as per https://github.com/rust-lang/cargo/blob/35c55a93200c84a4de4627f1770f76a8ad268a39/src/cargo/util/canonical_url.rs#L19" u = urlparse(url) # It seems cargo drops query and fragment u = ParseResult(u.scheme, u.netloc, u.path, None, None, None) u = u._replace(path = u.path.rstrip('/')) if u.netloc == "github.com": u = u._replace(scheme = "https") u = u._replace(path = u.path.lower()) if u.path.endswith(".git"): u.path = u.path[:-len(".git")] return u
def canonical_url(url): "Converts a string to a Cargo Canonical URL, as per https://github.com/rust-lang/cargo/blob/35c55a93200c84a4de4627f1770f76a8ad268a39/src/cargo/util/canonical_url.rs#L19" logging.debug("canonicalising %s", url) # Hrm. The upstream cargo does not replace those URLs, but if we don't then it doesn't work too well :( url = url.replace("git+https://", "https://") u = urlparse(url) # It seems cargo drops query and fragment u = ParseResult(u.scheme, u.netloc, u.path, None, None, None) u = u._replace(path=u.path.rstrip('/')) if u.netloc == "github.com": u = u._replace(scheme="https") u = u._replace(path=u.path.lower()) if u.path.endswith(".git"): u.path = u.path[:-len(".git")] return u