From: Bob Halley Date: Thu, 20 Jul 2006 21:59:20 +0000 (+0000) Subject: implement more of the sequence protocol in Answer X-Git-Tag: v1.5.0~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=695199c0ec2395fc761b6ccc6e74b87323041958;p=thirdparty%2Fdnspython.git implement more of the sequence protocol in Answer --- diff --git a/ChangeLog b/ChangeLog index 3d011320..86ed2773 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2006-07-20 Bob Halley + + * 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 * dns/query.py (xfr): Add IXFR support. diff --git a/dns/resolver.py b/dns/resolver.py index 0b4013f9..9e8339aa 100644 --- a/dns/resolver.py +++ b/dns/resolver.py @@ -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.