[Python-checkins] cpython (merge 3.4 -> default): (Merge 3.4) Issue #23881: urllib.request.ftpwrapper constructor now closes the
victor.stinner
python-checkins at python.org
Tue Apr 7 12:50:48 CEST 2015
https://hg.python.org/cpython/rev/1a72c0a1a50f
changeset: 95468:1a72c0a1a50f
parent: 95464:9a0caf6e7a16
parent: 95467:7b168db16e67
user: Victor Stinner <victor.stinner at gmail.com>
date: Tue Apr 07 12:50:24 2015 +0200
summary:
(Merge 3.4) Issue #23881: urllib.request.ftpwrapper constructor now closes the
socket if the FTP connection failed to fix a ResourceWarning.
files:
Lib/urllib/request.py | 6 +++++-
Misc/NEWS | 3 +++
2 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -2255,7 +2255,11 @@
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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -19,6 +19,9 @@
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.
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list