Update typing 03 (#48015)
This commit is contained in:
parent
6fb2e63e49
commit
fabd73f08b
37 changed files with 417 additions and 379 deletions
|
@ -1,6 +1,7 @@
|
|||
"""Network utilities."""
|
||||
from __future__ import annotations
|
||||
|
||||
from ipaddress import IPv4Address, IPv6Address, ip_address, ip_network
|
||||
from typing import Union
|
||||
|
||||
import yarl
|
||||
|
||||
|
@ -23,22 +24,22 @@ PRIVATE_NETWORKS = (
|
|||
LINK_LOCAL_NETWORK = ip_network("169.254.0.0/16")
|
||||
|
||||
|
||||
def is_loopback(address: Union[IPv4Address, IPv6Address]) -> bool:
|
||||
def is_loopback(address: IPv4Address | IPv6Address) -> bool:
|
||||
"""Check if an address is a loopback address."""
|
||||
return any(address in network for network in LOOPBACK_NETWORKS)
|
||||
|
||||
|
||||
def is_private(address: Union[IPv4Address, IPv6Address]) -> bool:
|
||||
def is_private(address: IPv4Address | IPv6Address) -> bool:
|
||||
"""Check if an address is a private address."""
|
||||
return any(address in network for network in PRIVATE_NETWORKS)
|
||||
|
||||
|
||||
def is_link_local(address: Union[IPv4Address, IPv6Address]) -> bool:
|
||||
def is_link_local(address: IPv4Address | IPv6Address) -> bool:
|
||||
"""Check if an address is link local."""
|
||||
return address in LINK_LOCAL_NETWORK
|
||||
|
||||
|
||||
def is_local(address: Union[IPv4Address, IPv6Address]) -> bool:
|
||||
def is_local(address: IPv4Address | IPv6Address) -> bool:
|
||||
"""Check if an address is loopback or private."""
|
||||
return is_loopback(address) or is_private(address)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue