diff --git a/stubs/netaddr/@tests/stubtest_allowlist.txt b/stubs/netaddr/@tests/stubtest_allowlist.txt new file mode 100644 index 000000000..6165bfd26 --- /dev/null +++ b/stubs/netaddr/@tests/stubtest_allowlist.txt @@ -0,0 +1,16 @@ +# Error: is not present in stub +# ============================= +netaddr.core.a # This is a temporary module attribute used to detect python version + +# These are unnecessary re-exports +netaddr.ip.INET_PTON +netaddr.ip.N +netaddr.ip.NOHOST +netaddr.ip.P +netaddr.ip.Z +netaddr.ip.ZEROFILL + + +# Error: is not present at runtime +# ================================ +netaddr.ip.iana.XMLRecordParser.__getattr__ # __init__ has `self.__dict__.update(kwargs)` diff --git a/stubs/netaddr/METADATA.toml b/stubs/netaddr/METADATA.toml new file mode 100644 index 000000000..54042496d --- /dev/null +++ b/stubs/netaddr/METADATA.toml @@ -0,0 +1,4 @@ +version = "0.8.*" + +[tool.stubtest] +ignore_missing_stub = false diff --git a/stubs/netaddr/netaddr/__init__.pyi b/stubs/netaddr/netaddr/__init__.pyi new file mode 100644 index 000000000..194e6052f --- /dev/null +++ b/stubs/netaddr/netaddr/__init__.pyi @@ -0,0 +1,75 @@ +from netaddr.contrib.subnet_splitter import SubnetSplitter as SubnetSplitter +from netaddr.core import ( + INET_PTON as INET_PTON, + NOHOST as NOHOST, + ZEROFILL as ZEROFILL, + AddrConversionError as AddrConversionError, + AddrFormatError as AddrFormatError, + N as N, + NotRegisteredError as NotRegisteredError, + P as P, + Z as Z, +) +from netaddr.eui import EUI as EUI, IAB as IAB, OUI as OUI +from netaddr.ip import ( + IPAddress as IPAddress, + IPNetwork as IPNetwork, + IPRange as IPRange, + all_matching_cidrs as all_matching_cidrs, + cidr_abbrev_to_verbose as cidr_abbrev_to_verbose, + cidr_exclude as cidr_exclude, + cidr_merge as cidr_merge, + iprange_to_cidrs as iprange_to_cidrs, + iter_iprange as iter_iprange, + iter_unique_ips as iter_unique_ips, + largest_matching_cidr as largest_matching_cidr, + smallest_matching_cidr as smallest_matching_cidr, + spanning_cidr as spanning_cidr, +) +from netaddr.ip.glob import ( + IPGlob as IPGlob, + cidr_to_glob as cidr_to_glob, + glob_to_cidrs as glob_to_cidrs, + glob_to_iprange as glob_to_iprange, + glob_to_iptuple as glob_to_iptuple, + iprange_to_globs as iprange_to_globs, + valid_glob as valid_glob, +) +from netaddr.ip.nmap import iter_nmap_range as iter_nmap_range, valid_nmap_range as valid_nmap_range +from netaddr.ip.rfc1924 import base85_to_ipv6 as base85_to_ipv6, ipv6_to_base85 as ipv6_to_base85 +from netaddr.ip.sets import IPSet as IPSet +from netaddr.strategy.eui48 import ( + mac_bare as mac_bare, + mac_cisco as mac_cisco, + mac_eui48 as mac_eui48, + mac_pgsql as mac_pgsql, + mac_unix as mac_unix, + mac_unix_expanded as mac_unix_expanded, + valid_str as __eui48_valid_str, +) +from netaddr.strategy.eui64 import ( + eui64_bare as eui64_bare, + eui64_base as eui64_base, + eui64_cisco as eui64_cisco, + eui64_unix as eui64_unix, + eui64_unix_expanded as eui64_unix_expanded, + valid_str as __eui64_valid_str, +) +from netaddr.strategy.ipv4 import valid_str as __ipv4_valid_str +from netaddr.strategy.ipv6 import ( + ipv6_compact as ipv6_compact, + ipv6_full as ipv6_full, + ipv6_verbose as ipv6_verbose, + valid_str as __ipv6_valid_str, +) + +# These are reexported with different names +valid_ipv4 = __ipv4_valid_str +valid_ipv6 = __ipv6_valid_str +valid_mac = __eui48_valid_str +valid_eui64 = __eui64_valid_str + +# Module constants +__version__: str +VERSION: tuple[int, ...] +STATUS: str diff --git a/stubs/netaddr/netaddr/cli.pyi b/stubs/netaddr/netaddr/cli.pyi new file mode 100644 index 000000000..3c7c5b202 --- /dev/null +++ b/stubs/netaddr/netaddr/cli.pyi @@ -0,0 +1,3 @@ +from netaddr import * + +def main() -> None: ... diff --git a/stubs/netaddr/netaddr/compat.pyi b/stubs/netaddr/netaddr/compat.pyi new file mode 100644 index 000000000..fd6128831 --- /dev/null +++ b/stubs/netaddr/netaddr/compat.pyi @@ -0,0 +1,2 @@ +# Python 2 compatibility module +# All members are prefixed with "_", nothing to declare. diff --git a/stubs/netaddr/netaddr/contrib/__init__.pyi b/stubs/netaddr/netaddr/contrib/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/stubs/netaddr/netaddr/contrib/subnet_splitter.pyi b/stubs/netaddr/netaddr/contrib/subnet_splitter.pyi new file mode 100644 index 000000000..2e4200065 --- /dev/null +++ b/stubs/netaddr/netaddr/contrib/subnet_splitter.pyi @@ -0,0 +1,7 @@ +from netaddr.ip import IPNetwork, _IPAddressAddr + +class SubnetSplitter: + def __init__(self, base_cidr: _IPAddressAddr) -> None: ... + def extract_subnet(self, prefix: int, count: int | None = ...) -> list[IPNetwork]: ... + def available_subnets(self) -> list[IPNetwork]: ... + def remove_subnet(self, ip_network: IPNetwork) -> None: ... diff --git a/stubs/netaddr/netaddr/core.pyi b/stubs/netaddr/netaddr/core.pyi new file mode 100644 index 000000000..da4d657f3 --- /dev/null +++ b/stubs/netaddr/netaddr/core.pyi @@ -0,0 +1,38 @@ +from _typeshed import Incomplete, SupportsWrite +from collections.abc import Iterator, Mapping +from typing_extensions import Final + +BIG_ENDIAN_PLATFORM: bool +P: Final = 1 +INET_PTON: Final = 1 +Z: Final = 2 +ZEROFILL: Final = 2 +N: Final = 4 +NOHOST: Final = 4 + +class AddrFormatError(Exception): ... +class AddrConversionError(Exception): ... +class NotRegisteredError(Exception): ... + +def num_bits(int_val: int) -> int: ... + +class Subscriber: + def update(self, data: Incomplete) -> None: ... + +class PrettyPrinter(Subscriber): + fh: SupportsWrite[str] + write_eol: bool + def __init__(self, fh: SupportsWrite[str] = ..., write_eol: bool = ...) -> None: ... + def update(self, data: object) -> None: ... + +class Publisher: + subscribers: list[Subscriber] + def __init__(self) -> None: ... + def attach(self, subscriber: Subscriber) -> None: ... + def detach(self, subscriber: Subscriber) -> None: ... + def notify(self, data: object) -> None: ... + +class DictDotLookup: + def __init__(self, d: Mapping[str, object]) -> None: ... + def __getitem__(self, name: str) -> object: ... + def __iter__(self) -> Iterator[str]: ... diff --git a/stubs/netaddr/netaddr/eui/__init__.pyi b/stubs/netaddr/netaddr/eui/__init__.pyi new file mode 100644 index 000000000..35340d741 --- /dev/null +++ b/stubs/netaddr/netaddr/eui/__init__.pyi @@ -0,0 +1,85 @@ +from _typeshed import Self +from typing import ClassVar, SupportsInt, overload +from typing_extensions import Literal, SupportsIndex + +from netaddr.core import DictDotLookup +from netaddr.ip import IPAddress +from netaddr.strategy.eui48 import mac_eui48 +from netaddr.strategy.eui64 import eui64_base + +class BaseIdentifier: + def __init__(self) -> None: ... + def __int__(self) -> int: ... + def __long__(self) -> int: ... + def __oct__(self) -> str: ... + def __hex__(self) -> str: ... + def __index__(self) -> int: ... + +class OUI(BaseIdentifier): + records: list[dict[str, object]] + def __init__(self, oui: str | int) -> None: ... + def __eq__(self, other: object) -> bool: ... + def __ne__(self, other: object) -> bool: ... + @property + def reg_count(self) -> int: ... + def registration(self, index: int = ...) -> DictDotLookup: ... + +class IAB(BaseIdentifier): + IAB_EUI_VALUES: ClassVar[tuple[int, int]] + @classmethod + def split_iab_mac(cls, eui_int: int, strict: bool = ...) -> tuple[int, int]: ... + record: dict[str, object] + def __init__(self, iab: str | int, strict: bool = ...) -> None: ... + def __eq__(self, other: object) -> bool: ... + def __ne__(self, other: object) -> bool: ... + def registration(self) -> DictDotLookup: ... + +class EUI(BaseIdentifier): + def __init__( + self, addr: EUI | int | str, version: int | None = ..., dialect: type[mac_eui48] | type[eui64_base] | None = ... + ) -> None: ... + @property + def value(self) -> int: ... + @value.setter + def value(self, value: str | SupportsInt | SupportsIndex) -> None: ... + @property + def dialect(self) -> type[mac_eui48] | type[eui64_base]: ... + @dialect.setter + def dialect(self, value: type[mac_eui48] | type[eui64_base] | None) -> None: ... + @property + def oui(self) -> OUI: ... + @property + def ei(self) -> str: ... + def is_iab(self) -> bool: ... + @property + def iab(self) -> IAB | None: ... + @property + def version(self) -> Literal[48, 64]: ... + @overload + def __getitem__(self, idx: int) -> int: ... + @overload + def __getitem__(self, idx: slice) -> list[int]: ... + @overload + def __getitem__(self, idx: int | slice) -> int | list[int]: ... + def __setitem__(self, idx: int, value: int) -> None: ... + def __hash__(self) -> int: ... + def __eq__(self, other: object) -> bool: ... + def __ne__(self, other: object) -> bool: ... + def __lt__(self, other: EUI | int | str) -> bool: ... + def __le__(self, other: EUI | int | str) -> bool: ... + def __gt__(self, other: EUI | int | str) -> bool: ... + def __ge__(self, other: EUI | int | str) -> bool: ... + def bits(self, word_sep: str | None = ...) -> str: ... + @property + def packed(self) -> bytes: ... + @property + def words(self) -> tuple[int, ...]: ... + @property + def bin(self) -> str: ... + def eui64(self: Self) -> Self: ... + def modified_eui64(self: Self) -> Self: ... + def ipv6(self, prefix: str | SupportsInt | SupportsIndex) -> IPAddress: ... + def ipv6_link_local(self) -> IPAddress: ... + @property + def info(self) -> DictDotLookup: ... + def format(self, dialect: type[mac_eui48] | type[eui64_base] | None = ...) -> str: ... diff --git a/stubs/netaddr/netaddr/eui/ieee.pyi b/stubs/netaddr/netaddr/eui/ieee.pyi new file mode 100644 index 000000000..53fe97038 --- /dev/null +++ b/stubs/netaddr/netaddr/eui/ieee.pyi @@ -0,0 +1,33 @@ +import _csv +from _typeshed import StrOrBytesPath +from collections.abc import Iterable +from typing import Any, BinaryIO, TextIO +from typing_extensions import TypeAlias + +from netaddr.core import Publisher, Subscriber + +_INDEX: TypeAlias = dict[int, list[tuple[int, int]]] +OUI_INDEX: _INDEX +IAB_INDEX: _INDEX + +class FileIndexer(Subscriber): + writer: _csv._writer + def __init__(self, index_file: TextIO | StrOrBytesPath | int) -> None: ... + def update(self, data: Iterable[Any]) -> None: ... + +class OUIIndexParser(Publisher): + fh: BinaryIO + def __init__(self, ieee_file: BinaryIO | StrOrBytesPath | int) -> None: ... + def parse(self) -> None: ... + +class IABIndexParser(Publisher): + fh: BinaryIO + def __init__(self, ieee_file: BinaryIO | StrOrBytesPath | int) -> None: ... + def parse(self) -> None: ... + +def create_index_from_registry( + registry_fh: BinaryIO | StrOrBytesPath | int, index_path: StrOrBytesPath, parser: type[OUIIndexParser] | type[IABIndexParser] +) -> None: ... +def create_indices() -> None: ... +def load_index(index: _INDEX, fp: Iterable[bytes]) -> None: ... +def load_indices() -> None: ... diff --git a/stubs/netaddr/netaddr/fbsocket.pyi b/stubs/netaddr/netaddr/fbsocket.pyi new file mode 100644 index 000000000..e924e7575 --- /dev/null +++ b/stubs/netaddr/netaddr/fbsocket.pyi @@ -0,0 +1,8 @@ +from typing_extensions import Literal + +AF_INET: Literal[2] +AF_INET6: Literal[10] + +def inet_ntoa(packed_ip: bytes) -> str: ... +def inet_ntop(af: int, packed_ip: bytes) -> str: ... +def inet_pton(af: int, ip_string: str) -> str: ... diff --git a/stubs/netaddr/netaddr/ip/__init__.pyi b/stubs/netaddr/netaddr/ip/__init__.pyi new file mode 100644 index 000000000..7125323f1 --- /dev/null +++ b/stubs/netaddr/netaddr/ip/__init__.pyi @@ -0,0 +1,174 @@ +from _typeshed import Incomplete, Self +from abc import abstractmethod +from collections.abc import Iterable, Iterator +from typing import SupportsInt, Union, overload +from typing_extensions import Literal, SupportsIndex, TypeAlias + +from netaddr.core import DictDotLookup +from netaddr.strategy.ipv6 import ipv6_verbose + +class BaseIP: + def __init__(self) -> None: ... + @property + def value(self) -> int | None: ... + @value.setter + def value(self, value: int) -> None: ... + @abstractmethod + def key(self) -> tuple[int, ...]: ... + @abstractmethod + def sort_key(self) -> tuple[int, ...]: ... + def __hash__(self) -> int: ... + def __eq__(self, other: object) -> bool: ... + def __ne__(self, other: object) -> bool: ... + def __lt__(self, other: BaseIP) -> bool: ... + def __le__(self, other: BaseIP) -> bool: ... + def __gt__(self, other: BaseIP) -> bool: ... + def __ge__(self, other: BaseIP) -> bool: ... + def is_unicast(self) -> bool: ... + def is_multicast(self) -> bool: ... + def is_loopback(self) -> bool: ... + def is_private(self) -> bool: ... + def is_link_local(self) -> bool: ... + def is_reserved(self) -> bool: ... + def is_ipv4_mapped(self) -> bool: ... + def is_ipv4_compat(self) -> bool: ... + @property + def info(self) -> DictDotLookup: ... + @property + def version(self) -> Literal[4, 6]: ... + +_IPAddressAddr: TypeAlias = BaseIP | int | str +_IPNetworkAddr: TypeAlias = Union[IPNetwork, IPAddress, tuple[int, int], str] + +class IPAddress(BaseIP): + def __init__(self, addr: _IPAddressAddr, version: Literal[4, 6] | None = ..., flags: int = ...) -> None: ... + def netmask_bits(self) -> int: ... + def is_hostmask(self) -> bool: ... + def is_netmask(self) -> bool: ... + def __iadd__(self: Self, num: int) -> Self: ... + def __isub__(self: Self, num: int) -> Self: ... + def __add__(self: Self, num: int) -> Self: ... + __radd__ = __add__ + def __sub__(self: Self, num: int) -> Self: ... + def __rsub__(self: Self, num: int) -> Self: ... + def key(self) -> tuple[int, ...]: ... + def sort_key(self) -> tuple[int, ...]: ... + def __int__(self) -> int: ... + def __long__(self) -> int: ... + def __oct__(self) -> str: ... + def __hex__(self) -> str: ... + def __index__(self) -> int: ... + def __bytes__(self) -> bytes: ... + def bits(self, word_sep: str | None = ...) -> str: ... + @property + def packed(self) -> bytes: ... + @property + def words(self) -> tuple[int, ...]: ... + @property + def bin(self) -> str: ... + @property + def reverse_dns(self) -> str: ... + def ipv4(self: Self) -> Self: ... + def ipv6(self: Self, ipv4_compatible: bool = ...) -> Self: ... + def format(self, dialect: type[ipv6_verbose] | None = ...) -> str: ... + def __or__(self: Self, other: str | SupportsInt | SupportsIndex) -> Self: ... + def __and__(self: Self, other: str | SupportsInt | SupportsIndex) -> Self: ... + def __xor__(self: Self, other: str | SupportsInt | SupportsIndex) -> Self: ... + def __lshift__(self: Self, numbits: int) -> Self: ... + def __rshift__(self: Self, numbits: int) -> Self: ... + def __bool__(self) -> bool: ... + +class IPListMixin: + def __iter__(self) -> Iterator[IPAddress]: ... + @property + def size(self) -> int: ... + def __len__(self) -> int: ... + @overload + def __getitem__(self, index: SupportsIndex) -> IPAddress: ... + @overload + def __getitem__(self, index: slice) -> Iterator[IPAddress]: ... + @overload + def __getitem__(self, index: SupportsIndex | slice) -> IPAddress | Iterator[IPAddress]: ... + def __contains__(self, other: BaseIP | _IPAddressAddr) -> bool: ... + def __bool__(self) -> Literal[True]: ... + +def parse_ip_network( + module: Incomplete, addr: tuple[int, int] | str, implicit_prefix: bool = ..., flags: int = ... +) -> tuple[int, int]: ... + +class IPNetwork(BaseIP, IPListMixin): + def __init__( + self, addr: _IPNetworkAddr, implicit_prefix: bool = ..., version: Literal[4, 6] | None = ..., flags: int = ... + ) -> None: ... + @property + def prefixlen(self) -> int: ... + @prefixlen.setter + def prefixlen(self, value: int) -> None: ... + @property + def ip(self) -> IPAddress: ... + @property + def network(self) -> IPAddress: ... + @property + def broadcast(self) -> IPAddress | None: ... + @property + def first(self) -> int: ... + @property + def last(self) -> int: ... + @property + def netmask(self) -> IPAddress: ... + @netmask.setter + def netmask(self, value: _IPAddressAddr) -> None: ... + @property + def hostmask(self) -> IPAddress: ... + @property + def cidr(self) -> IPNetwork: ... + def __iadd__(self: Self, num: int) -> Self: ... + def __isub__(self: Self, num: int) -> Self: ... + # runtime overrides __contains__ with incompatible type for "other" + def __contains__(self, other: BaseIP | _IPNetworkAddr) -> bool: ... # type: ignore[override] + def key(self) -> tuple[int, ...]: ... + def sort_key(self) -> tuple[int, ...]: ... + def ipv4(self: Self) -> Self: ... + def ipv6(self: Self, ipv4_compatible: bool = ...) -> Self: ... + def previous(self: Self, step: int = ...) -> Self: ... + def next(self: Self, step: int = ...) -> Self: ... + def supernet(self, prefixlen: int = ...) -> list[IPNetwork]: ... + def subnet(self: Self, prefixlen: int, count: int | None = ..., fmt: object | None = ...) -> Iterator[Self]: ... + def iter_hosts(self) -> Iterator[IPAddress]: ... + +class IPRange(BaseIP, IPListMixin): + def __init__(self, start: _IPAddressAddr, end: _IPAddressAddr, flags: int = ...) -> None: ... + def __contains__(self, other: BaseIP | _IPAddressAddr) -> bool: ... + @property + def first(self) -> int: ... + @property + def last(self) -> int: ... + def key(self) -> tuple[int, ...]: ... + def sort_key(self) -> tuple[int, ...]: ... + def cidrs(self) -> list[IPNetwork]: ... + +def iter_unique_ips(*args: IPRange | _IPNetworkAddr) -> Iterator[IPAddress]: ... +def cidr_abbrev_to_verbose(abbrev_cidr: str | SupportsInt | SupportsIndex) -> str: ... +def cidr_merge(ip_addrs: Iterable[IPRange | _IPNetworkAddr]) -> list[IPNetwork]: ... +def cidr_exclude(target: _IPNetworkAddr, exclude: _IPNetworkAddr) -> list[IPNetwork]: ... +def cidr_partition( + target: _IPNetworkAddr, exclude: _IPNetworkAddr +) -> tuple[list[IPNetwork], list[IPNetwork], list[IPNetwork]]: ... +def spanning_cidr(ip_addrs: Iterable[_IPNetworkAddr]) -> IPNetwork: ... +def iter_iprange(start: _IPAddressAddr, end: _IPAddressAddr, step: SupportsInt | SupportsIndex = ...) -> Iterator[IPAddress]: ... +def iprange_to_cidrs(start: _IPNetworkAddr, end: _IPNetworkAddr) -> list[IPNetwork]: ... +def smallest_matching_cidr(ip: _IPAddressAddr, cidrs: Iterable[_IPNetworkAddr]) -> IPNetwork | None: ... +def largest_matching_cidr(ip: _IPAddressAddr, cidrs: Iterable[_IPNetworkAddr]) -> IPNetwork | None: ... +def all_matching_cidrs(ip: _IPAddressAddr, cidrs: Iterable[_IPNetworkAddr]) -> list[IPNetwork]: ... + +IPV4_LOOPBACK: IPNetwork +IPV4_PRIVATE: tuple[IPNetwork | IPRange, ...] +IPV4_LINK_LOCAL: IPNetwork +IPV4_MULTICAST: IPNetwork +IPV4_6TO4: IPNetwork +IPV4_RESERVED: tuple[IPNetwork | IPRange, ...] +IPV6_LOOPBACK: IPAddress +IPV6_PRIVATE: tuple[IPNetwork, ...] +IPV6_LINK_LOCAL: IPNetwork +IPV6_MULTICAST: IPNetwork +IPV6_RESERVED: tuple[IPNetwork, ...] diff --git a/stubs/netaddr/netaddr/ip/glob.pyi b/stubs/netaddr/netaddr/ip/glob.pyi new file mode 100644 index 000000000..34660723c --- /dev/null +++ b/stubs/netaddr/netaddr/ip/glob.pyi @@ -0,0 +1,17 @@ +from typing_extensions import TypeGuard + +from netaddr.ip import IPAddress, IPNetwork, IPRange, _IPAddressAddr, _IPNetworkAddr + +def valid_glob(ipglob: object) -> TypeGuard[str]: ... +def glob_to_iptuple(ipglob: str) -> tuple[IPAddress, IPAddress]: ... +def glob_to_iprange(ipglob: str) -> IPRange: ... +def iprange_to_globs(start: _IPAddressAddr, end: _IPAddressAddr) -> list[str]: ... +def glob_to_cidrs(ipglob: str) -> list[IPNetwork]: ... +def cidr_to_glob(cidr: _IPNetworkAddr) -> str: ... + +class IPGlob(IPRange): + def __init__(self, ipglob: str) -> None: ... + @property + def glob(self) -> str: ... + @glob.setter + def glob(self, value: str) -> None: ... diff --git a/stubs/netaddr/netaddr/ip/iana.pyi b/stubs/netaddr/netaddr/ip/iana.pyi new file mode 100644 index 000000000..ef3657aa9 --- /dev/null +++ b/stubs/netaddr/netaddr/ip/iana.pyi @@ -0,0 +1,52 @@ +from _typeshed import Incomplete, SupportsWrite +from collections.abc import Callable, Mapping, MutableMapping +from typing import Any +from typing_extensions import TypeAlias +from xml.sax import handler +from xml.sax.xmlreader import XMLReader + +from netaddr.core import Publisher, Subscriber +from netaddr.ip import IPAddress, IPNetwork, IPRange + +_IanaInfoKey: TypeAlias = IPAddress | IPNetwork | IPRange + +IANA_INFO: dict[str, dict[_IanaInfoKey, dict[str, str]]] + +class SaxRecordParser(handler.ContentHandler): + def __init__(self, callback: Callable[[Mapping[str, object] | None], object] | None = ...) -> None: ... + def startElement(self, name: str, attrs: Mapping[str, object]) -> None: ... + def endElement(self, name: str) -> None: ... + def characters(self, content: str) -> None: ... + +class XMLRecordParser(Publisher): + xmlparser: XMLReader + fh: Incomplete + def __init__(self, fh: Incomplete, **kwargs: object) -> None: ... + def process_record(self, rec: Mapping[str, object]) -> dict[str, str] | None: ... + def consume_record(self, rec: object) -> None: ... + def parse(self) -> None: ... + # Arbitrary attributes are set in __init__ with `self.__dict__.update(kwargs)` + def __getattr__(self, __name: str) -> Any: ... + +class IPv4Parser(XMLRecordParser): + def process_record(self, rec: Mapping[str, object]) -> dict[str, str]: ... + +class IPv6Parser(XMLRecordParser): + def process_record(self, rec: Mapping[str, object]) -> dict[str, str]: ... + +class IPv6UnicastParser(XMLRecordParser): + def process_record(self, rec: Mapping[str, object]) -> dict[str, str]: ... + +class MulticastParser(XMLRecordParser): + def normalise_addr(self, addr: str) -> str: ... + +class DictUpdater(Subscriber): + dct: MutableMapping[_IanaInfoKey, Incomplete] + topic: str + unique_key: str + def __init__(self, dct: MutableMapping[_IanaInfoKey, Incomplete], topic: str, unique_key: str) -> None: ... + def update(self, data: Incomplete) -> None: ... + +def load_info() -> None: ... +def pprint_info(fh: SupportsWrite[str] | None = ...) -> None: ... +def query(ip_addr: IPAddress) -> dict[str, list[dict[str, str]]]: ... diff --git a/stubs/netaddr/netaddr/ip/nmap.pyi b/stubs/netaddr/netaddr/ip/nmap.pyi new file mode 100644 index 000000000..b63826b5e --- /dev/null +++ b/stubs/netaddr/netaddr/ip/nmap.pyi @@ -0,0 +1,6 @@ +from collections.abc import Iterator + +from netaddr.ip import IPAddress + +def valid_nmap_range(target_spec: str) -> bool: ... +def iter_nmap_range(*nmap_target_spec: str) -> Iterator[IPAddress]: ... diff --git a/stubs/netaddr/netaddr/ip/rfc1924.pyi b/stubs/netaddr/netaddr/ip/rfc1924.pyi new file mode 100644 index 000000000..6a4199bf0 --- /dev/null +++ b/stubs/netaddr/netaddr/ip/rfc1924.pyi @@ -0,0 +1,9 @@ +from netaddr.ip import _IPAddressAddr + +def chr_range(low: str, high: str) -> list[str]: ... + +BASE_85: list[str] +BASE_85_DICT: dict[str, int] + +def ipv6_to_base85(addr: _IPAddressAddr) -> str: ... +def base85_to_ipv6(addr: str) -> str: ... diff --git a/stubs/netaddr/netaddr/ip/sets.pyi b/stubs/netaddr/netaddr/ip/sets.pyi new file mode 100644 index 000000000..36c7e0dff --- /dev/null +++ b/stubs/netaddr/netaddr/ip/sets.pyi @@ -0,0 +1,46 @@ +from _typeshed import Self +from collections.abc import Iterable, Iterator +from typing import NoReturn +from typing_extensions import TypeAlias + +from netaddr.ip import IPAddress, IPNetwork, IPRange, _IPNetworkAddr + +_IPIterable: TypeAlias = IPNetwork | IPRange | IPSet | Iterable[_IPNetworkAddr | IPRange | int] + +class IPSet: + def __init__(self, iterable: _IPIterable | None = ..., flags: int = ...) -> None: ... + def compact(self) -> None: ... + def __hash__(self) -> NoReturn: ... + def __contains__(self, ip: _IPNetworkAddr) -> bool: ... + def __bool__(self) -> bool: ... + def __iter__(self) -> Iterator[IPAddress]: ... + def iter_cidrs(self) -> list[IPNetwork]: ... + def add(self, addr: IPRange | _IPNetworkAddr | int, flags: int = ...) -> None: ... + def remove(self, addr: IPRange | _IPNetworkAddr | int, flags: int = ...) -> None: ... + def pop(self) -> IPNetwork: ... + def isdisjoint(self, other: IPSet) -> bool: ... + def copy(self: Self) -> Self: ... + def update(self, iterable: _IPIterable, flags: int = ...) -> None: ... + def clear(self) -> None: ... + def __eq__(self, other: object) -> bool: ... + def __ne__(self, other: object) -> bool: ... + def __lt__(self, other: IPSet) -> bool: ... + def issubset(self, other: IPSet) -> bool: ... + __le__ = issubset + def __gt__(self, other: IPSet) -> bool: ... + def issuperset(self, other: IPSet) -> bool: ... + __ge__ = issuperset + def union(self: Self, other: IPSet) -> Self: ... + __or__ = union + def intersection(self, other: IPSet) -> IPSet: ... + __and__ = intersection + def symmetric_difference(self, other: IPSet) -> IPSet: ... + __xor__ = symmetric_difference + def difference(self, other: IPSet) -> IPSet: ... + __sub__ = difference + def __len__(self) -> int: ... + @property + def size(self) -> int: ... + def iscontiguous(self) -> bool: ... + def iprange(self) -> IPRange | None: ... + def iter_ipranges(self) -> Iterator[IPRange]: ... diff --git a/stubs/netaddr/netaddr/strategy/__init__.pyi b/stubs/netaddr/netaddr/strategy/__init__.pyi new file mode 100644 index 000000000..d2daa0f00 --- /dev/null +++ b/stubs/netaddr/netaddr/strategy/__init__.pyi @@ -0,0 +1,15 @@ +from collections.abc import Iterable, Sequence + +def bytes_to_bits() -> list[str]: ... + +BYTES_TO_BITS: list[str] + +def valid_words(words: Iterable[int], word_size: int, num_words: int) -> bool: ... +def int_to_words(int_val: int, word_size: int, num_words: int) -> tuple[int, ...]: ... +def words_to_int(words: Sequence[int], word_size: int, num_words: int) -> int: ... +def valid_bits(bits: str, width: int, word_sep: str = ...) -> bool: ... +def bits_to_int(bits: str, width: int, word_sep: str = ...) -> int: ... +def int_to_bits(int_val: int, word_size: int, num_words: int, word_sep: str = ...) -> str: ... +def valid_bin(bin_val: str, width: int) -> bool: ... +def int_to_bin(int_val: int, width: int) -> str: ... +def bin_to_int(bin_val: str, width: int) -> int: ... diff --git a/stubs/netaddr/netaddr/strategy/eui48.pyi b/stubs/netaddr/netaddr/strategy/eui48.pyi new file mode 100644 index 000000000..aa7dcb241 --- /dev/null +++ b/stubs/netaddr/netaddr/strategy/eui48.pyi @@ -0,0 +1,43 @@ +from collections.abc import Iterable, Sequence +from re import Pattern +from typing import ClassVar +from typing_extensions import Literal + +AF_LINK: Literal[48] +width: Literal[48] +family: Literal[48] +family_name: Literal["MAC"] +version: Literal[48] +max_int: int + +class mac_eui48: + word_size: ClassVar[int] + num_words: ClassVar[int] + max_word: ClassVar[int] + word_sep: ClassVar[str] + word_fmt: ClassVar[str] + word_base: ClassVar[int] + +class mac_unix(mac_eui48): ... +class mac_unix_expanded(mac_unix): ... +class mac_cisco(mac_eui48): ... +class mac_bare(mac_eui48): ... +class mac_pgsql(mac_eui48): ... + +DEFAULT_DIALECT: type[mac_eui48] +RE_MAC_FORMATS: list[Pattern[str]] + +def valid_str(addr: str) -> bool: ... +def str_to_int(addr: str) -> int: ... +def int_to_str(int_val: int, dialect: type[mac_eui48] | None = ...) -> str: ... +def int_to_packed(int_val: int) -> bytes: ... +def packed_to_int(packed_int: bytes) -> int: ... +def valid_words(words: Iterable[int], dialect: type[mac_eui48] | None = ...) -> bool: ... +def int_to_words(int_val: int, dialect: type[mac_eui48] | None = ...) -> tuple[int, ...]: ... +def words_to_int(words: Sequence[int], dialect: type[mac_eui48] | None = ...) -> int: ... +def valid_bits(bits: str, dialect: type[mac_eui48] | None = ...) -> bool: ... +def bits_to_int(bits: str, dialect: type[mac_eui48] | None = ...) -> int: ... +def int_to_bits(int_val: int, dialect: type[mac_eui48] | None = ...) -> str: ... +def valid_bin(bin_val: str, dialect: type[mac_eui48] | None = ...) -> bool: ... +def int_to_bin(int_val: int) -> str: ... +def bin_to_int(bin_val: str) -> int: ... diff --git a/stubs/netaddr/netaddr/strategy/eui64.pyi b/stubs/netaddr/netaddr/strategy/eui64.pyi new file mode 100644 index 000000000..c5e456cc1 --- /dev/null +++ b/stubs/netaddr/netaddr/strategy/eui64.pyi @@ -0,0 +1,42 @@ +from collections.abc import Iterable, Sequence +from re import Pattern +from typing import ClassVar +from typing_extensions import Literal + +AF_EUI64: Literal[64] +width: Literal[64] +family: Literal[64] +family_name: Literal["EUI-64"] +version: Literal[64] +max_int: int + +class eui64_base: + word_size: ClassVar[int] + num_words: ClassVar[int] + max_word: ClassVar[int] + word_sep: ClassVar[str] + word_fmt: ClassVar[str] + word_base: ClassVar[int] + +class eui64_unix(eui64_base): ... +class eui64_unix_expanded(eui64_unix): ... +class eui64_cisco(eui64_base): ... +class eui64_bare(eui64_base): ... + +DEFAULT_EUI64_DIALECT: type[eui64_base] +RE_EUI64_FORMATS: list[Pattern[str]] + +def valid_str(addr: str) -> bool: ... +def str_to_int(addr: str) -> int: ... +def int_to_str(int_val: int, dialect: type[eui64_base] | None = ...) -> str: ... +def int_to_packed(int_val: int) -> bytes: ... +def packed_to_int(packed_int: bytes) -> int: ... +def valid_words(words: Iterable[int], dialect: type[eui64_base] | None = ...) -> bool: ... +def int_to_words(int_val: int, dialect: type[eui64_base] | None = ...) -> tuple[int, ...]: ... +def words_to_int(words: Sequence[int], dialect: type[eui64_base] | None = ...) -> int: ... +def valid_bits(bits: str, dialect: type[eui64_base] | None = ...) -> bool: ... +def bits_to_int(bits: str, dialect: type[eui64_base] | None = ...) -> int: ... +def int_to_bits(int_val: int, dialect: type[eui64_base] | None = ...) -> str: ... +def valid_bin(bin_val: str, dialect: type[eui64_base] | None = ...) -> bool: ... +def int_to_bin(int_val: int) -> str: ... +def bin_to_int(bin_val: str) -> int: ... diff --git a/stubs/netaddr/netaddr/strategy/ipv4.pyi b/stubs/netaddr/netaddr/strategy/ipv4.pyi new file mode 100644 index 000000000..2fdbe1ae6 --- /dev/null +++ b/stubs/netaddr/netaddr/strategy/ipv4.pyi @@ -0,0 +1,38 @@ +from collections.abc import Iterable, Sequence +from socket import AddressFamily +from typing_extensions import Literal + +from netaddr.core import INET_PTON as INET_PTON, ZEROFILL as ZEROFILL + +width: Literal[32] +word_size: Literal[8] +word_fmt: Literal["%d"] +word_sep: Literal["."] +family: Literal[AddressFamily.AF_INET] +family_name: Literal["IPv4"] +version: Literal[4] +word_base: Literal[10] +max_int: int +num_words: Literal[4] +max_word: int +prefix_to_netmask: dict[int, int] +netmask_to_prefix: dict[int, int] +prefix_to_hostmask: dict[int, int] +hostmask_to_prefix: dict[int, int] + +def valid_str(addr: str, flags: int = ...) -> bool: ... +def str_to_int(addr: str, flags: int = ...) -> int: ... +def int_to_str(int_val: int, dialect: object | None = ...) -> str: ... +def int_to_arpa(int_val: int) -> str: ... +def int_to_packed(int_val: int) -> bytes: ... +def packed_to_int(packed_int: bytes) -> int: ... +def valid_words(words: Iterable[int]) -> bool: ... +def int_to_words(int_val: int) -> tuple[int, ...]: ... +def words_to_int(words: Sequence[int]) -> int: ... +def valid_bits(bits: str) -> bool: ... +def bits_to_int(bits: str) -> int: ... +def int_to_bits(int_val: int, word_sep: str | None = ...) -> str: ... +def valid_bin(bin_val: str) -> bool: ... +def int_to_bin(int_val: int) -> str: ... +def bin_to_int(bin_val: str) -> int: ... +def expand_partial_address(addr: str) -> str: ... diff --git a/stubs/netaddr/netaddr/strategy/ipv6.pyi b/stubs/netaddr/netaddr/strategy/ipv6.pyi new file mode 100644 index 000000000..d96f42efe --- /dev/null +++ b/stubs/netaddr/netaddr/strategy/ipv6.pyi @@ -0,0 +1,44 @@ +from collections.abc import Iterable, Sequence +from typing import ClassVar +from typing_extensions import Final, Literal + +from netaddr.fbsocket import AF_INET6 + +OPT_IMPORTS: bool +width: Literal[128] +word_size: Literal[16] +word_sep: Literal[":"] +family: Final = AF_INET6 +family_name: Literal["IPv6"] +version: Literal[6] +word_base: Literal[16] +max_int: int +num_words: Literal[8] +max_word: int +prefix_to_netmask: dict[int, int] +netmask_to_prefix: dict[int, int] +prefix_to_hostmask: dict[int, int] +hostmask_to_prefix: dict[int, int] + +class ipv6_compact: + word_fmt: ClassVar[str] + compact: ClassVar[bool] + +class ipv6_full(ipv6_compact): ... +class ipv6_verbose(ipv6_compact): ... + +def valid_str(addr: str, flags: int = ...) -> bool: ... +def str_to_int(addr: str, flags: int = ...) -> int: ... +def int_to_str(int_val: int, dialect: type[ipv6_compact] | None = ...) -> str: ... +def int_to_arpa(int_val: int) -> str: ... +def int_to_packed(int_val: int) -> bytes: ... +def packed_to_int(packed_int: bytes) -> int: ... +def valid_words(words: Iterable[int]) -> bool: ... +def int_to_words(int_val: int, num_words: int | None = ..., word_size: int | None = ...) -> tuple[int, ...]: ... +def words_to_int(words: Sequence[int]) -> int: ... +def valid_bits(bits: str) -> bool: ... +def bits_to_int(bits: str) -> int: ... +def int_to_bits(int_val: int, word_sep: str | None = ...) -> str: ... +def valid_bin(bin_val: str) -> bool: ... +def int_to_bin(int_val: int) -> str: ... +def bin_to_int(bin_val: str) -> int: ...