Convert an IP address from binary form into text representation.
(af, addr)
| 131 | |
| 132 | |
| 133 | def inet_ntop(af, addr): |
| 134 | # type: (socket.AddressFamily, bytes) -> str |
| 135 | """Convert an IP address from binary form into text representation.""" |
| 136 | # Use inet_ntop if available |
| 137 | addr = bytes_encode(addr) |
| 138 | try: |
| 139 | if not socket.has_ipv6: |
| 140 | raise AttributeError |
| 141 | return socket.inet_ntop(af, addr) |
| 142 | except AttributeError: |
| 143 | try: |
| 144 | return _INET_NTOP[af](addr) |
| 145 | except KeyError: |
| 146 | raise ValueError("unknown address family %d" % af) |
no test coverage detected