changeset: 95467:7b168db16e67 branch: 3.4 parent: 95463:7e2a7de211b4 user: Victor Stinner date: Tue Apr 07 12:49:27 2015 +0200 files: Lib/urllib/request.py Misc/NEWS description: Issue #23881: urllib.request.ftpwrapper constructor now closes the socket if the FTP connection failed to fix a ResourceWarning. diff -r 7e2a7de211b4 -r 7b168db16e67 Lib/urllib/request.py --- a/Lib/urllib/request.py Tue Apr 07 01:29:33 2015 -0400 +++ b/Lib/urllib/request.py Tue Apr 07 12:49:27 2015 +0200 @@ -2240,7 +2240,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 -r 7e2a7de211b4 -r 7b168db16e67 Misc/NEWS --- a/Misc/NEWS Tue Apr 07 01:29:33 2015 -0400 +++ b/Misc/NEWS Tue Apr 07 12:49:27 2015 +0200 @@ -24,6 +24,9 @@ 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.