]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Add hacks for switching protocol and path but leaving host unchanged
authorGuido van Rossum <guido@python.org>
Fri, 30 Dec 1994 17:18:59 +0000 (17:18 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 30 Dec 1994 17:18:59 +0000 (17:18 +0000)
Lib/urllib.py
Lib/urlparse.py

index 651e37fc18ffb18522c215f6ecd595ed0f6f4ae4..c49f032066bf1fc34db6e3261d41abf114b65378 100644 (file)
@@ -350,13 +350,13 @@ class addinfo(addbase):
 
 def basejoin(base, url):
        type, path = splittype(url)
-       if type: return url
        host, path = splithost(path)
+       if type and host: return url
        basetype, basepath = splittype(base)
        basehost, basepath = splithost(basepath)
        basepath, basetag = splittag(basepath)
        basepath, basequery = splitquery(basepath)
-       type = basetype or 'file'
+       if not type: type = basetype or 'file'
        if path[:1] != '/':
                i = string.rfind(basepath, '/')
                if i < 0: basepath = '/'
index 37fe62aad8164c085b7841ecdac66fba586cd5f5..9fce0bd8517e47a77a3cc103129e11cb4fe979ac 100644 (file)
@@ -88,6 +88,18 @@ def urljoin(base, url, allow_framents = 1):
                  urlparse(base, '', allow_framents)
        scheme, netloc, path, params, query, fragment = \
                urlparse(url, bscheme, allow_framents)
+       # XXX Unofficial hack: default netloc to bnetloc even if
+       # schemes differ
+       if scheme != bscheme and not netloc and \
+          scheme in uses_relative and bscheme in uses_relative and \
+          scheme in uses_netloc and bscheme in uses_netloc:
+          netloc = bnetloc
+          # Strip the port number
+          i = string.find(netloc, '@')
+          if i < 0: i = 0
+          i = string.find(netloc, ':', i)
+          if i >= 0:
+                  netloc = netloc[:i]
        if scheme != bscheme or scheme not in uses_relative:
                return urlunparse((scheme, netloc, path,
                                   params, query, fragment))