comparison frontends/src/tools/jid.py @ 1139:75025461141f

move sat.tools.jid to sat_frontends.tools.jid
author souliane <souliane@mailoo.org>
date Tue, 26 Aug 2014 12:52:46 +0200
parents src/tools/jid.py@4ab93557976e
children 7f32371568e4
comparison
equal deleted inserted replaced
1138:a7cdf03c00e9 1139:75025461141f
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # SAT: a jabber client
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org)
6
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
16
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20
21 class JID(unicode):
22 """This class help manage JID (Node@Domaine/Resource)"""
23
24 def __new__(cls, jid):
25 self = unicode.__new__(cls, jid)
26 self.__parse()
27 return self
28
29 def __parse(self):
30 """find node domain and resource"""
31 node_end = self.find('@')
32 if node_end < 0:
33 node_end = 0
34 domain_end = self.find('/')
35 if domain_end < 1:
36 domain_end = len(self)
37 self.node = self[:node_end]
38 self.domain = self[(node_end + 1) if node_end else 0:domain_end]
39 self.resource = self[domain_end + 1:]
40 if not node_end:
41 self.bare = self
42 else:
43 self.bare = self.node + '@' + self.domain
44
45 def is_valid(self):
46 """return True if the jid is xmpp compliant"""
47 #TODO: implement real check, according to RFCs
48 return self.domain != ""