]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
implement more of the sequence protocol in Answer
authorBob Halley <halley@dnspython.org>
Thu, 20 Jul 2006 21:59:20 +0000 (21:59 +0000)
committerBob Halley <halley@dnspython.org>
Thu, 20 Jul 2006 21:59:20 +0000 (21:59 +0000)
ChangeLog
dns/resolver.py

index 3d011320d8315cdd832babb5def7b86bee835448..86ed2773ae1b0245cc67e4df6908755122888fa6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2006-07-20  Bob Halley  <halley@dnspython.org>
+
+       * dns/resolver.py (Answer): Add more support for the sequence
+         protocol, forwarding requests to the answer object's rrset.
+         E.g. "for a in answer" is equivalent to "for a in answer.rrset",
+         "answer[i]" is equivalent to "answer.rrset[i]", and
+         "answer[i:j]" is equivalent to "answer.rrset[i:j]".
+
 2006-07-19  Bob Halley  <halley@dnspython.org>
 
        * dns/query.py (xfr): Add IXFR support.
index 0b4013f9e3dafe8b081d6aa702d15f55901a7982..9e8339aa85d2daf080f0cd915a4ed23f9fd434bb 100644 (file)
@@ -68,8 +68,11 @@ class Answer(object):
     Instances of this class bundle up the result of a successful DNS
     resolution.
 
-    For convenience, the answer is iterable.  "for a in answer" is
-    equivalent to "for a in answer.rrset".
+    For convenience, the answer object implements much of the sequence
+    protocol, forwarding to its rrset.  E.g. "for a in answer" is
+    equivalent to "for a in answer.rrset", "answer[i]" is equivalent
+    to "answer.rrset[i]", and "answer[i:j]" is equivalent to
+    "answer.rrset[i:j]".
 
     Note that CNAMEs or DNAMEs in the response may mean that answer
     node's name might not be the query name.
@@ -142,6 +145,18 @@ class Answer(object):
     def __iter__(self):
         return iter(self.rrset)
 
+    def __getitem__(self, i):
+        return self.rrset[i]
+
+    def __delitem__(self, i):
+        del self.rrset[i]
+
+    def __getslice__(self, i, j):
+        return self.rrset[i:j]
+
+    def __delslice__(self, i, j):
+        del self.rrset[i:j]
+
 class Cache(object):
     """Simple DNS answer cache.