aboutsummaryrefslogtreecommitdiff
path: root/scripts/Old/resource-set.py
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2007-12-24 06:36:18 +0000
committerRob Austein <sra@hactrn.net>2007-12-24 06:36:18 +0000
commite62cfb013638b5e68218c0702e88c6c4dfeb06f9 (patch)
tree93b5b864915a92a03e805062cf3b5b6d7f8b1e27 /scripts/Old/resource-set.py
parent6923ec5709af6f4fa5ea8e6e9af9265f5b9e213f (diff)
Cleanup
svn path=/scripts/Old/check-hashes.sh; revision=1434
Diffstat (limited to 'scripts/Old/resource-set.py')
-rw-r--r--scripts/Old/resource-set.py83
1 files changed, 83 insertions, 0 deletions
diff --git a/scripts/Old/resource-set.py b/scripts/Old/resource-set.py
new file mode 100644
index 00000000..fe0da8d3
--- /dev/null
+++ b/scripts/Old/resource-set.py
@@ -0,0 +1,83 @@
+# $Id$
+
+import socket
+import re
+
+class ip_address(object):
+
+ def __init__(self, text):
+ self.addr = socket.inet_pton(self.af, text)
+
+ def __str__(self):
+ return socket.inet_ntop(self.af, self.addr)
+
+ def __eq__(self, other):
+ return self.addr == other.addr
+
+ def __hash__(self):
+ return self.addr.__hash__()
+
+class ipv4_address(ip_address):
+ af = socket.AF_INET
+
+class ipv6_address(ip_address):
+ af = socket.AF_INET6
+
+class resource(object):
+ pass
+
+class asn(resource, long):
+ pass
+
+class ip_prefix(resource):
+
+ def __init__(self, addr, prefixlen):
+ self.addr = self.ac(addr)
+ self.prefixlen = prefixlen
+
+ def __str__(self):
+ return str(self.addr) + "/" + str(self.prefixlen)
+
+ def __eq__(self, other):
+ return self.addr == other.addr and self.prefixlen == other.prefixlen
+
+ def __hash__(self):
+ return self.addr.__hash__() + self.prefixlen.__hash__()
+
+class ipv4_prefix(ip_prefix):
+ ac = ipv4_address
+
+class ipv6_prefix(ip_prefix):
+ ac = ipv6_address
+
+class resource_range(resource):
+
+ def __init__(self, min, max):
+ assert isinstance(min, resource) and isinstance(max, resource)
+ self.min = min
+ self.max = max
+
+ def __str__(self):
+ return str(self.min) + "-" + str(self.max)
+
+ def __eq__(self, other):
+ return self.min == other.min and self.max == other.max
+
+ def __hash__(self):
+ return self.min.__hash__() + self.max.__hash__()
+
+class resource_set(set):
+
+ def __init__(self, *elts):
+ for e in elts:
+ assert isinstance(e, resource)
+ set.__init__(self, elts)
+
+ def __str__(self):
+ s = [i for i in self]
+ s.sort()
+ return "{" + ", ".join(map(str, s)) + "}"
+
+s = resource_set(ipv6_prefix("fe80::", 16), ipv4_prefix("10.0.0.44", 32), ipv4_prefix("10.3.0.44", 32))
+
+print s