classification
Title: localhost() and thishost() in urllib/request.py
Type: behavior Stage:
Components: Versions: Python 3.2, Python 3.3, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: orsenthil Nosy List: orsenthil, python-dev, serhiy.storchaka
Priority: normal Keywords:

Created on 2012-10-22 15:29 by orsenthil, last changed 2012-10-27 10:51 by orsenthil. This issue is now closed.

Messages (9)
msg173530 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2012-10-22 15:29
localhost() returns a string and thishost() returns tuple. In urllib/request.py, for file:// protocol, there is a verification to check to if the host is in the localhost and check happens:

socket.gethostbyname(host) in (localhost() + thishost())):

This is clearly wrong for the above mentioned reason. It should be changed to this, wrapping localhost with tuple() or making localhost return a tuple, which will be consistent with thishost

socket.gethostbyname(host) in (tuple(localhost()) + thishost())):
msg173537 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-10-22 16:10
This is wrong too.

>>> tuple('abc')
('a', 'b', 'c')

Use ((localhost(),) + thishost()))
msg173540 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2012-10-22 16:37
Serhiy: Yes. I stand corrected. That snippet suggestion was my mistake.
I think, wrapping the test is better than changing the return of localhost. It would always return a single value. Thanks.
msg173542 - (view) Author: Roundup Robot (python-dev) Date: 2012-10-22 16:43
New changeset 49de26395d1a by Senthil Kumaran in branch 'default':
Issue #16301: Fix the localhost verification in urllib/request.py for file://. Modify tests to use localhost for local temp files, which could make Windows Buildbot (#16300) happy
http://hg.python.org/cpython/rev/49de26395d1a
msg173571 - (view) Author: Roundup Robot (python-dev) Date: 2012-10-23 00:06
New changeset 478cda291bbc by Senthil Kumaran in branch 'default':
Fix the ResourceWarning in test_urllib.py due changes made for #16301. Patch by Berker Peksag
http://hg.python.org/cpython/rev/478cda291bbc
msg173610 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-10-23 13:03
> +        tmp_fileurl = 'file://localhost' + tmp_file

        tmp_fileurl = 'file://localhost/' + tmp_file.replace(os.path.sep, '/')
msg173623 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2012-10-23 16:38
> Serhiy Storchaka added the comment:
>
>> +        tmp_fileurl = 'file://localhost' + tmp_file
>
>         tmp_fileurl = 'file://localhost/' + tmp_file.replace(os.path.sep, '/')

Ok, I realized the mistake. 'file://localhost' + tmpfile is getting
expanded to 'file://localhostc:\something\..'
Yeah, the final '/' missing was the problem.

tmp_file.replace(...) is be better too, initial unwrap was encoding /
and  url2pathname to //. replacing path sep with '/' would be better.

Thanks for the suggestion, Serhiy.
msg173626 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2012-10-23 17:49
Buildbot still failing, but due to different reason.

PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'c:\\users\\buildbot\\appdata\\local\\temp\\tmpwwvqao'

http://buildbot.python.org/all/builders/AMD64%20Windows7%20SP1%203.x/builds/862/steps/test/logs/stdio

fixing.
msg173918 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2012-10-27 10:51
This is fixed in 3.3 and 3.2

3.2 5e71f2712076
3.3 30547e2cd04d
History
Date User Action Args
2012-10-27 10:51:11orsenthilsetstatus: open -> closed
resolution: fixed
messages: + msg173918

versions: - Python 2.7
2012-10-23 17:49:20orsenthilsetmessages: + msg173626
2012-10-23 16:38:41orsenthilsetmessages: + msg173623
2012-10-23 13:03:57serhiy.storchakasetmessages: + msg173610
2012-10-23 00:06:50python-devsetmessages: + msg173571
2012-10-22 16:43:49python-devsetnosy: + python-dev
messages: + msg173542
2012-10-22 16:37:58orsenthilsetmessages: + msg173540
2012-10-22 16:10:53serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg173537
2012-10-22 15:29:05orsenthilcreate