Debian Codegraph @

jedi/third_party/typeshed/stdlib/ipaddress.pyi

raw symbols SCIP
1 import sys
2 from collections.abc import Iterable, Iterator
3 from typing import Any, Final, Generic, Literal, TypeVar, overload
4 from typing_extensions import Self, TypeAlias
5
6 # Undocumented length constants
7 IPV4LENGTH: Final = 32
8 IPV6LENGTH: Final = 128
9
10 _A = TypeVar("_A", IPv4Address, IPv6Address)
11 _N = TypeVar("_N", IPv4Network, IPv6Network)
12
13 _RawIPAddress: TypeAlias = int | str | bytes | IPv4Address | IPv6Address
14 _RawNetworkPart: TypeAlias = IPv4Network | IPv6Network | IPv4Interface | IPv6Interface
15
16 def ip_address(address: _RawIPAddress) -> IPv4Address | IPv6Address: ...
17 def ip_network(
18 address: _RawIPAddress | _RawNetworkPart | tuple[_RawIPAddress] | tuple[_RawIPAddress, int], strict: bool = True
19 ) -> IPv4Network | IPv6Network: ...
20 def ip_interface(
21 address: _RawIPAddress | _RawNetworkPart | tuple[_RawIPAddress] | tuple[_RawIPAddress, int],
22 ) -> IPv4Interface | IPv6Interface: ...
23
24 class _IPAddressBase:
25 __slots__ = ()
26 @property
27 def compressed(self) -> str: ...
28 @property
29 def exploded(self) -> str: ...
30 @property
31 def reverse_pointer(self) -> str: ...
32 if sys.version_info < (3, 14):
33 @property
34 def version(self) -> int: ...
35
36 class _BaseAddress(_IPAddressBase):
37 __slots__ = ()
38 def __add__(self, other: int) -> Self: ...
39 def __hash__(self) -> int: ...
40 def __int__(self) -> int: ...
41 def __sub__(self, other: int) -> Self: ...
42 def __format__(self, fmt: str) -> str: ...
43 def __eq__(self, other: object) -> bool: ...
44 def __lt__(self, other: Self) -> bool: ...
45 if sys.version_info >= (3, 11):
46 def __ge__(self, other: Self) -> bool: ...
47 def __gt__(self, other: Self) -> bool: ...
48 def __le__(self, other: Self) -> bool: ...
49 else:
50 def __ge__(self, other: Self, NotImplemented: Any = ...) -> bool: ...
51 def __gt__(self, other: Self, NotImplemented: Any = ...) -> bool: ...
52 def __le__(self, other: Self, NotImplemented: Any = ...) -> bool: ...
53
54 class _BaseNetwork(_IPAddressBase, Generic[_A]):
55 network_address: _A
56 netmask: _A
57 def __contains__(self, other: Any) -> bool: ...
58 def __getitem__(self, n: int) -> _A: ...
59 def __iter__(self) -> Iterator[_A]: ...
60 def __eq__(self, other: object) -> bool: ...
61 def __hash__(self) -> int: ...
62 def __lt__(self, other: Self) -> bool: ...
63 if sys.version_info >= (3, 11):
64 def __ge__(self, other: Self) -> bool: ...
65 def __gt__(self, other: Self) -> bool: ...
66 def __le__(self, other: Self) -> bool: ...
67 else:
68 def __ge__(self, other: Self, NotImplemented: Any = ...) -> bool: ...
69 def __gt__(self, other: Self, NotImplemented: Any = ...) -> bool: ...
70 def __le__(self, other: Self, NotImplemented: Any = ...) -> bool: ...
71
72 def address_exclude(self, other: Self) -> Iterator[Self]: ...
73 @property
74 def broadcast_address(self) -> _A: ...
75 def compare_networks(self, other: Self) -> int: ...
76 def hosts(self) -> Iterator[_A]: ...
77 @property
78 def is_global(self) -> bool: ...
79 @property
80 def is_link_local(self) -> bool: ...
81 @property
82 def is_loopback(self) -> bool: ...
83 @property
84 def is_multicast(self) -> bool: ...
85 @property
86 def is_private(self) -> bool: ...
87 @property
88 def is_reserved(self) -> bool: ...
89 @property
90 def is_unspecified(self) -> bool: ...
91 @property
92 def num_addresses(self) -> int: ...
93 def overlaps(self, other: _BaseNetwork[IPv4Address] | _BaseNetwork[IPv6Address]) -> bool: ...
94 @property
95 def prefixlen(self) -> int: ...
96 def subnet_of(self, other: Self) -> bool: ...
97 def supernet_of(self, other: Self) -> bool: ...
98 def subnets(self, prefixlen_diff: int = 1, new_prefix: int | None = None) -> Iterator[Self]: ...
99 def supernet(self, prefixlen_diff: int = 1, new_prefix: int | None = None) -> Self: ...
100 @property
101 def with_hostmask(self) -> str: ...
102 @property
103 def with_netmask(self) -> str: ...
104 @property
105 def with_prefixlen(self) -> str: ...
106 @property
107 def hostmask(self) -> _A: ...
108
109 class _BaseV4:
110 __slots__ = ()
111 if sys.version_info >= (3, 14):
112 version: Final = 4
113 max_prefixlen: Final = 32
114 else:
115 @property
116 def version(self) -> Literal[4]: ...
117 @property
118 def max_prefixlen(self) -> Literal[32]: ...
119
120 class IPv4Address(_BaseV4, _BaseAddress):
121 __slots__ = ("_ip", "__weakref__")
122 def __init__(self, address: object) -> None: ...
123 @property
124 def is_global(self) -> bool: ...
125 @property
126 def is_link_local(self) -> bool: ...
127 @property
128 def is_loopback(self) -> bool: ...
129 @property
130 def is_multicast(self) -> bool: ...
131 @property
132 def is_private(self) -> bool: ...
133 @property
134 def is_reserved(self) -> bool: ...
135 @property
136 def is_unspecified(self) -> bool: ...
137 @property
138 def packed(self) -> bytes: ...
139 if sys.version_info >= (3, 13):
140 @property
141 def ipv6_mapped(self) -> IPv6Address: ...
142
143 class IPv4Network(_BaseV4, _BaseNetwork[IPv4Address]):
144 def __init__(self, address: object, strict: bool = True) -> None: ...
145
146 class IPv4Interface(IPv4Address):
147 netmask: IPv4Address
148 network: IPv4Network
149 def __eq__(self, other: object) -> bool: ...
150 def __hash__(self) -> int: ...
151 @property
152 def hostmask(self) -> IPv4Address: ...
153 @property
154 def ip(self) -> IPv4Address: ...
155 @property
156 def with_hostmask(self) -> str: ...
157 @property
158 def with_netmask(self) -> str: ...
159 @property
160 def with_prefixlen(self) -> str: ...
161
162 class _BaseV6:
163 __slots__ = ()
164 if sys.version_info >= (3, 14):
165 version: Final = 6
166 max_prefixlen: Final = 128
167 else:
168 @property
169 def version(self) -> Literal[6]: ...
170 @property
171 def max_prefixlen(self) -> Literal[128]: ...
172
173 class IPv6Address(_BaseV6, _BaseAddress):
174 __slots__ = ("_ip", "_scope_id", "__weakref__")
175 def __init__(self, address: object) -> None: ...
176 @property
177 def is_global(self) -> bool: ...
178 @property
179 def is_link_local(self) -> bool: ...
180 @property
181 def is_loopback(self) -> bool: ...
182 @property
183 def is_multicast(self) -> bool: ...
184 @property
185 def is_private(self) -> bool: ...
186 @property
187 def is_reserved(self) -> bool: ...
188 @property
189 def is_unspecified(self) -> bool: ...
190 @property
191 def packed(self) -> bytes: ...
192 @property
193 def ipv4_mapped(self) -> IPv4Address | None: ...
194 @property
195 def is_site_local(self) -> bool: ...
196 @property
197 def sixtofour(self) -> IPv4Address | None: ...
198 @property
199 def teredo(self) -> tuple[IPv4Address, IPv4Address] | None: ...
200 @property
201 def scope_id(self) -> str | None: ...
202 def __hash__(self) -> int: ...
203 def __eq__(self, other: object) -> bool: ...
204
205 class IPv6Network(_BaseV6, _BaseNetwork[IPv6Address]):
206 def __init__(self, address: object, strict: bool = True) -> None: ...
207 @property
208 def is_site_local(self) -> bool: ...
209
210 class IPv6Interface(IPv6Address):
211 netmask: IPv6Address
212 network: IPv6Network
213 def __eq__(self, other: object) -> bool: ...
214 def __hash__(self) -> int: ...
215 @property
216 def hostmask(self) -> IPv6Address: ...
217 @property
218 def ip(self) -> IPv6Address: ...
219 @property
220 def with_hostmask(self) -> str: ...
221 @property
222 def with_netmask(self) -> str: ...
223 @property
224 def with_prefixlen(self) -> str: ...
225
226 def v4_int_to_packed(address: int) -> bytes: ...
227 def v6_int_to_packed(address: int) -> bytes: ...
228
229 # Third overload is technically incorrect, but convenient when first and last are return values of ip_address()
230 @overload
231 def summarize_address_range(first: IPv4Address, last: IPv4Address) -> Iterator[IPv4Network]: ...
232 @overload
233 def summarize_address_range(first: IPv6Address, last: IPv6Address) -> Iterator[IPv6Network]: ...
234 @overload
235 def summarize_address_range(
236 first: IPv4Address | IPv6Address, last: IPv4Address | IPv6Address
237 ) -> Iterator[IPv4Network] | Iterator[IPv6Network]: ...
238 def collapse_addresses(addresses: Iterable[_N]) -> Iterator[_N]: ...
239 @overload
240 def get_mixed_type_key(obj: _A) -> tuple[int, _A]: ...
241 @overload
242 def get_mixed_type_key(obj: IPv4Network) -> tuple[int, IPv4Address, IPv4Address]: ...
243 @overload
244 def get_mixed_type_key(obj: IPv6Network) -> tuple[int, IPv6Address, IPv6Address]: ...
245
246 class AddressValueError(ValueError): ...
247 class NetmaskValueError(ValueError): ...