Martin Panter added the comment:

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().

----------
keywords: +patch
stage:  -> patch review
type:  -> behavior
versions: +Python 3.5, Python 3.6
Added file: http://bugs.python.org/file39513/file-handler.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue21970>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to