Author martin.panter
Recipients martin.panter, orsenthil, python-dev, r.david.murray
Date 2015-05-27.05:31:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1432704703.18.0.256209299196.issue21970@psf.upfronthosting.co.za>
In-reply-to
Content
I do not believe the change fixes anything on its own. It essentially just changed the error message to something even worse, and the added test case already passes without the change.

I am posting a patch which cleans up the code and related tests. It also fixes three minor theoretical bugs:

>>> urlopen("file://127.0.0.1//dev/null")  # Should succeed
urllib.error.URLError: <urlopen error unknown url type: file>
>>> urlopen("file://127.1//dev/null")  # 127.1 is localhost; should succeed
urllib.error.URLError: <urlopen error file:// scheme is supported only on localhost>
>>> urlopen("file://remote/missing")  # Should not try to access local file
urllib.error.URLError: <urlopen error [Errno 2] No such file or directory: '/missing'>

The localhost check in file_open() was added by revision 982c8ec73ae3 for Issue 10063. But notice how all the test cases involve strange URLs like file://ftp.example.com//foo.txt, with second extra double slash. I removed the check, because it is redundant with the more thorough and correct check that has existed since 1994 (revision 020d8c2d9d3c) in open_local_file().

For cases like file://remote/nonlocal-file, I think it is better to raise the correct error, even if that requires a DNS check, rather than raising a faster error with a misleading message. So I moved the check before the stat() call inside open_local_file().
History
Date User Action Args
2015-05-27 05:31:43martin.pantersetrecipients: + martin.panter, orsenthil, r.david.murray, python-dev
2015-05-27 05:31:43martin.pantersetmessageid: <1432704703.18.0.256209299196.issue21970@psf.upfronthosting.co.za>
2015-05-27 05:31:43martin.panterlinkissue21970 messages
2015-05-27 05:31:42martin.pantercreate