summaryrefslogtreecommitdiffstats
path: root/Lib/urlopen.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1994-03-07 11:45:36 (GMT)
committerGuido van Rossum <guido@python.org>1994-03-07 11:45:36 (GMT)
commitd1df83ba6c2c7dfb6e792c46e3fccb2c1d2310cc (patch)
tree71c6365321dc509011e2953e428cfd7df4c2c0cc /Lib/urlopen.py
parentd66acb45f8b44495379e20a4eceb2eea1ec921b2 (diff)
downloadcpython-d1df83ba6c2c7dfb6e792c46e3fccb2c1d2310cc.zip
cpython-d1df83ba6c2c7dfb6e792c46e3fccb2c1d2310cc.tar.gz
cpython-d1df83ba6c2c7dfb6e792c46e3fccb2c1d2310cc.tar.bz2
urlopen: add basejoin() function.
addpack: new module to add packages to sys.path.
Diffstat (limited to 'Lib/urlopen.py')
-rwxr-xr-xLib/urlopen.py22
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'