X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=ipaddrset-test.py;h=16258f05b4985ee35a29df3d96ba6112346e2851;hb=4a6ee8b677fd7addc97fc0d245f95ddde3b5f8e4;hp=290144b18a886d086d0f083492f2e942f1ec3d11;hpb=6437945aefa308c06ab14da291c5d5489c25b393;p=secnet.git diff --git a/ipaddrset-test.py b/ipaddrset-test.py index 290144b..16258f0 100755 --- a/ipaddrset-test.py +++ b/ipaddrset-test.py @@ -1,51 +1,69 @@ -#!/usr/bin/python +#!/usr/bin/python3 -import sys -import copy -import os -saved_path=copy.copy(sys.path) -for p in ['','.',os.getcwd()]: - try: sys.path.remove(p) - except ValueError: pass +# This file is Free Software. It was originally written for secnet. +# +# Copyright 2014 Ian Jackson +# +# You may redistribute secnet as a whole and/or modify it under the +# terms of the GNU General Public License as published by the Free +# Software Foundation; either version 3, or (at your option) any +# later version. +# +# 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. +# +# This software is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this software; if not, see +# https://www.gnu.org/licenses/gpl.html. +# +# The corresponding test vector file ise ipaddrset-test.expected. I +# don't believe it is a creative work that attracts copyright. -iwj. -import ipaddr -from ipaddr import IPNetwork, IPAddress +from __future__ import print_function +from __future__ import unicode_literals -sys.path=saved_path +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::/40')]) -print s +print('s =', s) +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'])) -print 't =', t -print t <= s -print t == s +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) - print n1 - print s.contains(n1) - print t.contains(n1) + n1=ip_network(n1s) + print(n1) + print(s.contains(n1)) + print(t.contains(n1)) n=s.networks()[0] a=ipaddrset.complete_set() -print 'a =', a -print a >= s -print a >= t +print('a =', a) +print(a >= s) +print(a >= t) -print '^' -print s.intersection(t) -print t.intersection(s) +print('^') +print(s.intersection(t)) +print(t.intersection(s)) -print 'u' -print s.union(t) -print t.union(s) +print('u') +print(s.union(t)) +print(t.union(s))