-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
[2.7] bpo-27973 - Fix for urllib.urlretrieve() failing on second ftp transfer #1040
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Misc/NEWS
Outdated
@@ -42,6 +42,8 @@ Extension Modules | |||
Library | |||
------- | |||
|
|||
- bpo-27973 - Fix for urllib.urlretrieve() failing on second ftp transfer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed :
. The second -
is not needed.
Lib/test/test_urllibnet.py
Outdated
try: | ||
for _ in range(3): | ||
fp = urllib.urlopen(self.FTP_TEST_FILE) | ||
# closing fp is not required. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test can behave differently in CPython and PyPy. If fp can remain unclosed, maybe save it in a list, so that it will not be closed in all implementations? If the file is not closed explicitly it is worth to call test_support.gc_collect() after removing all references to it. This will make the behavior more predicable in all implementations.
Lib/test/test_urllibnet.py
Outdated
for _ in range(3): | ||
urllib.FancyURLopener().retrieve( | ||
self.FTP_TEST_FILE, | ||
tempfile.NamedTemporaryFile().name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The NamedTemporaryFile object can be collected right after getting its name. Save a reference to tempfile.NamedTemporaryFile() until retrieve a file or better use a context manager.
Has this fix stalled? I'm able to reproduce this problem in Python 2.7.13 with the following steps:
These steps result in this error:
|
Lib/test/test_urllibnet.py
Outdated
@@ -213,14 +214,44 @@ def test_context_argument(self): | |||
self.assertIn("Python", response.read()) | |||
|
|||
|
|||
class urlopen_FTPTest(unittest.TestCase): | |||
# TODO: https://github.com/python/pythondotorg/issues/1069 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that this TODO is no longer needed.
Lib/test/test_urllibnet.py
Outdated
|
||
with test_support.transient_internet(self.FTP_TEST_FILE): | ||
try: | ||
for _ in range(3): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for _ in range(3):
is used a couple of times in this class. I think the 3 should be replaced with a constant.
Lib/test/test_urllibnet.py
Outdated
fp = urllib.urlopen(self.FTP_TEST_FILE) | ||
# closing fp is not required. | ||
except IOError as e: | ||
self.fail("Failed FTP binary file open." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a space after this period (or a space just before the "Error" on the next line).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you still want to pursue this, it will need to be rebased and blurbed.
When you're done making the requested changes, leave the comment: |
I have made the requested changes; please review again. @benjaminp - Please take a call to include the final 2.7 release. Thanks. |
Thanks for making the requested changes! @benjaminp: please review the changes made to this pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is essentially a revert, it seems good.
@orsenthil: Please replace |
This PR is failing in several 2.7 buildbots:
Example failure: |
The problem and the solution has been described well in the msg: http://bugs.python.org/issue27973#msg286016
This just brings the patch to github.
https://bugs.python.org/issue27973