[Python-Dev] Adding timeout to socket.py and httplib.py

Guido van Rossum guido at python.org
Thu Mar 22 15:41:20 CET 2007

On 3/22/07, Alan Kennedy <python-dev at alan.kennedy.name> wrote:
> [Alan]
> >> - Explicitly check that the address passed is a tuple of (string, integer)
> [Facundo]
> > In the code, I'll just make "host, port = address", I don't think it
> > will be a problem at all. Remember that this function primary use is for
> > higher level libraries, and that "address" in socket enviroment is
> > always, always, (host, port).
> It's rather unfortunate that the tuple needs to be unpacked at all.


> Instead, it should be possible to simply pass the address tuple
> directly to the socsket.getaddrinfo() function, and let it worry about
> the tuple-ness of the address, raising exceptions accordingly.
> The socket.getaddrinfo() function, unlike every other python socket
> function, takes separate host and port parameters. Which forces every
> user of the socket.getaddrinfo function to do the same unnecessary and
> potentially error-prone address tuple unpacking.
> I have raised a feature request to change this.
> [1685962] socket.getaddrinfo() should take an address tuple.

It's unlikely to be granted. Getaddrinfo(), like gethostname() and a
few other things, lives at a different abstraction level than the
basic socket object; it is only relevant for IP sockets, not for other
types of addresses. The Python call just wraps the system call which
has a similar API. While from a purist POV you might want to move all
IP-related APIs out of the "pure" socket module (and this would
include SSL), in practice, nobody cares.

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-Dev mailing list