diff options
Diffstat (limited to 'Lib/urlopen.py')
-rwxr-xr-x | Lib/urlopen.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/urlopen.py b/Lib/urlopen.py index 47f0f20..c43b7f4 100755 --- a/Lib/urlopen.py +++ b/Lib/urlopen.py @@ -303,6 +303,28 @@ class addinfo(addbase): return self.headers +# Utility to combine a URL with a base URL to form a new URL + +def basejoin(base, url): + type, path = splittype(url) + if type: return url + host, path = splithost(path) + basetype, basepath = splittype(base) + basehost, basepath = splithost(basepath) + basepath, basetag = splittag(basepath) + basepath, basequery = splitquery(basepath) + type = basetype or 'file' + if path[:1] != '/': + import string + i = string.rfind(basepath, '/') + if i < 0: basepath = '/' + else: basepath = basepath[:i+1] + path = basepath + path + if not host: host = basehost + if host: return type + '://' + host + path + else: return type + ':' + path + + # Utilities to parse URLs: # unwrap('<URL:type//host/path>') --> 'type//host/path' # splittype('type:opaquestring') --> 'type', 'opaquestring' |