diff 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
line wrap: on
line diff
--- a/frontends/src/tools/jid.py	Fri Mar 20 16:25:38 2015 +0100
+++ b/frontends/src/tools/jid.py	Fri Mar 20 16:28:19 2015 +0100
@@ -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 @@
                 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 @@
         """
         # 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))