comparison sat/plugins/plugin_xep_0050.py @ 3900:6c93a18b6250

plugin XEP-0050: use coroutine + minor code readability improvments: rel 372
author Goffi <goffi@goffi.org>
date Wed, 21 Sep 2022 22:33:59 +0200
parents fad3b3ffa8fe
children 524856bd7b19
comparison
equal deleted inserted replaced
3899:1e64f1ed3ebd 3900:6c93a18b6250
86 XMPPHandler.__init__(self) 86 XMPPHandler.__init__(self)
87 self.callback = callback 87 self.callback = callback
88 self.label = label 88 self.label = label
89 self.node = node 89 self.node = node
90 self.features = [disco.DiscoFeature(feature) for feature in features] 90 self.features = [disco.DiscoFeature(feature) for feature in features]
91 ( 91 self.allowed_jids = allowed_jids
92 self.allowed_jids, 92 self.allowed_groups = allowed_groups
93 self.allowed_groups, 93 self.allowed_magics = allowed_magics
94 self.allowed_magics, 94 self.forbidden_jids = forbidden_jids
95 self.forbidden_jids, 95 self.forbidden_groups = forbidden_groups
96 self.forbidden_groups,
97 ) = (
98 allowed_jids,
99 allowed_groups,
100 allowed_magics,
101 forbidden_jids,
102 forbidden_groups,
103 )
104 self.sessions = Sessions(timeout=timeout) 96 self.sessions = Sessions(timeout=timeout)
105 97
106 @property 98 @property
107 def client(self): 99 def client(self):
108 return self.parent 100 return self.parent
622 return (payload, status, None, note) 614 return (payload, status, None, note)
623 615
624 def _run(self, service_jid_s="", node="", profile_key=C.PROF_KEY_NONE): 616 def _run(self, service_jid_s="", node="", profile_key=C.PROF_KEY_NONE):
625 client = self.host.getClient(profile_key) 617 client = self.host.getClient(profile_key)
626 service_jid = jid.JID(service_jid_s) if service_jid_s else None 618 service_jid = jid.JID(service_jid_s) if service_jid_s else None
627 d = self.run(client, service_jid, node or None) 619 d = defer.ensureDeferred(self.run(client, service_jid, node or None))
628 d.addCallback(lambda xmlui: xmlui.toXml()) 620 d.addCallback(lambda xmlui: xmlui.toXml())
629 return d 621 return d
630 622
631 @defer.inlineCallbacks 623 async def run(self, client, service_jid=None, node=None):
632 def run(self, client, service_jid=None, node=None):
633 """Run an ad-hoc command 624 """Run an ad-hoc command
634 625
635 @param service_jid(jid.JID, None): jid of the ad-hoc service 626 @param service_jid(jid.JID, None): jid of the ad-hoc service
636 None to use profile's server 627 None to use profile's server
637 @param node(unicode, None): node of the ad-hoc commnad 628 @param node(unicode, None): node of the ad-hoc commnad
641 if service_jid is None: 632 if service_jid is None:
642 service_jid = jid.JID(client.jid.host) 633 service_jid = jid.JID(client.jid.host)
643 session_id, session_data = self.requesting.newSession(profile=client.profile) 634 session_id, session_data = self.requesting.newSession(profile=client.profile)
644 session_data["jid"] = service_jid 635 session_data["jid"] = service_jid
645 if node is None: 636 if node is None:
646 xmlui = yield self.listUI(client, service_jid) 637 xmlui = await self.listUI(client, service_jid)
647 else: 638 else:
648 session_data["node"] = node 639 session_data["node"] = node
649 cb_data = yield self.requestingEntity( 640 cb_data = await self.requestingEntity(
650 {"session_id": session_id}, client.profile 641 {"session_id": session_id}, client.profile
651 ) 642 )
652 xmlui = cb_data["xmlui"] 643 xmlui = cb_data["xmlui"]
653 644
654 xmlui.session_id = session_id 645 xmlui.session_id = session_id
655 defer.returnValue(xmlui) 646 return xmlui
656 647
657 def list(self, client, to_jid): 648 def list(self, client, to_jid):
658 """Request available commands 649 """Request available commands
659 650
660 @param to_jid(jid.JID, None): the entity answering the commands 651 @param to_jid(jid.JID, None): the entity answering the commands