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

Class IPv6Address

Lib/ipaddress.py:1910–2199  ·  view source on GitHub ↗

Represent and manipulate single IPv6 Addresses.

Source from the content-addressed store, hash-verified

1908 return addr, scope_id
1909
1910class IPv6Address(_BaseV6, _BaseAddress):
1911
1912 """Represent and manipulate single IPv6 Addresses."""
1913
1914 __slots__ = ('_ip', '_scope_id', '__weakref__')
1915
1916 def __init__(self, address):
1917 """Instantiate a new IPv6 address object.
1918
1919 Args:
1920 address: A string or integer representing the IP
1921
1922 Additionally, an integer can be passed, so
1923 IPv6Address('2001:db8::') ==
1924 IPv6Address(42540766411282592856903984951653826560)
1925 or, more generally
1926 IPv6Address(int(IPv6Address('2001:db8::'))) ==
1927 IPv6Address('2001:db8::')
1928
1929 Raises:
1930 AddressValueError: If address isn't a valid IPv6 address.
1931
1932 """
1933 # Efficient constructor from integer.
1934 if isinstance(address, int):
1935 self._check_int_address(address)
1936 self._ip = address
1937 self._scope_id = None
1938 return
1939
1940 # Constructing from a packed address
1941 if isinstance(address, bytes):
1942 self._check_packed_address(address, 16)
1943 self._ip = int.from_bytes(address, 'big')
1944 self._scope_id = None
1945 return
1946
1947 # Assume input argument to be string or any object representation
1948 # which converts into a formatted IP string.
1949 addr_str = str(address)
1950 if '/' in addr_str:
1951 raise AddressValueError(f"Unexpected '/' in {address!r}")
1952 addr_str, self._scope_id = self._split_scope_id(addr_str)
1953
1954 self._ip = self._ip_int_from_string(addr_str)
1955
1956 def _explode_shorthand_ip_string(self):
1957 ipv4_mapped = self.ipv4_mapped
1958 if ipv4_mapped is None:
1959 return super()._explode_shorthand_ip_string()
1960 prefix_len = 30
1961 raw_exploded_str = super()._explode_shorthand_ip_string()
1962 return f"{raw_exploded_str[:prefix_len]}{ipv4_mapped!s}"
1963
1964 def _reverse_pointer(self):
1965 ipv4_mapped = self.ipv4_mapped
1966 if ipv4_mapped is None:
1967 return super()._reverse_pointer()

Callers 5

ip_addressFunction · 0.85
ipv6_mappedMethod · 0.85
_make_netmaskMethod · 0.85
ipMethod · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected