comparison sat/plugins/plugin_xep_0329.py @ 3040:fee60f17ebac

jp: jp asyncio port: /!\ this commit is huge. Jp is temporarily not working with `dbus` bridge /!\ This patch implements the port of jp to asyncio, so it is now correctly using the bridge asynchronously, and it can be used with bridges like `pb`. This also simplify the code, notably for things which were previously implemented with many callbacks (like pagination with RSM). During the process, some behaviours have been modified/fixed, in jp and backends, check diff for details.
author Goffi <goffi@goffi.org>
date Wed, 25 Sep 2019 08:56:41 +0200
parents 95e2fd14a761
children 02492db1ce39
comparison
equal deleted inserted replaced
3039:a1bc34f90fa5 3040:fee60f17ebac
593 if not self.host.trigger.point( 593 if not self.host.trigger.point(
594 "XEP-0329_compGetFilesFromNode", client, iq_elt, owner, node_path, files_data 594 "XEP-0329_compGetFilesFromNode", client, iq_elt, owner, node_path, files_data
595 ): 595 ):
596 return 596 return
597 for file_data in files_data: 597 for file_data in files_data:
598 file_elt = self._jf.buildFileElementFromDict( 598 if file_data['type'] == C.FILE_TYPE_DIRECTORY:
599 file_data, modified=file_data.get("modified", file_data["created"]) 599 directory_elt = query_elt.addElement("directory")
600 ) 600 directory_elt['name'] = file_data['name']
601 query_elt.addChild(file_elt) 601 else:
602 file_elt = self._jf.buildFileElementFromDict(
603 file_data, modified=file_data.get("modified", file_data["created"])
604 )
605 query_elt.addChild(file_elt)
602 client.send(iq_result_elt) 606 client.send(iq_result_elt)
603 607
604 def onComponentRequest(self, iq_elt, client): 608 def onComponentRequest(self, iq_elt, client):
605 return self._requestHandler( 609 return self._requestHandler(
606 client, iq_elt, self._compGetRootNodesCb, self._compGetFilesFromNodeCb 610 client, iq_elt, self._compGetRootNodesCb, self._compGetFilesFromNodeCb
622 # we have a directory 626 # we have a directory
623 627
624 file_data = {"name": elt["name"], "type": C.FILE_TYPE_DIRECTORY} 628 file_data = {"name": elt["name"], "type": C.FILE_TYPE_DIRECTORY}
625 else: 629 else:
626 log.warning( 630 log.warning(
627 _("unexpected element, ignoring: {elt}").format(elt=elt.toXml()) 631 _(f"unexpected element, ignoring: {elt.toXml()}")
628 ) 632 )
629 continue 633 continue
630 files.append(file_data) 634 files.append(file_data)
631 return files 635 return files
632 636
640 ) 644 )
641 return files_data 645 return files_data
642 646
643 def _listFiles(self, target_jid, path, extra, profile): 647 def _listFiles(self, target_jid, path, extra, profile):
644 client = self.host.getClient(profile) 648 client = self.host.getClient(profile)
645 target_jid = client.jid.userhostJID() if not target_jid else jid.JID(target_jid) 649 target_jid = client.jid if not target_jid else jid.JID(target_jid)
646 d = self.listFiles(client, target_jid, path or None) 650 d = self.listFiles(client, target_jid, path or None)
647 d.addCallback(self._serializeData) 651 d.addCallback(self._serializeData)
648 return d 652 return d
649 653
650 def listFiles(self, client, target_jid, path=None, extra=None): 654 def listFiles(self, client, target_jid, path=None, extra=None):