diff --git a/frontends/src/tools/jid.py b/frontends/src/tools/jid.py index a9384c12..cd6e8344 100644 --- a/frontends/src/tools/jid.py +++ b/frontends/src/tools/jid.py @@ -22,12 +22,21 @@ class JID(unicode): """This class help manage JID (Node@Domaine/Resource)""" def __new__(cls, jid): - self = unicode.__new__(cls, jid) + self = unicode.__new__(cls, cls.__normalize(jid)) self.__parse() return self + @classmethod + def __normalize(cls, jid): + """Naive normalization before instantiating and parsing the JID""" + if not jid: + return jid + tokens = jid.split('/') + tokens[0] = tokens[0].lower() # force node and domain to lower-case + return '/'.join(tokens) + def __parse(self): - """find node domain and resource""" + """Find node domain and resource""" node_end = self.find('@') if node_end < 0: node_end = 0 @@ -43,6 +52,8 @@ class JID(unicode): self.bare = self.node + '@' + self.domain def is_valid(self): - """return True if the jid is xmpp compliant""" - #TODO: implement real check, according to RFCs + """ + @return: True if the JID is XMPP compliant + """ + # TODO: implement real check, according to the RFC http://tools.ietf.org/html/rfc6122 return self.domain != ""