httplib and socket.getaddrinfo

mirandacascade at yahoo.com mirandacascade at yahoo.com
Sat Dec 23 02:21:20 EST 2006


I noticed the following lines from the connect() method of the
HTTPConnection class within httplib:

        for res in socket.getaddrinfo(self.host, self.port, 0,
                                      socket.SOCK_STREAM):
            af, socktype, proto, canonname, sa = res

This led me to the docs that describe the socket.getaddrinfo() method:

http://www.python.org/doc/2.4.1/lib/module-socket.html

Which leads me to these questions:
1) Is it correct to infer from the "Resolves the host/port argument,
into a sequence of 5-tuples that contain all the necessary argument for
the sockets manipulation" description in the docs (in particular the
reference to 'sequence of 5-tuples') that a single host/port
combination may be associated with multiple sets of address
information?

2) In the very limited applications on which I've used
socket.getaddrinfo(), each a host/port combination that my application
passes to socket.getaddrinfo() has always returned a 1-entry list where
the list is a 5-tuple, in other words, each host/port combination has
always been associated with one set of address information.  Can
someone point me to a host/port combination that, when passed to
socket.getaddrinfo() will result in socket.getaddrinfo() returning a
list of > 1 entry, where each entry is a 5-tuple?

Thank you.




More information about the Python-list mailing list