Convert an IP address from text representation into binary form.
(af, addr)
| 81 | |
| 82 | |
| 83 | def inet_pton(af, addr): |
| 84 | # type: (socket.AddressFamily, Union[bytes, str]) -> bytes |
| 85 | """Convert an IP address from text representation into binary form.""" |
| 86 | # Will replace Net/Net6 objects |
| 87 | addr = plain_str(addr) |
| 88 | # Use inet_pton if available |
| 89 | try: |
| 90 | if not socket.has_ipv6: |
| 91 | raise AttributeError |
| 92 | return socket.inet_pton(af, addr) |
| 93 | except AttributeError: |
| 94 | try: |
| 95 | return _INET_PTON[af](addr) |
| 96 | except KeyError: |
| 97 | raise socket.error("Address family not supported by protocol") |
| 98 | |
| 99 | |
| 100 | def _inet6_ntop(addr): |
no test coverage detected