diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2019-04-09 00:34:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-09 00:34:02 +0200 |
commit | eb7e29f2a9d075accc1ab3faf3612ac44f5e2183 (patch) | |
tree | 6d4d31556465bc34e12de0ebc98dd751cb0fc09a /Lib/ftplib.py | |
parent | bpo-35416: fix potential resource warnings in distutils (GH-10918) (diff) | |
download | cpython-eb7e29f2a9d075accc1ab3faf3612ac44f5e2183.tar.gz cpython-eb7e29f2a9d075accc1ab3faf3612ac44f5e2183.tar.bz2 cpython-eb7e29f2a9d075accc1ab3faf3612ac44f5e2183.zip |
bpo-35934: Add socket.create_server() utility function (GH-11784)
Diffstat (limited to 'Lib/ftplib.py')
-rw-r--r-- | Lib/ftplib.py | 21 |
1 files changed, 1 insertions, 20 deletions
diff --git a/Lib/ftplib.py b/Lib/ftplib.py index 9611282ecac..a9b1aee39e4 100644 --- a/Lib/ftplib.py +++ b/Lib/ftplib.py @@ -302,26 +302,7 @@ class FTP: def makeport(self): '''Create a new socket and send a PORT command for it.''' - 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 OSError as _: - err = _ - if sock: - sock.close() - sock = None - continue - break - if sock is None: - if err is not None: - raise err - else: - raise OSError("getaddrinfo returns an empty list") - sock.listen(1) + sock = socket.create_server(("", 0), family=self.af, backlog=1) port = sock.getsockname()[1] # Get proper port host = self.sock.getsockname()[0] # Get proper host if self.af == socket.AF_INET: |