def __init__(self, service, *path, **conf): self.__dict__["service"] = service self.__dict__["path"] = tuple(path) for key, value in conf.items(): try: value = serialize.load(serialize.dump(value)) except serialize.UnregisteredType: raise SessionError("can not serialize key %r value %r" % (key, value)) conf[key] = value self.__dict__["_conf"] = frozenset(conf.items())
def _try_session(inner, self, service_id, *path, **conf): matches = list() for jid, service_ids in self.catalogue.items(): if service_id in service_ids: matches.append(jid) if matches: jid = random.choice(matches) else: channel = threado.Channel() self.waiters.setdefault(service_id, set()).add(channel) try: while not channel.was_source: jid = yield inner, channel finally: waiters = self.waiters.get(service_id, set()) waiters.discard(channel) if not waiters: self.waiters.pop(service_id, None) start = Element("start", xmlns=SERVICE_NS, id=service_id) if path: path_element = Element("path") path_element.add(serialize.dump(path)) start.add(path_element) conf_element = Element("config") conf_element.add(serialize.dump(conf)) start.add(conf_element) try: result = yield inner.sub(self.xmpp.core.iq_set(start, to=jid)) except XMPPError, error: if error.type != "cancel": raise inner.finish()