summaryrefslogtreecommitdiff
path: root/Lib/urllib/request.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-04-07 12:49:27 +0200
committerVictor Stinner <victor.stinner@gmail.com>2015-04-07 12:49:27 +0200
commited425281fc1bbd7fffedaede15c92b51992281f8 (patch)
tree0fa7f7b3db93654ae4783ca72510e1799962649d /Lib/urllib/request.py
parent4488726ba566c7c0333d6b5607f2a303333aae3e (diff)
downloadcpython-ed425281fc1bbd7fffedaede15c92b51992281f8.tar.gz
Issue #23881: urllib.request.ftpwrapper constructor now closes the socket if
the FTP connection failed to fix a ResourceWarning.
Diffstat (limited to 'Lib/urllib/request.py')
-rw-r--r--Lib/urllib/request.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
index 6da9007ac8..5cf0cf2e86 100644
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -2240,7 +2240,11 @@ class ftpwrapper:
self.timeout = timeout
self.refcount = 0
self.keepalive = persistent
- self.init()
+ try:
+ self.init()
+ except:
+ self.close()
+ raise
def init(self):
import ftplib