[Python-checkins] python/dist/src/Lib urllib.py,1.160,1.161
bcannon at users.sourceforge.net
bcannon at users.sourceforge.net
Tue Mar 23 16:26:42 EST 2004
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5420/Lib
Modified Files:
urllib.py
Log Message:
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.
Index: urllib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/urllib.py,v
retrieving revision 1.160
retrieving revision 1.161
diff -C2 -d -r1.160 -r1.161
*** urllib.py 12 Feb 2004 17:35:07 -0000 1.160
--- urllib.py 23 Mar 2004 21:26:39 -0000 1.161
***************
*** 28,31 ****
--- 28,32 ----
import time
import sys
+ from urlparse import urljoin as basejoin
__all__ = ["urlopen", "URLopener", "FancyURLopener", "urlretrieve",
***************
*** 37,41 ****
"splitgophertype", "getproxies"]
! __version__ = '1.15' # XXX This version is not always updated :-(
MAXFTPCACHE = 10 # Trim the ftp cache beyond this size
--- 38,42 ----
"splitgophertype", "getproxies"]
! __version__ = '1.16' # XXX This version is not always updated :-(
MAXFTPCACHE = 10 # Trim the ftp cache beyond this size
***************
*** 846,907 ****
- def basejoin(base, url):
- """Utility to combine a URL with a base URL to form a new URL."""
- type, path = splittype(url)
- if type:
- # if url is complete (i.e., it contains a type), return it
- return url
- host, path = splithost(path)
- type, basepath = splittype(base) # inherit type from base
- if host:
- # if url contains host, just inherit type
- if type: return type + '://' + host + path
- else:
- # no type inherited, so url must have started with //
- # just return it
- return url
- host, basepath = splithost(basepath) # inherit host
- basepath, basetag = splittag(basepath) # remove extraneous cruft
- basepath, basequery = splitquery(basepath) # idem
- if path[:1] != '/':
- # non-absolute path name
- if path[:1] in ('#', '?'):
- # path is just a tag or query, attach to basepath
- i = len(basepath)
- else:
- # else replace last component
- i = basepath.rfind('/')
- if i < 0:
- # basepath not absolute
- if host:
- # host present, make absolute
- basepath = '/'
- else:
- # else keep non-absolute
- basepath = ''
- else:
- # remove last file component
- basepath = basepath[:i+1]
- # Interpret ../ (important because of symlinks)
- while basepath and path[:3] == '../':
- path = path[3:]
- i = basepath[:-1].rfind('/')
- if i > 0:
- basepath = basepath[:i+1]
- elif i == 0:
- basepath = '/'
- break
- else:
- basepath = ''
-
- path = basepath + path
- if host and path and path[0] != '/':
- path = '/' + path
- if type and host: return type + '://' + host + path
- elif type: return type + ':' + path
- elif host: return '//' + host + path # don't know what this means
- else: return path
-
-
# Utilities to parse URLs (most of these return None for missing parts):
# unwrap('<URL:type://host/path>') --> 'type://host/path'
--- 847,850 ----
More information about the Python-checkins
mailing list