summaryrefslogtreecommitdiffstats
path: root/Lib/httplib.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/httplib.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/httplib.py')
-rw-r--r--Lib/httplib.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/Lib/httplib.py b/Lib/httplib.py
index 1e08539..d566b35 100644
--- a/Lib/httplib.py
+++ b/Lib/httplib.py
@@ -357,10 +357,22 @@ class HTTPConnection:
def connect(self):
"""Connect to the host and port specified in __init__."""
- self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- if self.debuglevel > 0:
- print "connect: (%s, %s)" % (self.host, self.port)
- self.sock.connect((self.host, self.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)
+ if self.debuglevel > 0:
+ print "connect: (%s, %s)" % (self.host, self.port)
+ self.sock.connect(sa)
+ except socket.error, msg:
+ if self.debuglevel > 0:
+ print 'connect fail:', (self.host, self.port)
+ self.sock.close()
+ self.sock = None
+ continue
+ break
+ if not self.sock:
+ raise socket.error, msg
def close(self):
"""Close the connection to the HTTP server."""