quick_frontends, primitivus: move the chat states logic to quick_frontend

This commit is contained in:
souliane 2015-03-20 16:28:19 +01:00
commit 14f4b4b8ec

View file

@ -20,7 +20,7 @@
# hack to use this module with pyjamas
try:
unicode('') # XXX: unicode doesn't exist in pyjamas
unicode('') # XXX: unicode doesn't exist in pyjamas
# normal version
class BaseJID(unicode):
@ -38,14 +38,15 @@ try:
node_end = 0
domain_end = self.find('/')
if domain_end == 0:
raise ValueError("a jid can't start with '/'")
raise ValueError("a jid can't start with '/'")
if domain_end == -1:
domain_end = len(self)
self.node = self[:node_end] or None
self.domain = self[(node_end + 1) if node_end else 0:domain_end]
self.resource = self[domain_end + 1:] or None
except (TypeError, AttributeError): # Error raised is not the same depending on pyjsbuild options
except (TypeError, AttributeError): # Error raised is not the same depending on pyjsbuild options
# pyjamas version
class BaseJID(object):
def __init__(self, jid_str):
@ -113,3 +114,13 @@ class JID(BaseJID):
"""
# TODO: implement real check, according to the RFC http://tools.ietf.org/html/rfc6122
return self.domain != ""
def newResource(entity, resource):
"""Build a new JID from the given entity and resource.
@param entity (JID): original JID
@param resource (unicode): new resource
@return: a new JID instance
"""
return JID(u"%s/%s" % (entity.bare, resource))