Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Lib/test/test_urllib2net.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ def setUp(self):
# They do sometimes catch some major disasters, though.

def test_ftp(self):
# Testing the same URL twice exercises the caching in CacheFTPHandler
urls = [
'ftp://www.pythontest.net/README',
'ftp://www.pythontest.net/README',
('ftp://www.pythontest.net/non-existent-file',
None, urllib.error.URLError),
Expand Down
6 changes: 6 additions & 0 deletions Lib/urllib/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -2469,7 +2469,13 @@ def retrfile(self, file, type):
return (ftpobj, retrlen)

def endtransfer(self):
if not self.busy:
return
self.busy = 0
try:
self.ftp.voidresp()
except ftperrors():
pass

def close(self):
self.keepalive = False
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:class:`urllib.request.CacheFTPHandler` no longer raises :class:`URLError`
if a cached FTP instance is reused. ftplib's endtransfer method calls
voidresp to drain the connection to handle FTP instance reuse properly.