changeset 558:b38629924602

browser_side: using property setters is explicitely NOT recommended
author souliane <souliane@mailoo.org>
date Tue, 23 Sep 2014 11:48:57 +0200
parents d0114855d6d4
children 77372641e05d
files src/browser/sat_browser/jid.py
diffstat 1 files changed, 28 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/src/browser/sat_browser/jid.py	Tue Sep 23 10:53:52 2014 +0200
+++ b/src/browser/sat_browser/jid.py	Tue Sep 23 11:48:57 2014 +0200
@@ -42,29 +42,40 @@
         tokens[0] = tokens[0].lower()  # force node and domain to lower-case
         return '/'.join(tokens)
 
-    # XXX: I defined node, domain and resource as properties here, and renamed
-    # the class attributes with the '__' prefix, but it appeared that the setter
-    # methods were not called! Maybe pyjamas doesn't handle them well.
-    def setNode(self, node):
-        self.node = node
-        self.__build()
+    @property
+    def node(self):
+        return self.__node
 
-    def setDomain(self, domain):
-        self.domain = domain
-        self.__build()
+    @property
+    def domain(self):
+        return self.__domain
 
-    def setResource(self, resource):
-        self.resource = resource
-        self.__build()
+    @property
+    def resource(self):
+        return self.__resource
 
     @property
     def bare(self):
         return self.domain if not self.node else (self.node + "@" + self.domain)
 
-    @bare.setter
-    def bare(self, bare):
+    # XXX: Avoid property setters, Pyjamas doesn't seem to handle them well. It seems
+    # that it will just naively assign the value without actually calling the method.
+    # FIXME: find a way to raise an error if the (undefined!) setter is called.
+    def setNode(self, node):
+        self.__node = node
+        self.__build()
+
+    def setDomain(self, domain):
+        self.__domain = domain
+        self.__build()
+
+    def setResource(self, resource):
+        self.__resource = resource
+        self.__build()
+
+    def setBare(self, bare):
         self.__parseBare(bare)
-        self.build()
+        self.__build()
 
     def __build(self):
         """Build the JID string from the node, domain and resource"""
@@ -73,7 +84,7 @@
     def __parse(self):
         """Parse the JID string to extract the node, domain and resource"""
         tokens = self.__raw.split('/')
-        bare, self.resource = (tokens[0], tokens[1]) if len(tokens) > 1 else (self.__raw, '')
+        bare, self.__resource = (tokens[0], tokens[1]) if len(tokens) > 1 else (self.__raw, '')
         self.__parseBare(bare)
 
     def __parseBare(self, bare):
@@ -82,7 +93,7 @@
         @param bare (str): JID bare to parse
         """
         tokens = bare.split('@')
-        self.node, self.domain = (tokens[0], tokens[1]) if len(tokens) > 1 else ('', bare)
+        self.__node, self.__domain = (tokens[0], tokens[1]) if len(tokens) > 1 else ('', bare)
 
     def __str__(self):
         try: