Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 69200fa

Browse files
committed
Replace code in urllib for basejoin (undocumented) with urlparse.urljoin .
Test suites for urllib and urlparse run with each other's function to verify correctness of replacement and both test suites pass. Bumped urllib's __version__ attribute up a minor number.
1 parent e05c3e0 commit 69200fa

1 file changed

Lines changed: 2 additions & 59 deletions

File tree

Lib/urllib.py

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import os
2828
import time
2929
import sys
30+
from urlparse import urljoin as basejoin
3031

3132
__all__ = ["urlopen", "URLopener", "FancyURLopener", "urlretrieve",
3233
"urlcleanup", "quote", "quote_plus", "unquote", "unquote_plus",
@@ -36,7 +37,7 @@
3637
"splitnport", "splitquery", "splitattr", "splitvalue",
3738
"splitgophertype", "getproxies"]
3839

39-
__version__ = '1.15' # XXX This version is not always updated :-(
40+
__version__ = '1.16' # XXX This version is not always updated :-(
4041

4142
MAXFTPCACHE = 10 # Trim the ftp cache beyond this size
4243

@@ -845,64 +846,6 @@ def geturl(self):
845846
return self.url
846847

847848

848-
def basejoin(base, url):
849-
"""Utility to combine a URL with a base URL to form a new URL."""
850-
type, path = splittype(url)
851-
if type:
852-
# if url is complete (i.e., it contains a type), return it
853-
return url
854-
host, path = splithost(path)
855-
type, basepath = splittype(base) # inherit type from base
856-
if host:
857-
# if url contains host, just inherit type
858-
if type: return type + '://' + host + path
859-
else:
860-
# no type inherited, so url must have started with //
861-
# just return it
862-
return url
863-
host, basepath = splithost(basepath) # inherit host
864-
basepath, basetag = splittag(basepath) # remove extraneous cruft
865-
basepath, basequery = splitquery(basepath) # idem
866-
if path[:1] != '/':
867-
# non-absolute path name
868-
if path[:1] in ('#', '?'):
869-
# path is just a tag or query, attach to basepath
870-
i = len(basepath)
871-
else:
872-
# else replace last component
873-
i = basepath.rfind('/')
874-
if i < 0:
875-
# basepath not absolute
876-
if host:
877-
# host present, make absolute
878-
basepath = '/'
879-
else:
880-
# else keep non-absolute
881-
basepath = ''
882-
else:
883-
# remove last file component
884-
basepath = basepath[:i+1]
885-
# Interpret ../ (important because of symlinks)
886-
while basepath and path[:3] == '../':
887-
path = path[3:]
888-
i = basepath[:-1].rfind('/')
889-
if i > 0:
890-
basepath = basepath[:i+1]
891-
elif i == 0:
892-
basepath = '/'
893-
break
894-
else:
895-
basepath = ''
896-
897-
path = basepath + path
898-
if host and path and path[0] != '/':
899-
path = '/' + path
900-
if type and host: return type + '://' + host + path
901-
elif type: return type + ':' + path
902-
elif host: return '//' + host + path # don't know what this means
903-
else: return path
904-
905-
906849
# Utilities to parse URLs (most of these return None for missing parts):
907850
# unwrap('<URL:type://host/path>') --> 'type://host/path'
908851
# splittype('type:opaquestring') --> 'type', 'opaquestring'

0 commit comments

Comments
 (0)