comparison frontends/src/tools/jid.py @ 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 faa1129559b8
children 3dae6964c071
comparison
equal deleted inserted replaced
1310:9ca93ecdeea5 1311:4895e1e092fb
56 56
57 def __getattr__(self, name): 57 def __getattr__(self, name):
58 return getattr(self.__internal_str, name) 58 return getattr(self.__internal_str, name)
59 59
60 def __eq__(self, other): 60 def __eq__(self, other):
61 if not isinstance(other, JID):
62 return False
61 return (self.node == other.node 63 return (self.node == other.node
62 and self.domain == other.domain 64 and self.domain == other.domain
63 and self.resource == other.resource) 65 and self.resource == other.resource)
64 66
65 def __hash__(self): 67 def __hash__(self):
66 return hash(self.__internal_str) 68 return hash('JID<{}>'.format(self.__internal_str))
67 69
68 def find(self, *args): 70 def find(self, *args):
69 return self.__internal_str.find(*args) 71 return self.__internal_str.find(*args)
70 72
71 def _parse(self): 73 def _parse(self):
73 node_end = self.__internal_str.find('@') 75 node_end = self.__internal_str.find('@')
74 if node_end < 0: 76 if node_end < 0:
75 node_end = 0 77 node_end = 0
76 domain_end = self.__internal_str.find('/') 78 domain_end = self.__internal_str.find('/')
77 if domain_end == 0: 79 if domain_end == 0:
78 raise ValueError("a jid can't start with '/'") 80 raise ValueError("a jid can't start with '/'")
79 if domain_end == -1: 81 if domain_end == -1:
80 domain_end = len(self.__internal_str) 82 domain_end = len(self.__internal_str)
81 self.node = self.__internal_str[:node_end] or None 83 self.node = self.__internal_str[:node_end] or None
82 self.domain = self.__internal_str[(node_end + 1) if node_end else 0:domain_end] 84 self.domain = self.__internal_str[(node_end + 1) if node_end else 0:domain_end]
83 self.resource = self.__internal_str[domain_end + 1:] or None 85 self.resource = self.__internal_str[domain_end + 1:] or None