]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
add get/del item/slice
authorBob Halley <halley@dnspython.org>
Fri, 2 Sep 2005 05:32:59 +0000 (05:32 +0000)
committerBob Halley <halley@dnspython.org>
Fri, 2 Sep 2005 05:32:59 +0000 (05:32 +0000)
Original author: Bob Halley <halley@dnspython.org>
Date: 2005-05-06 23:39:25

dns/set.py
tests/set.py

index a5dd966c9a9e6ac936afc621f74062b8b2f8511e..6a2363c23f21bc30caa8987df3348e6c22cdc573 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2003-2005 Nominum, Inc.
+# Copyright (C) 2003, 2004 Nominum, Inc.
 #
 # Permission to use, copy, modify, and distribute this software and its
 # documentation for any purpose with or without fee is hereby granted,
@@ -224,6 +224,18 @@ class Set(object):
     def __iter__(self):
         return iter(self.items)
 
+    def __getitem__(self, i):
+        return self.items[i]
+
+    def __delitem__(self, i):
+        del self.items[i]
+
+    def __getslice__(self, i, j):
+        return self.items[i:j]
+
+    def __delslice__(self, i, j):
+        del self.items[i:j]
+
     def issubset(self, other):
         """Is I{self} a subset of I{other}?
 
index e2dd9b0b1c53e9c7ea7bfbaa21c69d7acee750c3..af55399348e4dea06ed23a2cac25101096e0ee43 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2003-2005 Nominum, Inc.
+# Copyright (C) 2003, 2004 Nominum, Inc.
 #
 # Permission to use, copy, modify, and distribute this software and its
 # documentation for any purpose with or without fee is hereby granted,
@@ -172,5 +172,37 @@ class SimpleSetTestCase(unittest.TestCase):
         s1.update(u)
         self.failUnless(s1 == e)
 
+    def testGetitem(self):
+        s1 = S([1, 2, 3])
+        i0 = s1[0]
+        i1 = s1[1]
+        i2 = s1[2]
+        s2 = S([i0, i1, i2])
+        self.failUnless(s1 == s2)
+
+    def testGetslice(self):
+        s1 = S([1, 2, 3])
+        slice = s1[0:2]
+        self.failUnless(len(slice) == 2)
+        item = s1[2]
+        slice.append(item)
+        s2 = S(slice)
+        self.failUnless(s1 == s2)
+
+    def testDelitem(self):
+        s1 = S([1, 2, 3])
+        del s1[0]
+        i1 = s1[0]
+        i2 = s1[1]
+        self.failUnless(i1 != i2)
+        self.failUnless(i1 == 1 or i1 == 2 or i1 == 3)
+        self.failUnless(i2 == 1 or i2 == 2 or i2 == 3)
+
+    def testDelslice(self):
+        s1 = S([1, 2, 3])
+        del s1[0:2]
+        i1 = s1[0]
+        self.failUnless(i1 == 1 or i1 == 2 or i1 == 3)
+
 if __name__ == '__main__':
     unittest.main()