diff sat/plugins/plugin_xep_0329.py @ 2909:90146552cde5

core (memory), plugin XEP-0329, plugin invitation: minor style improvments
author Goffi <goffi@goffi.org>
date Sun, 14 Apr 2019 08:21:51 +0200
parents 003b8b4b56a7
children 1fd3ecb3351a
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0329.py	Sun Apr 14 08:21:51 2019 +0200
+++ b/sat/plugins/plugin_xep_0329.py	Sun Apr 14 08:21:51 2019 +0200
@@ -59,7 +59,7 @@
 
 
 class ShareNode(object):
-    """node containing directory or files to share, virtual or real"""
+    """Node containing directory or files to share, virtual or real"""
 
     host = None
 
@@ -112,7 +112,7 @@
         return self.children.itervalues()
 
     def getOrCreate(self, name, type_=TYPE_VIRTUAL, access=None):
-        """get a node or create a virtual node and return it"""
+        """Get a node or create a virtual node and return it"""
         if access is None:
             access = {C.ACCESS_PERM_READ: {KEY_TYPE: C.ACCESS_TYPE_PUBLIC}}
         try:
@@ -157,11 +157,12 @@
     def checkPermissions(
         self, client, peer_jid, perms=(C.ACCESS_PERM_READ,), check_parents=True
     ):
-        """check that peer_jid can access this node and all its parents
+        """Check that peer_jid can access this node and all its parents
 
         @param peer_jid(jid.JID): entrity trying to access the node
         @param perms(unicode): permissions to check, iterable of C.ACCESS_PERM_*
-        @param check_parents(bool): if True, access of all parents of this node will be checked too
+        @param check_parents(bool): if True, access of all parents of this node will be
+            checked too
         @return (bool): True if entity can access this node
         """
         peer_jid = peer_jid.userhostJID()
@@ -191,11 +192,9 @@
         path_elts = filter(None, path.split(u"/"))
 
         if u".." in path_elts:
-            log.warning(
-                _(
-                    u'parent dir ("..") found in path, hack attempt? path is {path} [{profile}]'
-                ).format(path=path, profile=client.profile)
-            )
+            log.warning(_(
+                u'parent dir ("..") found in path, hack attempt? path is {path} '
+                u'[{profile}]').format(path=path, profile=client.profile))
             raise exceptions.PermissionError(u"illegal path elements")
 
         if not path_elts:
@@ -312,9 +311,10 @@
     def _fileSendingRequestTrigger(
         self, client, session, content_data, content_name, file_data, file_elt
     ):
-        """this trigger check that a requested file is available, and fill suitable data if so
+        """This trigger check that a requested file is available, and fill suitable data
 
-        path and name are used to retrieve the file. If path is missing, we try our luck with known names
+        Path and name are used to retrieve the file. If path is missing, we try our luck
+        with known names
         """
         if client.is_component:
             return True, None
@@ -423,7 +423,8 @@
             )
 
             query_elt.addChild(file_elt)
-            # we don't specify hash as it would be too resource intensive to calculate it for all files
+            # we don't specify hash as it would be too resource intensive to calculate
+            # it for all files.
             # we add file to name_data, so users can request it later
             name_data = client._XEP_0329_names_data.setdefault(name, {})
             if path not in name_data:
@@ -547,7 +548,9 @@
         """retrieve files from local files repository according to permissions
 
         result stanza is then built and sent to requestor
-        @trigger XEP-0329_compGetFilesFromNode(client, iq_elt, owner, node_path, files_data): can be used to add data/elements
+        @trigger XEP-0329_compGetFilesFromNode(client, iq_elt, owner, node_path,
+                                               files_data):
+            can be used to add data/elements
         """
         peer_jid = jid.JID(iq_elt["from"])
         try:
@@ -660,7 +663,8 @@
         node = client._XEP_0329_root_node
         node_type = TYPE_PATH
         if os.path.isfile(path):
-            #  we have a single file, the workflow is diferrent as we store all single files in the same dir
+            # we have a single file, the workflow is diferrent as we store all single
+            # files in the same dir
             node = node.getOrCreate(SINGLE_FILES_DIR)
 
         if not name:
@@ -675,13 +679,9 @@
                 idx += 1
                 new_name = name + "_" + unicode(idx)
             name = new_name
-            log.info(
-                _(
-                    u"A directory with this name is already shared, renamed to {new_name} [{profile}]".format(
-                        new_name=new_name, profile=client.profile
-                    )
-                )
-            )
+            log.info(_(
+                u"A directory with this name is already shared, renamed to {new_name} "
+                u"[{profile}]".format( new_name=new_name, profile=client.profile)))
 
         ShareNode(name=name, parent=node, type_=node_type, access=access, path=path)
         self.host.bridge.FISSharedPathNew(path, name, client.profile)