From 86d8736dccd698b55ab9ddffe57326bad8851319 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Tue, 17 Jan 2012 23:03:48 -0800 Subject: [PATCH] Hash JIDs based on full JID string. This makes JID objects equivalent to strings in dictionaries, etc. >>> j = JID('foo@example.com') >>> s = 'foo@example.com' >>> d = {j: 'yay'} >>> d[j] 'yay' >>> d[s] 'yay' >>> d[s] = 'yay!!' >>> d[j] 'yay!!' --- sleekxmpp/xmlstream/jid.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sleekxmpp/xmlstream/jid.py b/sleekxmpp/xmlstream/jid.py index c91c8fb..281bf4e 100644 --- a/sleekxmpp/xmlstream/jid.py +++ b/sleekxmpp/xmlstream/jid.py @@ -139,3 +139,7 @@ class JID(object): def __ne__(self, other): """Two JIDs are considered unequal if they are not equal.""" return not self == other + + def __hash__(self): + """Hash a JID based on the string version of its full JID.""" + return hash(self.full)