summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-04-07 10:50:24 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-04-07 10:50:24 (GMT)
commita9dd680d238a5296a8c537b715aadd60a5817120 (patch)
tree18116d34aee27d49be61e749d798afff92037c8f
parent9bcbdb40da0da2213c23a8d87ae57e6cbe6e616f (diff)
parentab73e65032565029fdd00e73936dc3b4a197bef6 (diff)
downloadcpython-a9dd680d238a5296a8c537b715aadd60a5817120.zip
cpython-a9dd680d238a5296a8c537b715aadd60a5817120.tar.gz
cpython-a9dd680d238a5296a8c537b715aadd60a5817120.tar.bz2
(Merge 3.4) Issue #23881: urllib.request.ftpwrapper constructor now closes the
socket if the FTP connection failed to fix a ResourceWarning.
-rw-r--r--Lib/urllib/request.py6
-rw-r--r--Misc/NEWS3
2 files changed, 8 insertions, 1 deletions
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
index 3ba7c01..2e436ec 100644
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -2255,7 +2255,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
diff --git a/Misc/NEWS b/Misc/NEWS
index 7b64a89..5093208 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -19,6 +19,9 @@ Core and Builtins
Library
-------
+- Issue #23881: urllib.request.ftpwrapper constructor now closes the socket if
+ the FTP connection failed to fix a ResourceWarning.
+
- Issue #23853: :meth:`socket.socket.sendall` does no more reset the socket
timeout each time data is sent successfuly. The socket timeout is now the
maximum total duration to send all data.