diff --git a/mirrors/fields.py b/mirrors/fields.py index ceb20a7e..3216d831 100644 --- a/mirrors/fields.py +++ b/mirrors/fields.py @@ -1,10 +1,14 @@ -from IPy import IP - from django import forms from django.core import validators from django.core.exceptions import ValidationError from django.db import models +from ipaddress import ip_address, ip_interface + +def IP(address): + if '/' not in address: + return ip_address(address) + return ip_interface(address) class IPNetworkFormField(forms.Field): def to_python(self, value): diff --git a/mirrors/tests/test_mirrorrsync.py b/mirrors/tests/test_mirrorrsync.py index bf5d26fd..fe8ee5af 100644 --- a/mirrors/tests/test_mirrorrsync.py +++ b/mirrors/tests/test_mirrorrsync.py @@ -4,7 +4,9 @@ TEST_IPV6 = "2a0b:4342:1a31:410::" +TEST_IPV6_MASK = "2a0b:4342:1a31:410::/64" TEST_IPV4 = "8.8.8.8" +TEST_IPV4_MASK = "192.168.1.0/24" class MirrorRsyncTest(TransactionTestCase): @@ -20,12 +22,22 @@ def test_ipv6(self): self.assertEqual(str(mirrorrsync), TEST_IPV6) mirrorrsync.delete() + def test_ipv6_mask(self): + mirrorsync = MirrorRsync.objects.create(ip=TEST_IPV6_MASK, mirror=self.mirror) + self.assertEqual(str(mirrorsync), TEST_IPV6_MASK) + mirrorsync.delete() + def test_ipv4(self): mirrorrsync = MirrorRsync.objects.create(ip=TEST_IPV4, mirror=self.mirror) self.assertEqual(str(mirrorrsync), TEST_IPV4) mirrorrsync.delete() + def test_ipv4_mask(self): + mirrorrsync = MirrorRsync.objects.create(ip=TEST_IPV4_MASK, mirror=self.mirror) + self.assertEqual(str(mirrorrsync), TEST_IPV4_MASK) + mirrorrsync.delete() + def test_invalid(self): with self.assertRaises(ValueError) as e: MirrorRsync.objects.create(ip="8.8.8.8.8", mirror=self.mirror) - self.assertIn('IPv4 Address with more than 4 bytes', str(e.exception)) + self.assertIn('does not appear to be an IPv4 or IPv6 address', str(e.exception)) diff --git a/requirements.txt b/requirements.txt index 8107a325..1ea81185 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,5 @@ -e git+git://github.com/fredj/cssmin.git@master#egg=cssmin Django==3.2.7 -IPy==1.1 Markdown==3.3.4 bencode.py==4.0.0 django-countries==7.2.1