|
27 | 27 | import os |
28 | 28 | import time |
29 | 29 | import sys |
| 30 | +from urlparse import urljoin as basejoin |
30 | 31 |
|
31 | 32 | __all__ = ["urlopen", "URLopener", "FancyURLopener", "urlretrieve", |
32 | 33 | "urlcleanup", "quote", "quote_plus", "unquote", "unquote_plus", |
|
36 | 37 | "splitnport", "splitquery", "splitattr", "splitvalue", |
37 | 38 | "splitgophertype", "getproxies"] |
38 | 39 |
|
39 | | -__version__ = '1.15' # XXX This version is not always updated :-( |
| 40 | +__version__ = '1.16' # XXX This version is not always updated :-( |
40 | 41 |
|
41 | 42 | MAXFTPCACHE = 10 # Trim the ftp cache beyond this size |
42 | 43 |
|
@@ -845,64 +846,6 @@ def geturl(self): |
845 | 846 | return self.url |
846 | 847 |
|
847 | 848 |
|
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 | | - |
906 | 849 | # Utilities to parse URLs (most of these return None for missing parts): |
907 | 850 | # unwrap('<URL:type://host/path>') --> 'type://host/path' |
908 | 851 | # splittype('type:opaquestring') --> 'type', 'opaquestring' |
|
0 commit comments