def cb(url, criterion): # Resolve the link URL with respect to the current (fake) URL link_url = rfc3986_urljoin(fake_current_url, url) # Convert the fake URL into an absolute real URL link_url = rebase_url(link_url, fake_base_url, real_base_url) if not always_absolute: # Convert the absolute URL into a relative URL link_url = relative_url(link_url, real_current_url) return link_url
def test_relative_url(self): """relative_url""" from StillWeb.sw_urllib import relative_url # Basic tests self.assertEqual("http://xyz", relative_url("http://xyz", "http://a/b/c/")) self.assertEqual("http://xyz/b/c/", relative_url("http://xyz/b/c/", "http://a/b/c/")) self.assertEqual("../", relative_url("http://a/b/", "http://a/b/c/")) self.assertEqual("../d", relative_url("http://a/b/d", "http://a/b/c/")) self.assertEqual("../d/", relative_url("http://a/b/d/", "http://a/b/c/")) self.assertEqual("../../e/f/gee.html", relative_url("http://a/e/f/gee.html", "http://a/b/c/dee.html")) self.assertEqual("../../e/f.html", relative_url("http://a/e/f.html", "http://a/b/c/dee.html")) # Test allow_empty self.assertEqual("", relative_url("http://a/b/c/", "http://a/b/c/", allow_empty=True)) # Test allow_net self.assertEqual("//xyz/b/c/", relative_url("http://xyz/b/c/", "http://a/b/c/", allow_net=True)) # Relative input URLs self.assertEqual("./", relative_url("./", "http://a/b/c/")) self.assertEqual("../", relative_url("../", "http://a/b/c/")) self.assertEqual("./", relative_url("foo/../", "http://a/b/c/"))