Mercurial > libervia-backend
comparison frontends/src/tools/jid.py @ 1378:3dae6964c071
quick_frontends, primitivus: move the chat states logic to quick_frontend
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 20 Mar 2015 16:28:19 +0100 |
parents | 4895e1e092fb |
children | 069ad98b360d |
comparison
equal
deleted
inserted
replaced
1377:017270e6eea4 | 1378:3dae6964c071 |
---|---|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 | 20 |
21 # hack to use this module with pyjamas | 21 # hack to use this module with pyjamas |
22 try: | 22 try: |
23 unicode('') # XXX: unicode doesn't exist in pyjamas | 23 unicode('') # XXX: unicode doesn't exist in pyjamas |
24 | 24 |
25 # normal version | 25 # normal version |
26 class BaseJID(unicode): | 26 class BaseJID(unicode): |
27 def __new__(cls, jid_str): | 27 def __new__(cls, jid_str): |
28 self = unicode.__new__(cls, cls._normalize(jid_str)) | 28 self = unicode.__new__(cls, cls._normalize(jid_str)) |
36 node_end = self.find('@') | 36 node_end = self.find('@') |
37 if node_end < 0: | 37 if node_end < 0: |
38 node_end = 0 | 38 node_end = 0 |
39 domain_end = self.find('/') | 39 domain_end = self.find('/') |
40 if domain_end == 0: | 40 if domain_end == 0: |
41 raise ValueError("a jid can't start with '/'") | 41 raise ValueError("a jid can't start with '/'") |
42 if domain_end == -1: | 42 if domain_end == -1: |
43 domain_end = len(self) | 43 domain_end = len(self) |
44 self.node = self[:node_end] or None | 44 self.node = self[:node_end] or None |
45 self.domain = self[(node_end + 1) if node_end else 0:domain_end] | 45 self.domain = self[(node_end + 1) if node_end else 0:domain_end] |
46 self.resource = self[domain_end + 1:] or None | 46 self.resource = self[domain_end + 1:] or None |
47 | 47 |
48 except (TypeError, AttributeError): # Error raised is not the same depending on pyjsbuild options | 48 except (TypeError, AttributeError): # Error raised is not the same depending on pyjsbuild options |
49 | |
49 # pyjamas version | 50 # pyjamas version |
50 class BaseJID(object): | 51 class BaseJID(object): |
51 def __init__(self, jid_str): | 52 def __init__(self, jid_str): |
52 self.__internal_str = JID._normalize(jid_str) | 53 self.__internal_str = JID._normalize(jid_str) |
53 | 54 |
111 """ | 112 """ |
112 @return: True if the JID is XMPP compliant | 113 @return: True if the JID is XMPP compliant |
113 """ | 114 """ |
114 # TODO: implement real check, according to the RFC http://tools.ietf.org/html/rfc6122 | 115 # TODO: implement real check, according to the RFC http://tools.ietf.org/html/rfc6122 |
115 return self.domain != "" | 116 return self.domain != "" |
117 | |
118 | |
119 def newResource(entity, resource): | |
120 """Build a new JID from the given entity and resource. | |
121 | |
122 @param entity (JID): original JID | |
123 @param resource (unicode): new resource | |
124 @return: a new JID instance | |
125 """ | |
126 return JID(u"%s/%s" % (entity.bare, resource)) |