chiark / gitweb /
make-secnet-sites: Switch to `ipaddress' from `ipaddr'
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 24 Oct 2019 18:03:59 +0000 (19:03 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 24 Oct 2019 18:16:16 +0000 (19:16 +0100)
ipaddress is available in python3 and ipaddr is not.

Code changes:
 - Change the imports and references to the module name
 - IPNetwork & IPAddress functions => ip_address & ip_network
 - There is no IPNetwork superclass so don't mention it in docstrings
 - collapse_address_list => collapse_addresses
 - There is no version parameter to ip_address; we have to
   switch on v ourselves and call IPv6Address or IPv4Address

Administrivia:
 - Update debian/control and INSTALL.
 - Remove references to ipaddr's licence.  ipaddress is under
   the same licence as python so does not need special mention.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
INSTALL
debian/control
ipaddrset-test.py
ipaddrset.py
make-secnet-sites

diff --git a/INSTALL b/INSTALL
index 020907d884838a1a37a482a3a3d141851d71b21d..fa5bf3ad00201a80904acd8c3567fd584e68ec8c 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -30,8 +30,8 @@ http://vtun.sourceforge.net/tun/
 You will probably be using the supplied `make-secnet-sites' program to
 generate your VPN's list of sites as a secnet configuration from a
 more-human-writeable form.  If so you need to install the standard
-`future' and `ipaddr' Python modules (python-future and python-ipaddr
-on Debian-derived systems).
+`future' and `ipaddress' Python modules (python-future and
+python-ipaddress on Debian-derived systems).
 
 ** System and network configuration
 
index e0b0f8831c339056e720b823f70ef5440c324fcb..d4cdbd275d4c88981d739f6c360997bdfebdf7f3 100644 (file)
@@ -5,7 +5,7 @@ Maintainer: Ian Jackson <ijackson@chiark.greenend.org.uk>
 Uploaders: Stephen Early <steve@greenend.org.uk>,
            Richard Kettlewell <rjk@terraraq.org.uk>
 Build-Depends: debhelper (>= 5), libgmp3-dev, libadns1-dev, bison, flex,
-               libbsd-dev, python-ipaddr, python-future, tclx, tcl, libtcl-chiark-1
+               libbsd-dev, python-ipaddress, python-future, tclx, tcl, libtcl-chiark-1
 Standards-Version: 3.0.1
 
 Package: secnet
index fdc0b6b28c9f5fed667c6213174b9e516f6c12f8..f17e757b07a6bf0a4f2416c40d4ac54c73cdd98f 100755 (executable)
 # You may redistribute this fileand/or modify it under the terms of
 # the GNU General Public License as published by the Free Software
 # Foundation; either version 2, or (at your option) any later version.
-# Note however that this version of ipaddrset.py uses the Python
-# ipaddr library from Google, which is licenced only under the Apache
-# Licence, version 2.0, which is only compatible with the GNU GPL v3
-# (or perhaps later versions), and not with the GNU GPL v2.
 #
 # This software is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 from __future__ import print_function
 from __future__ import unicode_literals
 
-import ipaddr
-from ipaddr import IPNetwork, IPAddress
+import ipaddress
+from ipaddress import ip_network, ip_address
 
 import ipaddrset
 from ipaddrset import IPAddressSet
 
-v4a=IPAddress('172.18.45.6')
+v4a=ip_address('172.18.45.6')
 
 s=IPAddressSet()
 print('s =', s)
-s.append([IPNetwork('172.18.45.0/24')])
-s.append([IPNetwork('2001:23:24::/48')])
+s.append([ip_network('172.18.45.0/24')])
+s.append([ip_network('2001:23:24::/48')])
 print(s)
 
-t=IPAddressSet(map(IPNetwork,['172.31.80.8/32','172.18.45.192/28']))
+t=IPAddressSet(map(ip_network,['172.31.80.8/32','172.18.45.192/28']))
 print('t =', t)
 print(t <= s)
 print(t == s)
 
 for n1s in ['172.18.44.0/23','172.18.45.6/32','172.18.45.0/24']:
-    n1=IPNetwork(n1s)
+    n1=ip_network(n1s)
     print(n1)
     print(s.contains(n1))
     print(t.contains(n1))
index 84c7dcacdd66aff139f06d05331df374d3a64778..38d45711f3735a93958725aa50fb9e338c9f7b13 100644 (file)
@@ -1,4 +1,4 @@
-"""IP address set manipulation, built on top of ipaddr.py"""
+"""IP address set manipulation, built on top of ipaddress.py"""
 
 # This file is Free Software.  It was originally written for secnet.
 #
@@ -26,7 +26,7 @@
 # along with this software; if not, see
 # https://www.gnu.org/licenses/gpl.html.
 
-import ipaddr
+import ipaddress
 
 _vsns = [6,4]
 
@@ -35,7 +35,7 @@ class IPAddressSet:
 
        # constructors
        def __init__(self,l=[]):
-               "New set contains each ipaddr.IPNetwork in the sequence l"
+               "New set contains each IP*Network in the sequence l"
                self._v = {}
                for v in _vsns:
                        self._v[v] = [ ]
@@ -44,7 +44,8 @@ class IPAddressSet:
        # housekeeping and representation
        def _compact(self):
                for v in _vsns:
-                       self._v[v] = ipaddr.collapse_address_list(self._v[v])
+                       self._v[v] = list(
+                               ipaddress.collapse_addresses(self._v[v]))
        def __repr__(self):
                return "IPAddressSet(%s)" % self.networks()
        def str(self,comma=",",none="-"):
@@ -58,12 +59,12 @@ class IPAddressSet:
 
        # mutators
        def append(self,l):
-               "Appends each ipaddr.IPNetwork in the sequence l to self"
+               "Appends each IP*Network in the sequence l to self"
                self._append(l)
                self._compact()
 
        def _append(self,l):
-               "Appends each ipaddr.IPNetwork in the sequence l to self"
+               "Appends each IP*Network in the sequence l to self"
                for a in l:
                        self._v[a.version].append(a)
 
@@ -143,7 +144,7 @@ class IPAddressSet:
                except KeyError:
                        v = None
                if v:
-                       return self._contains_net(ipaddr.IPNetwork(thing))
+                       return self._contains_net(ipaddress.ip_network(thing))
                else:
                        return self.__ge__(thing)
 
@@ -151,7 +152,9 @@ def complete_set():
        "Returns a set containing all addresses"
        s=IPAddressSet()
        for v in _vsns:
-               a=ipaddr.IPAddress(0,v)
-               n=ipaddr.IPNetwork("%s/0" % a)
+               if v==6: a=ipaddress.IPv6Address(0)
+               elif v==4: a=ipaddress.IPv4Address(0)
+               else: raise "internal error"
+               n=ipaddress.ip_network("%s/0" % a)
                s.append([n])
        return s
index 1cc979b57e4c5c7ecb66ffcbee9edf19154541cd..158f5b36c8229b170969fe966de4cb23d4c84731 100755 (executable)
@@ -46,8 +46,7 @@ no-suppress-args
 cd ~/secnet/sites-test/
 execute ~/secnet/make-secnet-sites.py -u vpnheader groupfiles sites
 
-This program is part of secnet. It relies on the "ipaddr" library from
-Cendio Systems AB.
+This program is part of secnet.
 
 """
 
@@ -62,7 +61,7 @@ import os
 import getopt
 import re
 
-import ipaddr
+import ipaddress
 
 # entry 0 is "near the executable", or maybe from PYTHONPATH=.,
 # which we don't want to preempt
@@ -148,7 +147,7 @@ def listof(subtype):
 class single_ipaddr (basetype):
        "An IP address"
        def __init__(self,w):
-               self.addr=ipaddr.IPAddress(w[1])
+               self.addr=ipaddress.ip_address(w[1])
        def __str__(self):
                return '"%s"'%self.addr
 
@@ -157,7 +156,7 @@ class networks (basetype):
        def __init__(self,w):
                self.set=ipaddrset.IPAddressSet()
                for i in w[1:]:
-                       x=ipaddr.IPNetwork(i,strict=True)
+                       x=ipaddress.ip_network(i,strict=True)
                        self.set.append([x])
        def __str__(self):
                return ",".join(map((lambda n: '"%s"'%n), self.set.networks()))