[Python-checkins] cpython (merge 3.2 -> 3.3): Fix issue #16646: ftplib.FTP.makeport() might lose socket error details.

giampaolo.rodola python-checkins at python.org
Mon Dec 17 14:24:58 CET 2012


http://hg.python.org/cpython/rev/b8289a08d720
changeset: 80906:b8289a08d720
branch: 3.3
parent: 80903:fefe2fe93232
parent: 80905:b7419f88c628
user: Giampaolo Rodola' <g.rodola at gmail.com>
date: Mon Dec 17 14:22:19 2012 +0100
summary:
 Fix issue #16646: ftplib.FTP.makeport() might lose socket error details. (patch by Serhiy Storchaka)
files:
 Lib/ftplib.py | 10 +++++++---
 Misc/NEWS | 3 +++
 2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/Lib/ftplib.py b/Lib/ftplib.py
--- a/Lib/ftplib.py
+++ b/Lib/ftplib.py
@@ -288,20 +288,24 @@
 
 def makeport(self):
 '''Create a new socket and send a PORT command for it.'''
- msg = "getaddrinfo returns an empty list"
+ err = None
 sock = None
 for res in socket.getaddrinfo(None, 0, self.af, socket.SOCK_STREAM, 0, socket.AI_PASSIVE):
 af, socktype, proto, canonname, sa = res
 try:
 sock = socket.socket(af, socktype, proto)
 sock.bind(sa)
- except socket.error as msg:
+ except socket.error as err:
 if sock:
 sock.close()
 sock = None
 continue
 break
- if not sock:
+ if sock is None:
+ if err is not None:
+ raise err
+ else:
+ raise socket.error("getaddrinfo returns an empty list")
 raise socket.error(msg)
 sock.listen(1)
 port = sock.getsockname()[1] # Get proper port
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -108,6 +108,9 @@
 Library
 -------
 
+- Issue #16646: ftplib.FTP.makeport() might lose socket error details.
+ (patch by Serhiy Storchaka)
+
 - Issue #16626: Fix infinite recursion in glob.glob() on Windows when the
 pattern contains a wildcard in the drive or UNC path. Patch by Serhiy
 Storchaka.
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /