Format: application/octet-stream
⬇ Download File (5.1 KB)
   1  import sys
   2  from typing import Any, Container, Generic, Iterable, Iterator, Optional, SupportsInt, Tuple, TypeVar, overload
   3  
   4  # Undocumented length constants
   5  IPV4LENGTH: int
   6  IPV6LENGTH: int
   7  
   8  _A = TypeVar("_A", IPv4Address, IPv6Address)
   9  _N = TypeVar("_N", IPv4Network, IPv6Network)
  10  _T = TypeVar("_T")
  11  
  12  def ip_address(address: object) -> Any: ...  # morally Union[IPv4Address, IPv6Address]
  13  def ip_network(address: object, strict: bool = ...) -> Any: ...  # morally Union[IPv4Network, IPv6Network]
  14  def ip_interface(address: object) -> Any: ...  # morally Union[IPv4Interface, IPv6Interface]
  15  
  16  class _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) -> str: ...
  25      @property
  26      def exploded(self) -> str: ...
  27      @property
  28      def reverse_pointer(self) -> str: ...
  29      @property
  30      def version(self) -> int: ...
  31  
  32  class _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  
  57  class _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, other: _BaseNetwork[_A]) -> bool: ...
  88      @property
  89      def prefixlen(self) -> int: ...
  90      if sys.version_info >= (3, 7):
  91          def subnet_of(self: _T, other: _T) -> bool: ...
  92          def supernet_of(self: _T, other: _T) -> bool: ...
  93      def subnets(self: _T, prefixlen_diff: int = ..., new_prefix: Optional[int] = ...) -> Iterator[_T]: ...
  94      def supernet(self: _T, prefixlen_diff: int = ..., new_prefix: Optional[int] = ...) -> _T: ...
  95      @property
  96      def with_hostmask(self) -> str: ...
  97      @property
  98      def with_netmask(self) -> str: ...
  99      @property
 100      def with_prefixlen(self) -> str: ...
 101      @property
 102      def hostmask(self) -> _A: ...
 103  
 104  class _BaseInterface(_BaseAddress, Generic[_A, _N]):
 105      hostmask: _A
 106      netmask: _A
 107      network: _N
 108      @property
 109      def ip(self) -> _A: ...
 110      @property
 111      def with_hostmask(self) -> str: ...
 112      @property
 113      def with_netmask(self) -> str: ...
 114      @property
 115      def with_prefixlen(self) -> str: ...
 116  
 117  class IPv4Address(_BaseAddress): ...
 118  class IPv4Network(_BaseNetwork[IPv4Address]): ...
 119  class IPv4Interface(IPv4Address, _BaseInterface[IPv4Address, IPv4Network]): ...
 120  
 121  class IPv6Address(_BaseAddress):
 122      @property
 123      def ipv4_mapped(self) -> Optional[IPv4Address]: ...
 124      @property
 125      def is_site_local(self) -> bool: ...
 126      @property
 127      def sixtofour(self) -> Optional[IPv4Address]: ...
 128      @property
 129      def teredo(self) -> Optional[Tuple[IPv4Address, IPv4Address]]: ...
 130  
 131  class IPv6Network(_BaseNetwork[IPv6Address]):
 132      @property
 133      def is_site_local(self) -> bool: ...
 134  
 135  class IPv6Interface(IPv6Address, _BaseInterface[IPv6Address, IPv6Network]): ...
 136  
 137  def v4_int_to_packed(address: int) -> bytes: ...
 138  def v6_int_to_packed(address: int) -> bytes: ...
 139  @overload
 140  def summarize_address_range(first: IPv4Address, last: IPv4Address) -> Iterator[IPv4Network]: ...
 141  @overload
 142  def summarize_address_range(first: IPv6Address, last: IPv6Address) -> Iterator[IPv6Network]: ...
 143  def collapse_addresses(addresses: Iterable[_N]) -> Iterator[_N]: ...
 144  @overload
 145  def get_mixed_type_key(obj: _A) -> Tuple[int, _A]: ...
 146  @overload
 147  def get_mixed_type_key(obj: IPv4Network) -> Tuple[int, IPv4Address, IPv4Address]: ...
 148  @overload
 149  def get_mixed_type_key(obj: IPv6Network) -> Tuple[int, IPv6Address, IPv6Address]: ...
 150  
 151  class AddressValueError(ValueError): ...
 152  class NetmaskValueError(ValueError): ...
 153