diff sat/plugins/plugin_xep_0199.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_0199.py	Fri Apr 07 15:18:39 2023 +0200
+++ b/sat/plugins/plugin_xep_0199.py	Sat Apr 08 13:54:42 2023 +0200
@@ -48,36 +48,36 @@
     def __init__(self, host):
         log.info(_("XMPP Ping plugin initialization"))
         self.host = host
-        host.bridge.addMethod(
+        host.bridge.add_method(
             "ping", ".plugin", in_sign='ss', out_sign='d', method=self._ping, async_=True)
         try:
             self.text_cmds = self.host.plugins[C.TEXT_CMDS]
         except KeyError:
             log.info(_("Text commands not available"))
         else:
-            self.text_cmds.registerTextCommands(self)
+            self.text_cmds.register_text_commands(self)
 
-    def getHandler(self, client):
+    def get_handler(self, client):
         return XEP_0199_handler(self)
 
-    def _pingRaiseIfFailure(self, pong):
+    def _ping_raise_if_failure(self, pong):
         """If ping didn't succeed, raise the failure, else return pong delay"""
         if pong[0] != "PONG":
             raise pong[0]
         return pong[1]
 
     def _ping(self, jid_s, profile):
-        client = self.host.getClient(profile)
+        client = self.host.get_client(profile)
         entity_jid = jid.JID(jid_s)
         d = self.ping(client, entity_jid)
-        d.addCallback(self._pingRaiseIfFailure)
+        d.addCallback(self._ping_raise_if_failure)
         return d
 
-    def _pingCb(self, iq_result, send_time):
+    def _ping_cb(self, iq_result, send_time):
         receive_time = time.time()
         return ("PONG", receive_time - send_time)
 
-    def _pingEb(self, failure_, send_time):
+    def _ping_eb(self, failure_, send_time):
         receive_time = time.time()
         return (failure_.value, receive_time - send_time)
 
@@ -94,8 +94,8 @@
         iq_elt.addElement((NS_PING, "ping"))
         d = iq_elt.send()
         send_time = time.time()
-        d.addCallback(self._pingCb, send_time)
-        d.addErrback(self._pingEb, send_time)
+        d.addCallback(self._ping_cb, send_time)
+        d.addErrback(self._ping_eb, send_time)
         return d
 
     def _cmd_ping_fb(self, pong, client, mess_data):
@@ -103,9 +103,9 @@
         txt_cmd = self.host.plugins[C.TEXT_CMDS]
 
         if pong[0] == "PONG":
-            txt_cmd.feedBack(client, "PONG ({time} s)".format(time=pong[1]), mess_data)
+            txt_cmd.feed_back(client, "PONG ({time} s)".format(time=pong[1]), mess_data)
         else:
-            txt_cmd.feedBack(
+            txt_cmd.feed_back(
                 client, _("ping error ({err_msg}). Response time: {time} s")
                 .format(err_msg=pong[0], time=pong[1]), mess_data)
 
@@ -120,7 +120,7 @@
                 entity_jid = jid.JID(mess_data["unparsed"].strip())
             except RuntimeError:
                 txt_cmd = self.host.plugins[C.TEXT_CMDS]
-                txt_cmd.feedBack(client, _('Invalid jid: "{entity_jid}"').format(
+                txt_cmd.feed_back(client, _('Invalid jid: "{entity_jid}"').format(
                     entity_jid=mess_data["unparsed"].strip()), mess_data)
                 return False
         else:
@@ -130,7 +130,7 @@
 
         return False
 
-    def onPingRequest(self, iq_elt, client):
+    def on_ping_request(self, iq_elt, client):
         log.info(_("XMPP PING received from {from_jid} [{profile}]").format(
             from_jid=iq_elt["from"], profile=client.profile))
         iq_elt.handled = True
@@ -146,7 +146,7 @@
 
     def connectionInitialized(self):
         self.xmlstream.addObserver(
-            PING_REQUEST, self.plugin_parent.onPingRequest, client=self.parent
+            PING_REQUEST, self.plugin_parent.on_ping_request, client=self.parent
         )
 
     def getDiscoInfo(self, requestor, target, nodeIdentifier=""):