This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author amak
Recipients
Date 2007-03-22.13:10:31
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
The getaddrinfo call should not take separate host and port parameters. Instead, it should take the same address tuples as every other python socket function, i.e. it's signature should be

getaddrinfo( address_tuple[, family[, socktype[, proto[, flags]]]]) 

This is because all python socket calls take a (host, port) tuple as an address.

However, functions that take a tuple are then forced to unpack that tuple in order to call getaddrinfo. The problem is that this is error prone. Consider the following code

def my_trivial_socket_function(address_tuple, a=None):
    host, port = address_tuple
    for result in getaddrinfo(host, port, 0, 0, 0):
        whatever(*result)

I can then call this function like so, and get a weird error

my_trivial_socket_function("lo", 80)

because the outcome of 

host, port = "lo"

is

host = "l" ; port = "o"

One solution to this problem is to force every socket function, trivial or otherwise, to do error checking on the address tuple, like so

def my_trivial_socket_function(address_tuple,a=None):
    assert type(address_tuple) is type( () )
    assert type(address_tuple[0]) is type("")
    assert type(address_tuple[1]) is type(0)
    host, port = address_tuple
    for result in getaddrinfo(host, port, 0, 0, 0):
        pass

But since the only reason the function has to unpack the tuple is to pass it to getaddrinfo, then the correct solution is to make getaddrinfo accept the same address format as every other python socket function.
History
Date User Action Args
2007-08-23 14:52:41adminlinkissue1685962 messages
2007-08-23 14:52:41admincreate