diff options
author | Lance Stout <lancestout@gmail.com> | 2012-01-17 23:03:48 -0800 |
---|---|---|
committer | Lance Stout <lancestout@gmail.com> | 2012-01-17 23:03:48 -0800 |
commit | 86d8736dccd698b55ab9ddffe57326bad8851319 (patch) | |
tree | cc4043733c96d486d8811987c85151a842bb203b /sleekxmpp/xmlstream/jid.py | |
parent | 2923f5656150448e10f6f3a58a63470a987d47e1 (diff) | |
download | slixmpp-86d8736dccd698b55ab9ddffe57326bad8851319.tar.gz slixmpp-86d8736dccd698b55ab9ddffe57326bad8851319.tar.bz2 slixmpp-86d8736dccd698b55ab9ddffe57326bad8851319.tar.xz slixmpp-86d8736dccd698b55ab9ddffe57326bad8851319.zip |
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!!'
Diffstat (limited to 'sleekxmpp/xmlstream/jid.py')
-rw-r--r-- | sleekxmpp/xmlstream/jid.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/sleekxmpp/xmlstream/jid.py b/sleekxmpp/xmlstream/jid.py index c91c8fb3..281bf4ee 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) |