From 0443149ef8c197a9e6b5aeeb7e9ede58503796f5 Mon Sep 17 00:00:00 2001 From: souliane Date: Tue, 26 Aug 2014 13:33:12 +0200 Subject: [PATCH] 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 --- frontends/src/tools/jid.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) 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 != ""