changeset 1311:4895e1e092fb frontends_multi_profiles

frontends (tools): Pyjamas's JID implementation can be compared to an object of a different type: - always return False if the other object is not a JID - to not fake list membership's test, hash(jid) now differs from hash(unicode(jid))
author souliane <souliane@mailoo.org>
date Sat, 07 Feb 2015 14:47:23 +0100
parents 9ca93ecdeea5
children 9e904f8a094e
files frontends/src/tools/jid.py
diffstat 1 files changed, 4 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/tools/jid.py	Fri Feb 06 22:28:00 2015 +0100
+++ b/frontends/src/tools/jid.py	Sat Feb 07 14:47:23 2015 +0100
@@ -58,12 +58,14 @@
             return getattr(self.__internal_str, name)
 
         def __eq__(self, other):
+            if not isinstance(other, JID):
+                return False
             return (self.node == other.node
                     and self.domain == other.domain
                     and self.resource == other.resource)
 
         def __hash__(self):
-            return hash(self.__internal_str)
+            return hash('JID<{}>'.format(self.__internal_str))
 
         def find(self, *args):
             return self.__internal_str.find(*args)
@@ -75,7 +77,7 @@
                 node_end = 0
             domain_end = self.__internal_str.find('/')
             if domain_end == 0:
-               raise ValueError("a jid can't start with '/'")
+                raise ValueError("a jid can't start with '/'")
             if domain_end == -1:
                 domain_end = len(self.__internal_str)
             self.node = self.__internal_str[:node_end] or None