summaryrefslogtreecommitdiffstats
path: root/Lib/poplib.py
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2001-07-24 20:34:08 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2001-07-24 20:34:08 (GMT)
commita43c2f845e59b833b17e45994cd81c631c071236 (patch)
tree76fcd97361c26474054557e554fc548770431acf /Lib/poplib.py
parentd61e3eab449102834406b9026852e1db51de16bb (diff)
downloadcpython-a43c2f845e59b833b17e45994cd81c631c071236.zip
cpython-a43c2f845e59b833b17e45994cd81c631c071236.tar.gz
cpython-a43c2f845e59b833b17e45994cd81c631c071236.tar.bz2
Patch #401196: Use getaddrinfo and AF_INET6 in TCP servers and clients.
Diffstat (limited to 'Lib/poplib.py')
-rw-r--r--Lib/poplib.py24
1 files changed, 17 insertions, 7 deletions
diff --git a/Lib/poplib.py b/Lib/poplib.py
index fb24a0f..c6c432d 100644
--- a/Lib/poplib.py
+++ b/Lib/poplib.py
@@ -73,13 +73,23 @@ class POP3:
def __init__(self, host, port = POP3_PORT):
- self.host = host
- self.port = port
- self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- self.sock.connect((self.host, self.port))
- self.file = self.sock.makefile('rb')
- self._debugging = 0
- self.welcome = self._getresp()
+ self.host = host
+ self.port = port
+ for res in socket.getaddrinfo(self.host, self.port, 0, socket.SOCK_STREAM):
+ af, socktype, proto, canonname, sa = res
+ try:
+ self.sock = socket.socket(af, socktype, proto)
+ self.sock.connect(sa)
+ except socket.error, msg:
+ self.sock.close()
+ self.sock = None
+ continue
+ break
+ if not self.sock:
+ raise socket.error, msg
+ self.file = self.sock.makefile('rb')
+ self._debugging = 0
+ self.welcome = self._getresp()
def _putline(self, line):