diff sat/plugins/plugin_xep_0163.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 5d72dc52ee4a
children
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0163.py	Fri Apr 07 15:18:39 2023 +0200
+++ b/sat/plugins/plugin_xep_0163.py	Sat Apr 08 13:54:42 2023 +0200
@@ -53,18 +53,18 @@
         self.host = host
         self.pep_events = set()
         self.pep_out_cb = {}
-        host.trigger.add("PubSub Disco Info", self.disoInfoTrigger)
-        host.bridge.addMethod(
-            "PEPSend",
+        host.trigger.add("PubSub Disco Info", self.diso_info_trigger)
+        host.bridge.add_method(
+            "pep_send",
             ".plugin",
             in_sign="sa{ss}s",
             out_sign="",
-            method=self.PEPSend,
+            method=self.pep_send,
             async_=True,
         )  # args: type(MOOD, TUNE, etc), data, profile_key;
-        self.addPEPEvent("MOOD", NS_USER_MOOD, self.userMoodCB, self.sendMood)
+        self.add_pep_event("MOOD", NS_USER_MOOD, self.user_mood_cb, self.send_mood)
 
-    def disoInfoTrigger(self, disco_info, profile):
+    def diso_info_trigger(self, disco_info, profile):
         """Add info from managed PEP
 
         @param disco_info: list of disco feature as returned by PubSub,
@@ -74,7 +74,7 @@
         disco_info.extend(list(map(disco.DiscoFeature, self.pep_events)))
         return True
 
-    def addPEPEvent(
+    def add_pep_event(
         self,
         event_type: Optional[str],
         node: str,
@@ -93,7 +93,7 @@
             the callable will be called with (itemsEvent, profile) as arguments
         @param out_callback: method to call when we want to publish this
             event (must return a deferred)
-            the callable will be called when sendPEPEvent is called
+            the callable will be called when send_pep_event is called
         @param notify: add autosubscribe (+notify) if True
         """
         if event_type and out_callback:
@@ -107,7 +107,7 @@
         if notify:
             self.pep_events.add(node + "+notify")
 
-        def filterPEPEvent(client, itemsEvent):
+        def filter_pep_event(client, itemsEvent):
             """Ignore messages which are not coming from PEP (i.e. a bare jid)
 
             @param itemsEvent(pubsub.ItemsEvent): pubsub event
@@ -121,20 +121,20 @@
                 return
             in_callback(itemsEvent, client.profile)
 
-        self.host.plugins["XEP-0060"].addManagedNode(node, items_cb=filterPEPEvent)
+        self.host.plugins["XEP-0060"].add_managed_node(node, items_cb=filter_pep_event)
 
-    def sendPEPEvent(self, node, data, profile):
+    def send_pep_event(self, node, data, profile):
         """Publish the event data
 
         @param node(unicode): node namespace
         @param data: domish.Element to use as payload
         @param profile: profile which send the data
         """
-        client = self.host.getClient(profile)
+        client = self.host.get_client(profile)
         item = pubsub.Item(payload=data)
         return self.host.plugins["XEP-0060"].publish(client, None, node, [item])
 
-    def PEPSend(self, event_type, data, profile_key=C.PROF_KEY_NONE):
+    def pep_send(self, event_type, data, profile_key=C.PROF_KEY_NONE):
         """Send personal event after checking the data is alright
 
         @param event_type: type of event (eg: MOOD, TUNE),
@@ -142,7 +142,7 @@
         @param data: dict of {string:string} of event_type dependant data
         @param profile_key: profile who send the event
         """
-        profile = self.host.memory.getProfileName(profile_key)
+        profile = self.host.memory.get_profile_name(profile_key)
         if not profile:
             log.error(
                 _("Trying to send personal event with an unknown profile key [%s]")
@@ -154,7 +154,7 @@
             raise exceptions.DataError("Type unknown")
         return self.pep_out_cb[event_type](data, profile)
 
-    def userMoodCB(self, itemsEvent, profile):
+    def user_mood_cb(self, itemsEvent, profile):
         if not itemsEvent.items:
             log.debug(_("No item found"))
             return
@@ -169,7 +169,7 @@
         if not mood:
             log.debug(_("No mood found"))
             return
-        self.host.bridge.psEvent(
+        self.host.bridge.ps_event(
             C.PS_PEP,
             itemsEvent.sender.full(),
             itemsEvent.nodeIdentifier,
@@ -178,7 +178,7 @@
             profile,
         )
 
-    def sendMood(self, data, profile):
+    def send_mood(self, data, profile):
         """Send XEP-0107's User Mood
 
         @param data: must include mood and text
@@ -189,7 +189,7 @@
         except KeyError:
             raise exceptions.DataError("Mood data must contain at least 'mood' key")
         mood = UserMood(value, text)
-        return self.sendPEPEvent(NS_USER_MOOD, mood, profile)
+        return self.send_pep_event(NS_USER_MOOD, mood, profile)
 
 
 class UserMood(Mood, domish.Element):