comparison src/browser/sat_browser/jid.py @ 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 138336986bd0
children f8a355bede6a
comparison
equal deleted inserted replaced
557:d0114855d6d4 558:b38629924602
40 return jid 40 return jid
41 tokens = jid.split('/') 41 tokens = jid.split('/')
42 tokens[0] = tokens[0].lower() # force node and domain to lower-case 42 tokens[0] = tokens[0].lower() # force node and domain to lower-case
43 return '/'.join(tokens) 43 return '/'.join(tokens)
44 44
45 # XXX: I defined node, domain and resource as properties here, and renamed 45 @property
46 # the class attributes with the '__' prefix, but it appeared that the setter 46 def node(self):
47 # methods were not called! Maybe pyjamas doesn't handle them well. 47 return self.__node
48 def setNode(self, node):
49 self.node = node
50 self.__build()
51 48
52 def setDomain(self, domain): 49 @property
53 self.domain = domain 50 def domain(self):
54 self.__build() 51 return self.__domain
55 52
56 def setResource(self, resource): 53 @property
57 self.resource = resource 54 def resource(self):
58 self.__build() 55 return self.__resource
59 56
60 @property 57 @property
61 def bare(self): 58 def bare(self):
62 return self.domain if not self.node else (self.node + "@" + self.domain) 59 return self.domain if not self.node else (self.node + "@" + self.domain)
63 60
64 @bare.setter 61 # XXX: Avoid property setters, Pyjamas doesn't seem to handle them well. It seems
65 def bare(self, bare): 62 # that it will just naively assign the value without actually calling the method.
63 # FIXME: find a way to raise an error if the (undefined!) setter is called.
64 def setNode(self, node):
65 self.__node = node
66 self.__build()
67
68 def setDomain(self, domain):
69 self.__domain = domain
70 self.__build()
71
72 def setResource(self, resource):
73 self.__resource = resource
74 self.__build()
75
76 def setBare(self, bare):
66 self.__parseBare(bare) 77 self.__parseBare(bare)
67 self.build() 78 self.__build()
68 79
69 def __build(self): 80 def __build(self):
70 """Build the JID string from the node, domain and resource""" 81 """Build the JID string from the node, domain and resource"""
71 self.__raw = self.bare if not self.resource else (self.bare + '/' + self.resource) 82 self.__raw = self.bare if not self.resource else (self.bare + '/' + self.resource)
72 83
73 def __parse(self): 84 def __parse(self):
74 """Parse the JID string to extract the node, domain and resource""" 85 """Parse the JID string to extract the node, domain and resource"""
75 tokens = self.__raw.split('/') 86 tokens = self.__raw.split('/')
76 bare, self.resource = (tokens[0], tokens[1]) if len(tokens) > 1 else (self.__raw, '') 87 bare, self.__resource = (tokens[0], tokens[1]) if len(tokens) > 1 else (self.__raw, '')
77 self.__parseBare(bare) 88 self.__parseBare(bare)
78 89
79 def __parseBare(self, bare): 90 def __parseBare(self, bare):
80 """Parse the given JID bare to extract the node and domain 91 """Parse the given JID bare to extract the node and domain
81 92
82 @param bare (str): JID bare to parse 93 @param bare (str): JID bare to parse
83 """ 94 """
84 tokens = bare.split('@') 95 tokens = bare.split('@')
85 self.node, self.domain = (tokens[0], tokens[1]) if len(tokens) > 1 else ('', bare) 96 self.__node, self.__domain = (tokens[0], tokens[1]) if len(tokens) > 1 else ('', bare)
86 97
87 def __str__(self): 98 def __str__(self):
88 try: 99 try:
89 return self.__raw 100 return self.__raw
90 except AttributeError: 101 except AttributeError: