diff sat/plugins/plugin_xep_0033.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 944f51f9c2b4
children c23cad65ae99
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0033.py	Fri Apr 07 15:18:39 2023 +0200
+++ b/sat/plugins/plugin_xep_0033.py	Sat Apr 08 13:54:42 2023 +0200
@@ -77,11 +77,11 @@
         self.host = host
         self.internal_data = {}
         host.trigger.add(
-            "sendMessage", self.sendMessageTrigger, trigger.TriggerManager.MIN_PRIORITY
+            "sendMessage", self.send_message_trigger, trigger.TriggerManager.MIN_PRIORITY
         )
-        host.trigger.add("messageReceived", self.messageReceivedTrigger)
+        host.trigger.add("messageReceived", self.message_received_trigger)
 
-    def sendMessageTrigger(
+    def send_message_trigger(
         self, client, mess_data, pre_xml_treatments, post_xml_treatments
     ):
         """Process the XEP-0033 related data to be sent"""
@@ -91,7 +91,7 @@
             if not "address" in mess_data["extra"]:
                 return mess_data
 
-            def discoCallback(entities):
+            def disco_callback(entities):
                 if not entities:
                     log.warning(
                         _("XEP-0033 is being used but the server doesn't support it!")
@@ -126,18 +126,18 @@
                         )
                     )
                 # when the prosody plugin is completed, we can immediately return mess_data from here
-                self.sendAndStoreMessage(mess_data, entries, profile)
+                self.send_and_store_message(mess_data, entries, profile)
                 log.debug("XEP-0033 took over")
                 raise failure.Failure(exceptions.CancelError("Cancelled by XEP-0033"))
 
-            d = self.host.findFeaturesSet(client, [NS_ADDRESS])
-            d.addCallbacks(discoCallback, lambda __: discoCallback(None))
+            d = self.host.find_features_set(client, [NS_ADDRESS])
+            d.addCallbacks(disco_callback, lambda __: disco_callback(None))
             return d
 
         post_xml_treatments.addCallback(treatment)
         return True
 
-    def sendAndStoreMessage(self, mess_data, entries, profile):
+    def send_and_store_message(self, mess_data, entries, profile):
         """Check if target servers support XEP-0033, send and store the messages
         @return: a friendly failure to let the core know that we sent the message already
 
@@ -148,24 +148,24 @@
         Ideas:
         - fix Prosody plugin to check if target server support the feature
         - redesign the database to save only one entry to the database
-        - change the messageNew signal to eventually pass more than one recipient
+        - change the message_new signal to eventually pass more than one recipient
         """
-        client = self.host.getClient(profile)
+        client = self.host.get_client(profile)
 
         def send(mess_data, skip_send=False):
             d = defer.Deferred()
             if not skip_send:
                 d.addCallback(
-                    lambda ret: defer.ensureDeferred(client.sendMessageData(ret))
+                    lambda ret: defer.ensureDeferred(client.send_message_data(ret))
                 )
             d.addCallback(
-                lambda ret: defer.ensureDeferred(client.messageAddToHistory(ret))
+                lambda ret: defer.ensureDeferred(client.message_add_to_history(ret))
             )
-            d.addCallback(client.messageSendToBridge)
+            d.addCallback(client.message_send_to_bridge)
             d.addErrback(lambda failure: failure.trap(exceptions.CancelError))
             return d.callback(mess_data)
 
-        def discoCallback(entities, to_jid_s):
+        def disco_callback(entities, to_jid_s):
             history_data = copy.deepcopy(mess_data)
             history_data["to"] = JID(to_jid_s)
             history_data["xml"]["to"] = to_jid_s
@@ -183,7 +183,7 @@
                 send(history_data)
 
         def errback(failure, to_jid):
-            discoCallback(None, to_jid)
+            disco_callback(None, to_jid)
 
         timestamp = time()
         self.internal_data[timestamp] = []
@@ -191,17 +191,17 @@
         for type_, jid_ in entries:
             d = defer.Deferred()
             d.addCallback(
-                self.host.findFeaturesSet, client=client, jid_=JID(JID(jid_).host)
+                self.host.find_features_set, client=client, jid_=JID(JID(jid_).host)
             )
             d.addCallbacks(
-                discoCallback, errback, callbackArgs=[jid_], errbackArgs=[jid_]
+                disco_callback, errback, callbackArgs=[jid_], errbackArgs=[jid_]
             )
             d.callback([NS_ADDRESS])
             defer_list.append(d)
         d = defer.Deferred().addCallback(lambda __: self.internal_data.pop(timestamp))
         defer.DeferredList(defer_list).chainDeferred(d)
 
-    def messageReceivedTrigger(self, client, message, post_treat):
+    def message_received_trigger(self, client, message, post_treat):
         """In order to save the addressing information in the history"""
 
         def post_treat_addr(data, addresses):
@@ -224,7 +224,7 @@
             post_treat.addCallback(post_treat_addr, addresses.children)
         return True
 
-    def getHandler(self, client):
+    def get_handler(self, client):
         return XEP_0033_handler(self, client.profile)