Bugs item #1685962, was opened at 2007-03-22 13:10
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1685962&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Feature Request
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Alan Kennedy (amak)
Assigned to: Nobody/Anonymous (nobody)
Summary: socket.getaddrinfo() should take an address tuple.
Initial Comment:
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.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1685962&group_id=5470
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com