chiark / gitweb /
Makefiles: Use Final.sd.mk to implementing RECHECK_RM
[secnet.git] / ipaddrset-test.py
1 #!/usr/bin/python3
2
3 # This file is Free Software.  It was originally written for secnet.
4 #
5 # Copyright 2014 Ian Jackson
6 #
7 # You may redistribute secnet as a whole and/or modify it under the
8 # terms of the GNU General Public License as published by the Free
9 # Software Foundation; either version 3, or (at your option) any
10 # later version.
11 #
12 # You may redistribute this fileand/or modify it under the terms of
13 # the GNU General Public License as published by the Free Software
14 # Foundation; either version 2, or (at your option) any later version.
15 #
16 # This software is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this software; if not, see
23 # https://www.gnu.org/licenses/gpl.html.
24 #
25 # The corresponding test vector file ise ipaddrset-test.expected.  I
26 # don't believe it is a creative work that attracts copyright.  -iwj.
27
28 from __future__ import print_function
29 from __future__ import unicode_literals
30
31 import ipaddress
32 from ipaddress import ip_network, ip_address
33
34 import ipaddrset
35 from ipaddrset import IPAddressSet
36
37 v4a=ip_address('172.18.45.6')
38
39 s=IPAddressSet()
40 print('s =', s)
41 s.append([ip_network('172.18.45.0/24')])
42 s.append([ip_network('2001:23:24::/48')])
43 print(s)
44
45 t=IPAddressSet(map(ip_network,['172.31.80.8/32','172.18.45.192/28']))
46 print('t =', t)
47 print(t <= s)
48 print(t == s)
49
50 for n1s in ['172.18.44.0/23','172.18.45.6/32','172.18.45.0/24']:
51     n1=ip_network(n1s)
52     print(n1)
53     print(s.contains(n1))
54     print(t.contains(n1))
55
56 n=s.networks()[0]
57
58 a=ipaddrset.complete_set()
59 print('a =', a)
60 print(a >= s)
61 print(a >= t)
62
63 print('^')
64 print(s.intersection(t))
65 print(t.intersection(s))
66
67 print('u')
68 print(s.union(t))
69 print(t.union(s))