comparison frontends/src/tools/jid.py @ 1140:7f32371568e4

sat_frontends (tools): force JID's node and domain to lower-case: - this changeset should go with a modification of PRIVATE_PREFIX, but the change has been already (accidentally) pushed with the previous changeset
author souliane <souliane@mailoo.org>
date Tue, 26 Aug 2014 13:33:12 +0200
parents 75025461141f
children e3a9ea76de35
comparison
equal deleted inserted replaced
1139:75025461141f 1140:7f32371568e4
20 20
21 class JID(unicode): 21 class JID(unicode):
22 """This class help manage JID (Node@Domaine/Resource)""" 22 """This class help manage JID (Node@Domaine/Resource)"""
23 23
24 def __new__(cls, jid): 24 def __new__(cls, jid):
25 self = unicode.__new__(cls, jid) 25 self = unicode.__new__(cls, cls.__normalize(jid))
26 self.__parse() 26 self.__parse()
27 return self 27 return self
28 28
29 @classmethod
30 def __normalize(cls, jid):
31 """Naive normalization before instantiating and parsing the JID"""
32 if not jid:
33 return jid
34 tokens = jid.split('/')
35 tokens[0] = tokens[0].lower() # force node and domain to lower-case
36 return '/'.join(tokens)
37
29 def __parse(self): 38 def __parse(self):
30 """find node domain and resource""" 39 """Find node domain and resource"""
31 node_end = self.find('@') 40 node_end = self.find('@')
32 if node_end < 0: 41 if node_end < 0:
33 node_end = 0 42 node_end = 0
34 domain_end = self.find('/') 43 domain_end = self.find('/')
35 if domain_end < 1: 44 if domain_end < 1:
41 self.bare = self 50 self.bare = self
42 else: 51 else:
43 self.bare = self.node + '@' + self.domain 52 self.bare = self.node + '@' + self.domain
44 53
45 def is_valid(self): 54 def is_valid(self):
46 """return True if the jid is xmpp compliant""" 55 """
47 #TODO: implement real check, according to RFCs 56 @return: True if the JID is XMPP compliant
57 """
58 # TODO: implement real check, according to the RFC http://tools.ietf.org/html/rfc6122
48 return self.domain != "" 59 return self.domain != ""