From: Nicolas Iooss <nicolas.iooss@m4x.org>
To: Petr Lautrbach <plautrba@redhat.com>
Cc: SElinux list <selinux@vger.kernel.org>
Subject: Re: [PATCH v2] python/semanage: Use ipaddress module instead of IPy
Date: Tue, 28 Apr 2020 23:28:13 +0200 [thread overview]
Message-ID: <CAJfZ7=mjM5YqgaF0sjibssaj3Jdb03f5HDtXdwg-VQcF7_ygPg@mail.gmail.com> (raw)
In-Reply-To: <20200427153438.17061-1-plautrba@redhat.com>
On Mon, Apr 27, 2020 at 5:35 PM Petr Lautrbach <plautrba@redhat.com> wrote:
>
> ipaddress python module was added to standard library in Python 3.3 -
> https://docs.python.org/3/library/ipaddress.html
>
> seobject.py was the only consumer of IPy module so this dependency is not needed
> anymore.
>
> Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
> ---
>
> Based on Nicolas input:
>
> - improved the check comment
> - dropped the unnecessary check
Acked-by: Nicolas Iooss <nicolas.iooss@m4x.org>
I will apply this patch tomorrow if nobody else has any comment.
Thanks,
Nicolas
> python/semanage/seobject.py | 15 ++++++---------
> 1 file changed, 6 insertions(+), 9 deletions(-)
>
> diff --git a/python/semanage/seobject.py b/python/semanage/seobject.py
> index f2a139c970bd..6e0b87f2fa3c 100644
> --- a/python/semanage/seobject.py
> +++ b/python/semanage/seobject.py
> @@ -32,7 +32,7 @@ from semanage import *
> PROGNAME = "policycoreutils"
> import sepolicy
> import setools
> -from IPy import IP
> +import ipaddress
>
> try:
> import gettext
> @@ -1858,15 +1858,12 @@ class nodeRecords(semanageRecords):
> if addr == "":
> raise ValueError(_("Node Address is required"))
>
> - # verify valid combination
> + # verify that (addr, mask) is either a IP address (without a mask) or a valid network mask
> if len(mask) == 0 or mask[0] == "/":
> - i = IP(addr + mask)
> - newaddr = i.strNormal(0)
> - newmask = str(i.netmask())
> - if newmask == "0.0.0.0" and i.version() == 6:
> - newmask = "::"
> -
> - protocol = "ipv%d" % i.version()
> + i = ipaddress.ip_network(addr + mask)
> + newaddr = str(i.network_address)
> + newmask = str(i.netmask)
> + protocol = "ipv%d" % i.version
>
> try:
> newprotocol = self.protocol.index(protocol)
> --
> 2.26.2
>
next prev parent reply other threads:[~2020-04-28 21:28 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-24 14:59 [PATCH] python/semanage: Use ipaddress module instead of IPy Petr Lautrbach
2020-04-24 19:46 ` Roberts, William C
2020-04-25 6:52 ` Nicolas Iooss
2020-04-27 15:34 ` [PATCH v2] " Petr Lautrbach
2020-04-28 21:28 ` Nicolas Iooss [this message]
2020-05-01 7:47 ` Nicolas Iooss
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAJfZ7=mjM5YqgaF0sjibssaj3Jdb03f5HDtXdwg-VQcF7_ygPg@mail.gmail.com' \
--to=nicolas.iooss@m4x.org \
--cc=plautrba@redhat.com \
--cc=selinux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).