]> granicus.if.org Git - python/commitdiff
Issue #23881: urllib.request.ftpwrapper constructor now closes the socket if
authorVictor Stinner <victor.stinner@gmail.com>
Tue, 7 Apr 2015 10:49:27 +0000 (12:49 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Tue, 7 Apr 2015 10:49:27 +0000 (12:49 +0200)
the FTP connection failed to fix a ResourceWarning.

Lib/urllib/request.py
Misc/NEWS

index 6da9007ac80ee4c587bb5882beb65deb44e0bfe3..5cf0cf2e86a175c7d44231e2e116f030ce5937bd 100644 (file)
@@ -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
index a8c7eccf7e3e108bc5d2c539e60a66bac8909c17..645e1ade1bb1c810b13da88c1f1491e61625fde8 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -24,6 +24,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 #15133: _tkinter.tkapp.getboolean() now supports Tcl_Obj and always
   returns bool.  tkinter.BooleanVar now validates input values (accepted bool,
   int, str, and Tcl_Obj).  tkinter.BooleanVar.get() now always returns bool.