Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions flow/record/fieldtypes/net/ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,9 @@ def __eq__(self, b: _ConversionTypes | _IPNetwork) -> bool:
def __hash__(self) -> int:
return hash(self.val)

@staticmethod
def _is_subnet_of(a: _IPNetwork, b: _IPNetwork) -> bool:
try:
# Always false if one is v4 and the other is v6.
if a._version != b._version:
raise TypeError(f"{a} and {b} are not of the same version")
except AttributeError:
raise TypeError(f"Unable to test subnet containment between {a} and {b}")
else:
return b.network_address <= a.network_address and b.broadcast_address >= a.broadcast_address

def __contains__(self, b: object) -> bool:
try:
return self._is_subnet_of(ip_network(b), self.val)
return ip_network(b).subnet_of(self.val)
except (ValueError, TypeError):
return False

Expand Down