import urlparse from urlparse import uses_netloc ### The function, that is patched def urlunsplit((scheme, netloc, url, query, fragment)): if not ( scheme == 'file' and not netloc): if (netloc or (scheme and scheme in uses_netloc and url[:2] != '//')): if url and url[:1] != '/': url = '/' + url url = '//' + (netloc or '') + url if scheme: url = scheme + ':' + url if query: url = url + '?' + query if fragment: url = url + '#' + fragment return url if __name__ == "__main__": example='../../../../work/albert.mietus.nl/index.html' val=urlparse.urlsplit(example, 'file') url=urlunsplit(val) print """The relative file: '%s' is urlsplit, with default scheme=file, and urlunsplit again into: '%s'. When that url contains '//' is it absolute and so wrong !! Note: urllib{,2}.urlopen can open the orginal but not the false copy""" % ( example, url) val2=urlparse.urlsplit(url) print "When the result is urlsplit again, the path parts should be the same" print "example-path: '%s'\n becomes: '%s'" % (val.path, val2.path)