FAQ
"John J. Lee" <jjl at pobox.com> wrote in message
news:87n0e1zqzh.fsf at pobox.com...
"Michael Geary" <Mike at DeleteThis.Geary.com> writes:
MAK wrote:
[...]
If I were to use, say, Netscape to open this file, I'd specify it as
"file:///c:/mypage.html", and it would open it just fine. But
urlopen() won't accept it as a valid URL. I get an OSError
exception with the error message "No such file or directory:
'\\C:\\mypage.html'".
[...]
f = urllib2.urlopen( 'file:///c|/mypage.html' )
Why does Python use a different syntax to the rest of the Windows
world?
On Windows, if I open a local file in Netscape 4, the Location bar shows a
"file" URL with the "|". If I open a local file in Internet Explorer (or the
file Explorer with the Address bar turned on), the Address bar shows a
"file" URL with a ":". The resolver used by both Netscape and Explorer will
accept either one, if you type it in the address bar. So who is to say what
is canon? The 'file' URI scheme is, by definition, OS dependent. If the OS
likes the URL, then it's good enough.

For 4Suite running on Windows, we were thinking of making a Python wrapper
to the Windows resolver for maximum compatibility, but haven't gotten around
to it. For now, we avoid the bug-ridden urllib as much as we can, and do
some voodoo on 'file' URLs to convert them to OS-specific paths that are
safe to pass to open() on the (win32 or posix) OS we're running on. It's not
foolproof yet, and won't handle the colon case, but does a round-trip from
an OS path to a URI and back pretty well. See the UriToOsPath() and
OsPathToUri() work in the Ft.Lib.Uri module here:
http://cvs.4suite.org/cgi-bin/viewcvs.cgi/4Suite/Ft/Lib/Uri.py?rev=1.49&content-type=text/vnd.viewcvs-markup

Search Discussions

Discussion Posts

Previous

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 6 of 6 | next ›
Discussion Overview
grouppython-list @
categoriespython
postedAug 21, '03 at 7:37p
activeAug 22, '03 at 5:47p
posts6
users5
websitepython.org

People

Translate

site design / logo © 2022 Grokbase