1from typing import (Any, Container, Generic, Iterable, Iterator, Optional, 2 overload, SupportsInt, Text, Tuple, TypeVar) 3 4# Undocumented length constants 5IPV4LENGTH: int 6IPV6LENGTH: int 7 8_A = TypeVar("_A", IPv4Address, IPv6Address) 9_N = TypeVar("_N", IPv4Network, IPv6Network) 10_T = TypeVar("_T") 11 12def ip_address(address: object) -> Any: ... # morally Union[IPv4Address, IPv6Address] 13def ip_network(address: object, strict: bool = ...) -> Any: ... # morally Union[IPv4Network, IPv6Network] 14def ip_interface(address: object) -> Any: ... # morally Union[IPv4Interface, IPv6Interface] 15 16class _IPAddressBase: 17 def __eq__(self, other: Any) -> bool: ... 18 def __ge__(self: _T, other: _T) -> bool: ... 19 def __gt__(self: _T, other: _T) -> bool: ... 20 def __le__(self: _T, other: _T) -> bool: ... 21 def __lt__(self: _T, other: _T) -> bool: ... 22 def __ne__(self, other: Any) -> bool: ... 23 @property 24 def compressed(self) -> Text: ... 25 @property 26 def exploded(self) -> Text: ... 27 @property 28 def reverse_pointer(self) -> Text: ... 29 @property 30 def version(self) -> int: ... 31 32class _BaseAddress(_IPAddressBase, SupportsInt): 33 def __init__(self, address: object) -> None: ... 34 def __add__(self: _T, other: int) -> _T: ... 35 def __hash__(self) -> int: ... 36 def __int__(self) -> int: ... 37 def __sub__(self: _T, other: int) -> _T: ... 38 @property 39 def is_global(self) -> bool: ... 40 @property 41 def is_link_local(self) -> bool: ... 42 @property 43 def is_loopback(self) -> bool: ... 44 @property 45 def is_multicast(self) -> bool: ... 46 @property 47 def is_private(self) -> bool: ... 48 @property 49 def is_reserved(self) -> bool: ... 50 @property 51 def is_unspecified(self) -> bool: ... 52 @property 53 def max_prefixlen(self) -> int: ... 54 @property 55 def packed(self) -> bytes: ... 56 57class _BaseNetwork(_IPAddressBase, Container[_A], Iterable[_A], Generic[_A]): 58 network_address: _A 59 netmask: _A 60 def __init__(self, address: object, strict: bool = ...) -> None: ... 61 def __contains__(self, other: Any) -> bool: ... 62 def __getitem__(self, n: int) -> _A: ... 63 def __iter__(self) -> Iterator[_A]: ... 64 def address_exclude(self: _T, other: _T) -> Iterator[_T]: ... 65 @property 66 def broadcast_address(self) -> _A: ... 67 def compare_networks(self: _T, other: _T) -> int: ... 68 def hosts(self) -> Iterator[_A]: ... 69 @property 70 def is_global(self) -> bool: ... 71 @property 72 def is_link_local(self) -> bool: ... 73 @property 74 def is_loopback(self) -> bool: ... 75 @property 76 def is_multicast(self) -> bool: ... 77 @property 78 def is_private(self) -> bool: ... 79 @property 80 def is_reserved(self) -> bool: ... 81 @property 82 def is_unspecified(self) -> bool: ... 83 @property 84 def max_prefixlen(self) -> int: ... 85 @property 86 def num_addresses(self) -> int: ... 87 def overlaps(self: _T, other: _T) -> bool: ... 88 @property 89 def prefixlen(self) -> int: ... 90 def subnets(self: _T, prefixlen_diff: int = ..., new_prefix: Optional[int] = ...) -> Iterator[_T]: ... 91 def supernet(self: _T, prefixlen_diff: int = ..., new_prefix: Optional[int] = ...) -> _T: ... 92 @property 93 def with_hostmask(self) -> Text: ... 94 @property 95 def with_netmask(self) -> Text: ... 96 @property 97 def with_prefixlen(self) -> Text: ... 98 @property 99 def hostmask(self) -> _A: ... 100 101class _BaseInterface(_BaseAddress, Generic[_A, _N]): 102 hostmask: _A 103 netmask: _A 104 network: _N 105 @property 106 def ip(self) -> _A: ... 107 @property 108 def with_hostmask(self) -> Text: ... 109 @property 110 def with_netmask(self) -> Text: ... 111 @property 112 def with_prefixlen(self) -> Text: ... 113 114class IPv4Address(_BaseAddress): ... 115class IPv4Network(_BaseNetwork[IPv4Address]): ... 116class IPv4Interface(IPv4Address, _BaseInterface[IPv4Address, IPv4Network]): ... 117 118class IPv6Address(_BaseAddress): 119 @property 120 def ipv4_mapped(self) -> Optional[IPv4Address]: ... 121 @property 122 def is_site_local(self) -> bool: ... 123 @property 124 def sixtofour(self) -> Optional[IPv4Address]: ... 125 @property 126 def teredo(self) -> Optional[Tuple[IPv4Address, IPv4Address]]: ... 127 128class IPv6Network(_BaseNetwork[IPv6Address]): 129 @property 130 def is_site_local(self) -> bool: ... 131 132class IPv6Interface(IPv6Address, _BaseInterface[IPv6Address, IPv6Network]): ... 133 134def v4_int_to_packed(address: int) -> bytes: ... 135def v6_int_to_packed(address: int) -> bytes: ... 136@overload 137def summarize_address_range(first: IPv4Address, last: IPv4Address) -> Iterator[IPv4Network]: ... 138@overload 139def summarize_address_range(first: IPv6Address, last: IPv6Address) -> Iterator[IPv6Network]: ... 140def collapse_addresses(addresses: Iterable[_N]) -> Iterator[_N]: ... 141@overload 142def get_mixed_type_key(obj: _A) -> Tuple[int, _A]: ... 143@overload 144def get_mixed_type_key(obj: IPv4Network) -> Tuple[int, IPv4Address, IPv4Address]: ... 145@overload 146def get_mixed_type_key(obj: IPv6Network) -> Tuple[int, IPv6Address, IPv6Address]: ... 147 148class AddressValueError(ValueError): ... 149class NetmaskValueError(ValueError): ... 150