diff sat/plugins/plugin_xep_0115.py @ 4037:524856bd7b19

massive refactoring to switch from camelCase to snake_case: historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a pre-PEP8 code, to use the same coding style as in Twisted. However, snake_case is more readable and it's better to follow PEP8 best practices, so it has been decided to move on full snake_case. Because Libervia has a huge codebase, this ended with a ugly mix of camelCase and snake_case. To fix that, this patch does a big refactoring by renaming every function and method (including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case. This is a massive change, and may result in some bugs.
author Goffi <goffi@goffi.org>
date Sat, 08 Apr 2023 13:54:42 +0200
parents be6d91572633
children
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0115.py	Fri Apr 07 15:18:39 2023 +0200
+++ b/sat/plugins/plugin_xep_0115.py	Sat Apr 08 13:54:42 2023 +0200
@@ -57,13 +57,13 @@
     def __init__(self, host):
         log.info(_("Plugin XEP_0115 initialization"))
         self.host = host
-        host.trigger.add("Presence send", self._presenceTrigger)
+        host.trigger.add("Presence send", self._presence_trigger)
 
-    def getHandler(self, client):
+    def get_handler(self, client):
         return XEP_0115_handler(self)
 
     @defer.inlineCallbacks
-    def _prepareCaps(self, client):
+    def _prepare_caps(self, client):
         # we have to calculate hash for client
         # because disco infos/identities may change between clients
 
@@ -80,7 +80,7 @@
         disco_infos = disco.DiscoInfo()
         for item in _infos:
             disco_infos.append(item)
-        cap_hash = client._caps_hash = self.host.memory.disco.generateHash(disco_infos)
+        cap_hash = client._caps_hash = self.host.memory.disco.generate_hash(disco_infos)
         log.info(
             "Our capability hash has been generated: [{cap_hash}]".format(
                 cap_hash=cap_hash
@@ -96,22 +96,22 @@
             client._caps_sent = False
         if cap_hash not in self.host.memory.disco.hashes:
             self.host.memory.disco.hashes[cap_hash] = disco_infos
-            self.host.memory.updateEntityData(
+            self.host.memory.update_entity_data(
                 client, client.jid, C.ENTITY_CAP_HASH, cap_hash
             )
 
-    def _presenceAddElt(self, client, obj):
+    def _presence_add_elt(self, client, obj):
         if client._caps_optimize:
             if client._caps_sent:
                 return
             client.caps_sent = True
         obj.addChild(client._caps_elt)
 
-    def _presenceTrigger(self, client, obj, presence_d):
+    def _presence_trigger(self, client, obj, presence_d):
         if not hasattr(client, "_caps_optimize"):
-            presence_d.addCallback(lambda __: self._prepareCaps(client))
+            presence_d.addCallback(lambda __: self._prepare_caps(client))
 
-        presence_d.addCallback(lambda __: self._presenceAddElt(client, obj))
+        presence_d.addCallback(lambda __: self._presence_add_elt(client, obj))
         return True
 
 
@@ -160,7 +160,7 @@
                 "hash [%(hash)s] already in cache, updating entity [%(jid)s]"
                 % {"hash": c_ver, "jid": from_jid.full()}
             )
-            self.host.memory.updateEntityData(
+            self.host.memory.update_entity_data(
                 self.client, from_jid, C.ENTITY_CAP_HASH, c_ver
             )
             return
@@ -175,7 +175,7 @@
             )
 
         def cb(__):
-            computed_hash = self.host.memory.getEntityDatum(
+            computed_hash = self.host.memory.get_entity_datum(
                 self.client, from_jid, C.ENTITY_CAP_HASH
             )
             if computed_hash != c_ver:
@@ -207,6 +207,6 @@
                 )
             )
 
-        d = self.host.getDiscoInfos(self.parent, from_jid)
+        d = self.host.get_disco_infos(self.parent, from_jid)
         d.addCallbacks(cb, eb)
         # TODO: me must manage the full algorithm described at XEP-0115 #5.4 part 3