chiark
/
gitweb
/
~ianmdlvl
/
secnet.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
test-example: Use subdirmk's new &:macro feature
[secnet.git]
/
ipaddrset.py
diff --git
a/ipaddrset.py
b/ipaddrset.py
index 54869580840aa4fa9d53fbbd27164cbaa98f9cd7..38d45711f3735a93958725aa50fb9e338c9f7b13 100644
(file)
--- a/
ipaddrset.py
+++ b/
ipaddrset.py
@@
-1,4
+1,4
@@
-"""IP address set manipulation, built on top of ipaddr.py"""
+"""IP address set manipulation, built on top of ipaddr
ess
.py"""
# This file is Free Software. It was originally written for secnet.
#
# 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.
# along with this software; if not, see
# https://www.gnu.org/licenses/gpl.html.
-import ipaddr
+import ipaddr
ess
_vsns = [6,4]
_vsns = [6,4]
@@
-35,7
+35,7
@@
class IPAddressSet:
# constructors
def __init__(self,l=[]):
# constructors
def __init__(self,l=[]):
- "New set contains each
ipaddr.IP
Network in the sequence l"
+ "New set contains each
IP*
Network in the sequence l"
self._v = {}
for v in _vsns:
self._v[v] = [ ]
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:
# 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="-"):
def __repr__(self):
return "IPAddressSet(%s)" % self.networks()
def str(self,comma=",",none="-"):
@@
-58,21
+59,22
@@
class IPAddressSet:
# mutators
def append(self,l):
# mutators
def append(self,l):
- "Appends each
ipaddr.IP
Network 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):
self._append(l)
self._compact()
def _append(self,l):
- "Appends each
ipaddr.IP
Network 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)
# enquirers including standard comparisons
for a in l:
self._v[a.version].append(a)
# enquirers including standard comparisons
- def __
nonzero
__(self):
+ def __
bool
__(self):
for v in _vsns:
if self._v[v]:
return True
return False
for v in _vsns:
if self._v[v]:
return True
return False
+ __nonzero__=__bool__ # for python2
def __eq__(self,other):
for v in _vsns:
def __eq__(self,other):
for v in _vsns:
@@
-142,7
+144,7
@@
class IPAddressSet:
except KeyError:
v = None
if v:
except KeyError:
v = None
if v:
- return self._contains_net(ipaddr
.IPN
etwork(thing))
+ return self._contains_net(ipaddr
ess.ip_n
etwork(thing))
else:
return self.__ge__(thing)
else:
return self.__ge__(thing)
@@
-150,7
+152,9
@@
def complete_set():
"Returns a set containing all addresses"
s=IPAddressSet()
for v in _vsns:
"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
s.append([n])
return s