aboutsummaryrefslogtreecommitdiff
path: root/portal-gui/rpkigui/myrpki/asnset.py
diff options
context:
space:
mode:
Diffstat (limited to 'portal-gui/rpkigui/myrpki/asnset.py')
-rw-r--r--portal-gui/rpkigui/myrpki/asnset.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/portal-gui/rpkigui/myrpki/asnset.py b/portal-gui/rpkigui/myrpki/asnset.py
new file mode 100644
index 00000000..2fa52450
--- /dev/null
+++ b/portal-gui/rpkigui/myrpki/asnset.py
@@ -0,0 +1,23 @@
+class asnset(object):
+ """a set-like objet for containing sets of ASN values."""
+ v = set()
+
+ def __init__(self, init=None):
+ """
+ May be initialized from a comma separated list of positive integers.
+ """
+ if init:
+ self.v = set(int(x) for x in init.split(',') if x.strip() != '')
+ if any([x for x in self.v if x < 0]):
+ raise ValueError, "can't contain negative values."
+
+ def __str__(self):
+ return ','.join(str(x) for x in sorted(self.v))
+
+ def __iter__(self):
+ return iter(self.v)
+
+ def add(self, n):
+ assert isinstance(n, int)
+ assert n > 0
+ self.v.add(n)