diff sat/plugins/plugin_xep_0234.py @ 3314:5887fb414758

component file sharing: add/parse affiliation when possible
author Goffi <goffi@goffi.org>
date Fri, 17 Jul 2020 13:00:10 +0200
parents f17379123571
children ac9342f359e9
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0234.py	Fri Jul 17 12:58:57 2020 +0200
+++ b/sat/plugins/plugin_xep_0234.py	Fri Jul 17 13:00:10 2020 +0200
@@ -105,7 +105,8 @@
 
     # generic methods
 
-    def buildFileElement(self, name=None, file_hash=None, hash_algo=None, size=None,
+    def buildFileElement(
+        self, client, name=None, file_hash=None, hash_algo=None, size=None,
         mime_type=None, desc=None, modified=None, transfer_range=None, path=None,
         namespace=None, file_elt=None, **kwargs):
         """Generate a <file> element with available metadata
@@ -113,17 +114,20 @@
         @param file_hash(unicode, None): hash of the file
             empty string to set <hash-used/> element
         @param hash_algo(unicode, None): hash algorithm used
-            if file_hash is None and hash_algo is set, a <hash-used/> element will be generated
+            if file_hash is None and hash_algo is set, a <hash-used/> element will be
+            generated
         @param transfer_range(Range, None): where transfer must start/stop
         @param modified(int, unicode, None): date of last modification
             0 to use current date
             int to use an unix timestamp
-            else must be an unicode string which will be used as it (it must be an XMPP time)
+            else must be an unicode string which will be used as it (it must be an XMPP
+            time)
         @param file_elt(domish.Element, None): element to use
             None to create a new one
         @param **kwargs: data for plugin extension (ignored by default)
         @return (domish.Element): generated element
-        @trigger XEP-0234_buildFileElement(file_elt, extra_args): can be used to extend elements to add
+        @trigger XEP-0234_buildFileElement(file_elt, extra_args): can be used to extend
+            elements to add
         """
         if file_elt is None:
             file_elt = domish.Element((NS_JINGLE_FT, "file"))
@@ -159,13 +163,14 @@
                 file_elt.addChild(self._hash.buildHashElt(file_hash, hash_algo))
         elif hash_algo is not None:
             file_elt.addChild(self._hash.buildHashUsedElt(hash_algo))
-        self.host.trigger.point("XEP-0234_buildFileElement", file_elt, extra_args=kwargs)
+        self.host.trigger.point(
+            "XEP-0234_buildFileElement", client, file_elt, extra_args=kwargs)
         if kwargs:
             for kw in kwargs:
                 log.debug("ignored keyword: {}".format(kw))
         return file_elt
 
-    def buildFileElementFromDict(self, file_data, **kwargs):
+    def buildFileElementFromDict(self, client, file_data, **kwargs):
         """like buildFileElement but get values from a file_data dict
 
         @param file_data(dict): metadata to use
@@ -174,10 +179,11 @@
         if kwargs:
             file_data = file_data.copy()
             file_data.update(kwargs)
-        return self.buildFileElement(**file_data)
+        return self.buildFileElement(client, **file_data)
 
-    def parseFileElement(self, file_elt, file_data=None, given=False, parent_elt=None,
-                         keep_empty_range=False,):
+    def parseFileElement(
+            self, client, file_elt, file_data=None, given=False, parent_elt=None,
+            keep_empty_range=False):
         """Parse a <file> element and file dictionary accordingly
 
         @param file_data(dict, None): dict where the data will be set
@@ -268,7 +274,7 @@
         except exceptions.NotFound:
             pass
 
-        self.host.trigger.point("XEP-0234_parseFileElement", file_elt, file_data)
+        self.host.trigger.point("XEP-0234_parseFileElement", client, file_elt, file_data)
 
         return file_data
 
@@ -423,7 +429,8 @@
                 file_data["namespace"] = extra["namespace"]
             if "path" in extra:
                 file_data["path"] = extra["path"]
-            self.buildFileElementFromDict(file_data, file_elt=file_elt, file_hash="")
+            self.buildFileElementFromDict(
+                client, file_data, file_elt=file_elt, file_hash="")
         else:
             # we request a file
             file_hash = extra.pop("file_hash", "")
@@ -440,7 +447,7 @@
                 file_data["namespace"] = extra["namespace"]
             if "path" in extra:
                 file_data["path"] = extra["path"]
-            self.buildFileElementFromDict(file_data, file_elt=file_elt)
+            self.buildFileElementFromDict(client, file_data, file_elt=file_elt)
 
         return desc_elt
 
@@ -474,7 +481,7 @@
         self, client, session, content_data, content_name, file_data, file_elt
     ):
         """parse file_elt, and handle file retrieving/permission checking"""
-        self.parseFileElement(file_elt, file_data)
+        self.parseFileElement(client, file_elt, file_data)
         content_data["application_data"]["file_data"] = file_data
         finished_d = content_data["finished_d"] = defer.Deferred()
 
@@ -504,7 +511,7 @@
         self, client, session, content_data, content_name, file_data, file_elt
     ):
         """parse file_elt, and handle user permission/file opening"""
-        self.parseFileElement(file_elt, file_data, given=True)
+        self.parseFileElement(client, file_elt, file_data, given=True)
         try:
             hash_algo, file_data["given_file_hash"] = self._hash.parseHashElt(file_elt)
         except exceptions.NotFound: