Commits

jviide-work  committed 562bd06

idiokit.xmpp.muc: Published method xmpp.muc.get_full_room_jid for determining a fully qualified XMPP room name without joining it.

  • Participants
  • Parent commits 403655e

Comments (0)

Files changed (1)

File idiokit/xmpp/muc.py

 OWNER_NS = MUC_NS + "#owner"
 ROOMS_NODE = "http://jabber.org/protocol/muc#rooms"
 
+
 class MUCError(XMPPError):
     pass
 
+
 def gen_random(length=8):
     return "".join(random.choice(string.digits) for _ in xrange(length))
 
+
 def parse_presence(elements, own_jid):
     presences = elements.named("presence", STANZA_NS)
 
             return participant, codes
     return None
 
+
 @idiokit.stream
 def join_room(jid, xmpp, output, password=None, history=False):
     participants = list()
         if participant.name == jid or "110" in codes:
             idiokit.stop(participant.name, participants)
 
+
 class MUCRoom(idiokit.Proxy):
     def __init__(self, jid, muc, output, participants):
         self.jid = JID(jid)
         finally:
             self._muc._exit_room(self)
 
+
 class MUCParticipant(object):
     def __init__(self, name, affiliation, role, payload, jid=None):
         self.name = name
         self.jid = jid
         self.payload = payload
 
+
 class MUC(object):
     def __init__(self, xmpp):
         self.xmpp = xmpp
     @idiokit.stream
     def _test_muc(self, domain):
         info = yield self.xmpp.disco.info(domain)
-        if MUC_NS not in info.features:
-            raise MUCError("%r is not a multi-user chat service" % domain)
-
-        for identity in info.identities:
-            if identity.category == "conference" and identity.type == "text":
-                idiokit.stop(domain)
-
-        raise MUCError("%r is not a multi-user chat service" % domain)
+        if MUC_NS in info.features:
+            for identity in info.identities:
+                if identity.category == "conference" and identity.type == "text":
+                    idiokit.stop(domain)
+        raise MUCError("{0!r} is not a multi-user chat service".format(domain))
 
     @idiokit.stream
     def _resolve_muc(self):
         idiokit.stop(domain)
 
     @idiokit.stream
-    def _full_room_jid(self, room):
+    def get_full_room_jid(self, room):
         if "@" in unicode(room):
             jid = JID(room)
             if jid.resource is not None:
 
     @idiokit.stream
     def join(self, room, nick=None, password=None, history=False):
-        jid = yield self._full_room_jid(room)
+        jid = yield self.get_full_room_jid(room)
         if nick is None:
             nick = self.xmpp.jid.node
         jid = JID(jid.node, jid.domain, nick)
         try:
             while True:
                 try:
-                    jid, participants = yield join_room(jid,
-                                                        self.xmpp, output,
-                                                        password, history)
+                    jid, participants = yield join_room(jid, self.xmpp, output, password, history)
                 except MUCError as me:
                     if (me.type, me.condition) != ("cancel", "conflict"):
                         raise
-                    jid = JID(jid.node, jid.domain, nick+"-"+gen_random())
+                    jid = JID(jid.node, jid.domain, nick + "-" + gen_random())
                 else:
                     break
         except: