From 023aa5e4937065fc879857a0891982c42a9d9c5e Mon Sep 17 00:00:00 2001 From: Alex Charrett Date: Fri, 12 Jul 2024 11:14:24 +0100 Subject: [PATCH] Update for netaddr 1.0.0 --- geofeed_validator/fields/base.py | 9 ++++++++- pyproject.toml | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/geofeed_validator/fields/base.py b/geofeed_validator/fields/base.py index 75b145a..b9d2049 100644 --- a/geofeed_validator/fields/base.py +++ b/geofeed_validator/fields/base.py @@ -115,6 +115,7 @@ class NetworkField(Field): ERROR_PRIVATE = "Private network not allowed" ERROR_RESERVED = "Reserved network not allowed" ERROR_MULTICAST = "Multicast network not allowed" + ERROR_LINKLOCAL = "Link-local network not allowed" NAME = "network" def _check_errors(self, value): @@ -124,10 +125,16 @@ def _check_errors(self, value): except: return True + ip = netaddr.IPAddress(net.network) + if net.is_loopback(): return self.ERROR_LOOPBACK - elif net.is_private(): + elif ip.is_ipv4_private_use(): + return self.ERROR_PRIVATE + elif ip.is_ipv6_unique_local(): return self.ERROR_PRIVATE + elif ip.is_link_local(): + return self.ERROR_LINKLOCAL elif net.is_reserved(): return self.ERROR_RESERVED elif net.is_multicast(): diff --git a/pyproject.toml b/pyproject.toml index e5095fc..45cb666 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,7 +32,7 @@ include = [ [tool.poetry.dependencies] python = ">=3.6.2,<4" pycountry = ">=20.7.3" -netaddr = ">=0.8.0" +netaddr = ">=1.0.0" [tool.poetry.dev-dependencies] coverage = ">=5.5.0"