[Python-Dev] urllib2

Paul Prescod paulp@ActiveState.com
Wed, 06 Jun 2001 16:00:52 -0700

Tim asked me to look into test_urllib2 failure. I notice that Guido's
name is in the relevant RFC so I guess he's the real expert <0.5 wink>:


Anyhow, there are a variety of problems. :(

First, test_urllib2 says:

   file_url = "file://%s" % urllib2.__file__

This is not going to construct a strictly standards conforming URL on
Windows but that form is still common enough and obvious enough that
maybe we should support it. So that's problem #1, we aren't compatible
with mildly broken Windows file URLs. Problem #2 is that the test
program generates mildly broken URLs on Windows.

That begs the question of what IS the right way to construct file urls
in a cross-platform manner. I would have thought that
urllib.pathname2url was the way but I note that it isn't documented.
Plus it is poorly named. A function that does this:

"""Convert a DOS path name to a file url.




is not really constructing a URL! And the semantics of the function on
multiple platforms do not seem to me to be identical. On Windows it adds
a bunch of leading slashes and mac and Unix seem not to. So you can't
safely paste a "file:" or "file://" on the front. I don't know how
widely pathname2url has been used even though it is
undocumented....should we fix it and document it or write a new
Take a recipe. Leave a recipe.  
Python Cookbook!  http://www.ActiveState.com/pythoncookbook