Take an IP string/int and return an object of the correct type. Args: address: A string or integer, the IP address. Either IPv4 or IPv6 addresses may be supplied; integers less than 2**32 will be considered to be IPv4 by default. Returns: An IPv4Address
(address)
| 26 | |
| 27 | |
| 28 | def ip_address(address): |
| 29 | """Take an IP string/int and return an object of the correct type. |
| 30 | |
| 31 | Args: |
| 32 | address: A string or integer, the IP address. Either IPv4 or |
| 33 | IPv6 addresses may be supplied; integers less than 2**32 will |
| 34 | be considered to be IPv4 by default. |
| 35 | |
| 36 | Returns: |
| 37 | An IPv4Address or IPv6Address object. |
| 38 | |
| 39 | Raises: |
| 40 | ValueError: if the *address* passed isn't either a v4 or a v6 |
| 41 | address |
| 42 | |
| 43 | """ |
| 44 | try: |
| 45 | return IPv4Address(address) |
| 46 | except (AddressValueError, NetmaskValueError): |
| 47 | pass |
| 48 | |
| 49 | try: |
| 50 | return IPv6Address(address) |
| 51 | except (AddressValueError, NetmaskValueError): |
| 52 | pass |
| 53 | |
| 54 | raise ValueError(f'{address!r} does not appear to be an IPv4 or IPv6 address') |
| 55 | |
| 56 | |
| 57 | def ip_network(address, strict=True): |
nothing calls this directly
no test coverage detected