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