def testJIDaliases(self): """Test changing JID using aliases for domain.""" j = JID('user@someserver/resource') j.server = 'anotherserver' self.check_jid(j, domain='anotherserver') j.host = 'yetanother' self.check_jid(j, domain='yetanother')
def testJIDUnescape(self): jid = JID('here\\27s_a_wild_\\26_\\2fcr%zy\\2f_\\40ddress\\20for\\3a\\3cwv\\3e(\\22IMPS\\22)\\[email protected]') ujid = jid.unescape() self.assertEqual(ujid.local, 'here\'s_a_wild_&_/cr%zy/_@ddress for:<wv>("imps")\\') jid = JID('blah\\5cfoo\\[email protected]') ujid = jid.unescape() self.assertEqual(ujid.local, 'blah\\foo\\20bar')
def testJIDBareNoUser(self): """Test setting the bare JID without a user.""" j = JID('user@domain/resource') j.bare = 'otherdomain' self.check_jid(j, '', 'otherdomain', 'resource', 'otherdomain', 'otherdomain/resource', 'otherdomain/resource')
def testJIDSetFullWithUser(self): """Test setting the full JID with a user portion.""" j = JID('user@domain/resource') j.full = 'otheruser@otherdomain/otherresource' self.check_jid(j, 'otheruser', 'otherdomain', 'otherresource', 'otheruser@otherdomain', 'otheruser@otherdomain/otherresource', 'otheruser@otherdomain/otherresource')
def testJIDchange(self): """Test changing JID of the form 'user@server/resource/with/slashes'""" j = JID('user1@someserver1/some1/resource1') j.user = '******' j.domain = 'someserver' j.resource = 'some/resource' self.check_jid(j, 'user', 'someserver', 'some/resource', 'user@someserver', 'user@someserver/some/resource', 'user@someserver/some/resource')
def testJIDFullNoUserNoResource(self): """ Test setting the full JID without a user portion and without a resource. """ j = JID('user@domain/resource') j.full = 'otherdomain' self.check_jid(j, '', 'otherdomain', '', 'otherdomain', 'otherdomain', 'otherdomain')
def ack_message(self, msg_id: str, msg_jid: JID): if JID(msg_jid).bare == self.core.xmpp.boundjid.bare: msg_jid = JID(self.jid.bare) msg_jid.resource = self.own_nick super().ack_message(msg_id, msg_jid)
async def get_info(self, jid: OptJid = None, node: Optional[str] = None, local: Optional[bool] = None, cached: Optional[bool] = None, **kwargs) -> Iq: """ Retrieve the disco#info results from a given JID/node combination. Info may be retrieved from both local resources and remote agents; the local parameter indicates if the information should be gathered by executing the local node handlers, or if a disco#info stanza must be generated and sent. If requesting items from a local JID/node, then only a DiscoInfo stanza will be returned. Otherwise, an Iq stanza will be returned. .. versionchanged:: 1.8.0 This function is now a coroutine. :param jid: Request info from this JID. :param node: The particular node to query. :param local: If true, then the query is for a JID/node combination handled by this Slixmpp instance and no stanzas need to be sent. Otherwise, a disco stanza must be sent to the remote JID to retrieve the info. :param cached: If true, then look for the disco info data from the local cache system. If no results are found, send the query as usual. The self.use_cache setting must be set to true for this option to be useful. If set to false, then the cache will be skipped, even if a result has already been cached. Defaults to false. """ if local is None: if jid is not None and not isinstance(jid, JID): jid = JID(jid) if self.xmpp.is_component: if jid.domain == self.xmpp.boundjid.domain: local = True else: if str(jid) == str(self.xmpp.boundjid): local = True jid = jid.full elif jid in (None, ''): local = True ifrom = kwargs.pop('ifrom', None) if local: log.debug("Looking up local disco#info data " "for %s, node %s.", jid, node) info = await self.api['get_info'](jid, node, ifrom, kwargs) info = self._fix_default_info(info) return self._wrap(ifrom, jid, info) if cached: log.debug("Looking up cached disco#info data " "for %s, node %s.", jid, node) info = await self.api['get_cached_info'](jid, node, ifrom, kwargs) if info is not None: return self._wrap(ifrom, jid, info) iq = self.xmpp.Iq() # Check dfrom parameter for backwards compatibility iq['from'] = ifrom or kwargs.get('dfrom', '') iq['to'] = jid iq['type'] = 'get' iq['disco_info']['node'] = node if node else '' return await iq.send(**kwargs)
def get_activities(self) -> Iterable[JID]: return [JID(el.xml.text) for el in self if isinstance(el, Activity)]
async def publish_ok(self): for uid in self.bus._publish_futures.keys(): await self.bus._on_event({ 'id': uid, 'from': JID('test@localhost') })
def get_to(self): return JID(self._get_attr('from'))