summaryrefslogtreecommitdiffstats
path: root/Lib/urllib2.py
diff options
context:
space:
mode:
authorNadeem Vawda <nadeem.vawda@gmail.com>2011-07-23 13:51:16 (GMT)
committerNadeem Vawda <nadeem.vawda@gmail.com>2011-07-23 13:51:16 (GMT)
commitb42c53e442b211d0ded1d4c9abd18c74d29ed663 (patch)
tree0ad39ae840da96efaa2ff6bdb49f2c44a226c0aa /Lib/urllib2.py
parent578617ad453c399ea52c0aef937fdf0904b2213c (diff)
downloadcpython-b42c53e442b211d0ded1d4c9abd18c74d29ed663.zip
cpython-b42c53e442b211d0ded1d4c9abd18c74d29ed663.tar.gz
cpython-b42c53e442b211d0ded1d4c9abd18c74d29ed663.tar.bz2
Issue #10883: Fix socket leaks in urllib.request.
* ftpwrapper now uses reference counting to ensure that the underlying socket is closed when the ftpwrapper object is no longer in use * ftplib.FTP.ntransfercmd() now closes the socket if an error occurs Initial patch by Victor Stinner.
Diffstat (limited to 'Lib/urllib2.py')
-rw-r--r--Lib/urllib2.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/urllib2.py b/Lib/urllib2.py
index 2641619..2bce745 100644
--- a/Lib/urllib2.py
+++ b/Lib/urllib2.py
@@ -1399,7 +1399,8 @@ class FTPHandler(BaseHandler):
raise URLError, ('ftp error: %s' % msg), sys.exc_info()[2]
def connect_ftp(self, user, passwd, host, port, dirs, timeout):
- fw = ftpwrapper(user, passwd, host, port, dirs, timeout)
+ fw = ftpwrapper(user, passwd, host, port, dirs, timeout,
+ persistent=False)
## fw.ftp.set_debuglevel(1)
return fw
@@ -1448,3 +1449,9 @@ class CacheFTPHandler(FTPHandler):
del self.timeout[k]
break
self.soonest = min(self.timeout.values())
+
+ def clear_cache(self):
+ for conn in self.cache.values():
+ conn.close()
+ self.cache.clear()
+ self.timeout.clear()