Instantiate a new IPv6 address object. Args: address: A string or integer representing the IP Additionally, an integer can be passed, so IPv6Address('2001:db8::') == IPv6Address(42540766411282592856903984951653826560) or
(self, address)
| 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 |
nothing calls this directly
no test coverage detected