MCPcopy Index your code
hub / github.com/RustPython/RustPython / ip_address

Function ip_address

Lib/ipaddress.py:28–54  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

26
27
28def 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
57def ip_network(address, strict=True):

Callers

nothing calls this directly

Calls 2

IPv4AddressClass · 0.85
IPv6AddressClass · 0.85

Tested by

no test coverage detected