On 9 Dec 2010, at 22:12, Casey Deccio wrote:

> On Thu, Dec 9, 2010 at 4:22 PM, Casey Deccio <[email protected]> wrote:
> 
> Sorry for the self-reply, but I just found my answer.  The __hash__()
> method is used for operations on members of hashed collections, like
> dict [1].  The default for new-style classes is to use id(), which is
> why my tests are failing.
> 
> For now I can subclass and define my own hash of the rdata.

Try the patch below for the hash.  It should result in equal rdatas having 
equal hashes, and works even if the rdatas have relativized names.  I'm not 
inclined to add hash support to rdatasets or rrsets as they are not nominally 
immutable.

/Bob


diff --git a/dns/rdata.py b/dns/rdata.py
index ce02686..399677e 100644
--- a/dns/rdata.py
+++ b/dns/rdata.py
@@ -28,6 +28,7 @@ chunk of hexstring that _hexify() produces before whitespace 
occurs.
 import cStringIO
 
 import dns.exception
+import dns.name
 import dns.rdataclass
 import dns.rdatatype
 import dns.tokenizer
@@ -252,6 +253,9 @@ class Rdata(object):
             return NotImplemented
         return self._cmp(other) > 0
 
+    def __hash__(self):
+        return hash(self.to_digestable(dns.name.root))
+
     def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
         """Build an rdata object from text format.
 

_______________________________________________
dnspython-users mailing list
[email protected]
http://howl.play-bow.org/mailman/listinfo.cgi/dnspython-users

Reply via email to