Skip to content

Commit

Permalink
Replace IPy with ipaddress
Browse files Browse the repository at this point in the history
The Python standary library includes ipaddress packages since Python
3.3. Therefore, the IPy can be replaced
  • Loading branch information
ott committed Sep 7, 2024
1 parent 219fff2 commit 0216c75
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
14 changes: 8 additions & 6 deletions mirrormanager2/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
# pylint: disable=W0232


import ipaddress
import re

import wtforms
Expand All @@ -40,7 +41,6 @@
except ImportError:
from flask_wtf import Form as FlaskForm

import IPy
from flask import current_app, g

COUNTRY_REGEX = "^[a-zA-Z][a-zA-Z]$"
Expand Down Expand Up @@ -140,17 +140,19 @@ def validate_netblocks(form, field):
emsg += " can only be created by mirrormanager administrators."
emsg += " Please ask the mirrormanager administrators for assistance."

ipv4_block = IPy.IP(f"10.0.0.0{max_ipv4_netblock_size}")
ipv6_block = IPy.IP(f"fec0::{max_ipv6_netblock_size}")
ipv4_block = ipaddress.IPv4Network(f"10.0.0.0{max_ipv4_netblock_size}",
strict=False)
ipv6_block = ipaddress.IPv6Network(f"fec0::{max_ipv6_netblock_size}",
strict=False)

try:
ip = IPy.IP(field.data, make_net=True)
ip = ipaddress.ip_network(field.data, strict=False)
except ValueError:
# also accept DNS hostnames
return
if (
(ip.version() == 4 and ip.len() > ipv4_block.len())
or (ip.version() == 6 and ip.len() > ipv6_block.len())
(ip.version == 4 and ip.prefixlen < ipv4_block.prefixlen)
or (ip.version == 6 and ip.prefixlen < ipv6_block.prefixlen)
) and not g.is_mirrormanager_admin:
raise wtforms.validators.ValidationError(emsg)

Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ flask-oidc = "^2.0.0"
flask-xml-rpc-re = "^0.1.4"
flask-wtf = "^1.1.1"
wtforms = "^3.0.1"
ipy = "^1.1"
dnspython = "^2.3.0"
backoff = "^2.2.1"
fedora-messaging = "^3.3.0"
Expand Down
2 changes: 0 additions & 2 deletions utility/mirrormanager2.spec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ BuildRequires: python%{python_pkgversion}-flask-oidc >= 2.0.0
BuildRequires: python%{python_pkgversion}-flask-xml-rpc
BuildRequires: python%{python_pkgversion}-flask-wtf
BuildRequires: python%{python_pkgversion}-wtforms
BuildRequires: python%{python_pkgversion}-IPy
BuildRequires: python%{python_pkgversion}-dns
BuildRequires: python%{python_pkgversion}-backoff
BuildRequires: python%{python_pkgversion}-fedora-messaging
Expand Down Expand Up @@ -71,7 +70,6 @@ Summary: Library to interact with MirrorManager's database
BuildArch: noarch

Requires: %{name}-filesystem = %{version}-%{release}
Requires: python%{python_pkgversion}-IPy
Requires: python%{python_pkgversion}-dns
Requires: python%{python_pkgversion}-pyrpmmd

Expand Down

0 comments on commit 0216c75

Please sign in to comment.