|
@@ -1,5 +1,4 @@
|
|
|
import re
|
|
|
-from typing import Union, Any, Optional
|
|
|
|
|
|
|
|
|
class IPAddress:
|
|
@@ -120,13 +119,13 @@ class IPAddress:
|
|
|
def __hash__(self) -> int:
|
|
|
return self.ipnum
|
|
|
|
|
|
- def __eq__(self, other: Any) -> bool:
|
|
|
+ def __eq__(self, other) -> bool:
|
|
|
if other is None:
|
|
|
return False
|
|
|
|
|
|
return isinstance(other, IPAddress) and self.ipnum == other.ipnum
|
|
|
|
|
|
- def __lt__(self, other: Any) -> bool:
|
|
|
+ def __lt__(self, other) -> bool:
|
|
|
if other is None:
|
|
|
raise TypeError("Cannot compare to None")
|
|
|
if not isinstance(other, IPAddress):
|
|
@@ -147,7 +146,7 @@ class IPAddressBlock:
|
|
|
# this regex describes CIDR-notation (an ip-address plus "/XX", whereas XX is a number between 1 and 32)
|
|
|
CIDR_REGEXP = IPAddress.IP_REGEXP + r"(\/(3[0-2]|[12]?\d)|)?"
|
|
|
|
|
|
- def __init__(self, ip: Union(str, list, IPAddress), netmask = 32) -> "IPAddressBlock":
|
|
|
+ def __init__(self, ip: "Union(str, list, IPAddress)", netmask = 32) -> "IPAddressBlock":
|
|
|
"""
|
|
|
Construct a ip-block given a ip-address and a netmask. Given an ip and a netmask,
|
|
|
the constructed ip-block will describe the range ip/netmask (e.g. 127.0.0.1/8)
|
|
@@ -244,7 +243,7 @@ class ReservedIPBlocks:
|
|
|
return any(ip in block for block in ReservedIPBlocks.PRIVATE_IP_SEGMENTS)
|
|
|
|
|
|
@staticmethod
|
|
|
- def get_private_segment(ip: IPAddress) -> Optional[IPAddressBlock]:
|
|
|
+ def get_private_segment(ip: IPAddress) -> "Optional[IPAddressBlock]":
|
|
|
if not ReservedIPBlocks.is_private(ip):
|
|
|
raise ValueError("%s is not part of a private IP segment" % ip)
|
|
|
|