changeset 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 7fcafc3206b1
files frontends/src/tools/jid.py
diffstat 1 files changed, 15 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/tools/jid.py	Tue Aug 26 12:52:46 2014 +0200
+++ b/frontends/src/tools/jid.py	Tue Aug 26 13:33:12 2014 +0200
@@ -22,12 +22,21 @@
     """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 @@
             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 != ""