msg106916 - (view) |
Author: Giampaolo Rodola' (giampaolo.rodola) *  |
Date: 2010-06-02 21:31 |
As of right now socket.getaddrinfo() returns a sequence of 5-tuples reflecting family, type, protocol, canonname, and address of a socket: >>> socket.getaddrinfo(None, 0) [(10, 1, 6, '', ('::1', 0, 0, 0)), (10, 2, 17, '', ('::1', 0, 0, 0)), (10, 3, 0, '', ('::1', 0, 0, 0)), (2, 1, 6, '', ('127.0.0.1', 0)), (2, 2, 17, '', ('127.0.0.1', 0)), (2, 3, 0, '', ('127.0.0.1', 0))] For readability it would be good if they were named tuples instead: >>> socket.getaddrinfo(None, 0)[0] addr_info(family=10, type=1, protocol=6, canonname='', address=('::1', 0, 0, 0)) Optionally, integers can be replaced by socket constant names: >>> socket.getaddrinfo(None, 0)[0] addr_info(family=socket.AF_INET6, type=socket.SOCK_STREAM, protocol=socket.IPPROTO_TCP, canonname='', address=('::1', 0, 0, 0)) |
|
|
msg106919 - (view) |
Author: Eric V. Smith (eric.smith) *  |
Date: 2010-06-02 21:52 |
Keep in mind this isn't an entirely backwards compatible change. See issue 8413, for example. |
|
|
msg151200 - (view) |
Author: Floris Bruynooghe (flub) |
Date: 2012-01-13 22:14 |
I think the part which could possibly a problem is addressed in http://hg.python.org/cpython/rev/384f73a104e9/. Bearing in mind that direct usage for string interpolation is a pretty strange use for the result of getaddrinfo. |
|
|
msg151201 - (view) |
Author: Antoine Pitrou (pitrou) *  |
Date: 2012-01-13 22:15 |
A reasonable request indeed. |
|
|
msg164816 - (view) |
Author: Floris Bruynooghe (flub) |
Date: 2012-07-07 10:46 |
Attached in a patch for this, I've also changed the version to 3.4 since this is a feature and therefore probably too late to go in 3.3. Please let me know if anything is inadequate. |
|
|
msg310874 - (view) |
Author: Cheryl Sabella (cheryl.sabella) *  |
Date: 2018-01-27 18:31 |
This one looks to be partly done due to #18720 and enums. >>> for item in socket.getaddrinfo(None, 0): ... print(item) ... (<AddressFamily.AF_INET6: 10>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('::1', 0, 0, 0)) (<AddressFamily.AF_INET6: 10>, <SocketKind.SOCK_DGRAM: 2>, 17, '', ('::1', 0, 0, 0)) (<AddressFamily.AF_INET6: 10>, <SocketKind.SOCK_RAW: 3>, 0, '', ('::1', 0, 0, 0)) (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('127.0.0.1', 0)) (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_DGRAM: 2>, 17, '', ('127.0.0.1', 0)) (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_RAW: 3>, 0, '', ('127.0.0.1', 0)) Is there a reason that Protocols weren't converted to be enums? I added quick code to socket.py and it turned the above into: (<AddressFamily.AF_INET6: 10>, <SocketKind.SOCK_STREAM: 1>, <Protocol.IPPROTO_TCP: 6>, '', ('::1', 0, 0, 0)) (<AddressFamily.AF_INET6: 10>, <SocketKind.SOCK_DGRAM: 2>, <Protocol.IPPROTO_UDP: 17>, '', ('::1', 0, 0, 0)) (<AddressFamily.AF_INET6: 10>, <SocketKind.SOCK_RAW: 3>, <Protocol.IPPROTO_HOPOPTS: 0>, '', ('::1', 0, 0, 0)) (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, <Protocol.IPPROTO_TCP: 6>, '', ('127.0.0.1', 0)) (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_DGRAM: 2>, <Protocol.IPPROTO_UDP: 17>, '', ('127.0.0.1', 0)) (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_RAW: 3>, <Protocol.IPPROTO_HOPOPTS: 0>, '', ('127.0.0.1', 0)) Would that be a responsible change to include? |
|
|