diff sat/plugins/plugin_xep_0191.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 24fbc4cad534
children
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0191.py	Fri Apr 07 15:18:39 2023 +0200
+++ b/sat/plugins/plugin_xep_0191.py	Sat Apr 08 13:54:42 2023 +0200
@@ -53,26 +53,26 @@
 
     def __init__(self, host):
         log.info(_("Blocking Command initialization"))
-        host.registerNamespace("blocking", NS_BLOCKING)
+        host.register_namespace("blocking", NS_BLOCKING)
         self.host = host
-        host.bridge.addMethod(
-            "blockingList",
+        host.bridge.add_method(
+            "blocking_list",
             ".plugin",
             in_sign="s",
             out_sign="as",
-            method=self._blockList,
+            method=self._block_list,
             async_=True,
         )
-        host.bridge.addMethod(
-            "blockingBlock",
+        host.bridge.add_method(
+            "blocking_block",
             ".plugin",
             in_sign="ass",
             out_sign="",
             method=self._block,
             async_=True,
         )
-        host.bridge.addMethod(
-            "blockingUnblock",
+        host.bridge.add_method(
+            "blocking_unblock",
             ".plugin",
             in_sign="ass",
             out_sign="",
@@ -80,20 +80,20 @@
             async_=True,
         )
 
-    def getHandler(self, client):
+    def get_handler(self, client):
         return XEP_0191_Handler(self)
 
     @ensure_deferred
-    async def _blockList(
+    async def _block_list(
         self,
         profile_key=C.PROF_KEY_NONE
     ) -> List[str]:
-        client = self.host.getClient(profile_key)
-        blocked_jids = await self.blockList(client)
+        client = self.host.get_client(profile_key)
+        blocked_jids = await self.block_list(client)
         return [j.full() for j in blocked_jids]
 
-    async def blockList(self, client: SatXMPPEntity) -> Set[jid.JID]:
-        await self.host.checkFeature(client, NS_BLOCKING)
+    async def block_list(self, client: SatXMPPEntity) -> Set[jid.JID]:
+        await self.host.check_feature(client, NS_BLOCKING)
         iq_elt = client.IQ("get")
         iq_elt.addElement((NS_BLOCKING, "blocklist"))
         iq_result_elt = await iq_elt.send()
@@ -118,13 +118,13 @@
         entities: List[str],
         profile_key: str = C.PROF_KEY_NONE
     ) -> str:
-        client = self.host.getClient(profile_key)
+        client = self.host.get_client(profile_key)
         return defer.ensureDeferred(
             self.block(client, [jid.JID(entity) for entity in entities])
         )
 
     async def block(self, client: SatXMPPEntity, entities: List[jid.JID]) -> None:
-        await self.host.checkFeature(client, NS_BLOCKING)
+        await self.host.check_feature(client, NS_BLOCKING)
         iq_elt = client.IQ("set")
         block_elt = iq_elt.addElement((NS_BLOCKING, "block"))
         for entity in entities:
@@ -137,13 +137,13 @@
         entities: List[str],
         profile_key: str = C.PROF_KEY_NONE
     ) -> None:
-        client = self.host.getClient(profile_key)
+        client = self.host.get_client(profile_key)
         return defer.ensureDeferred(
             self.unblock(client, [jid.JID(e) for e in entities])
         )
 
     async def unblock(self, client: SatXMPPEntity, entities: List[jid.JID]) -> None:
-        await self.host.checkFeature(client, NS_BLOCKING)
+        await self.host.check_feature(client, NS_BLOCKING)
         iq_elt = client.IQ("set")
         unblock_elt = iq_elt.addElement((NS_BLOCKING, "unblock"))
         for entity in entities:
@@ -151,7 +151,7 @@
             item_elt["jid"] = entity.full()
         await iq_elt.send()
 
-    def onBlockPush(self, iq_elt: domish.Element, client: SatXMPPEntity) -> None:
+    def on_block_push(self, iq_elt: domish.Element, client: SatXMPPEntity) -> None:
         # TODO: send notification to user
         iq_elt.handled = True
         for item_elt in iq_elt.block.elements(NS_BLOCKING, "item"):
@@ -164,7 +164,7 @@
         iq_result_elt = xmlstream.toResponse(iq_elt, "result")
         client.send(iq_result_elt)
 
-    def onUnblockPush(self, iq_elt: domish.Element, client: SatXMPPEntity) -> None:
+    def on_unblock_push(self, iq_elt: domish.Element, client: SatXMPPEntity) -> None:
         # TODO: send notification to user
         iq_elt.handled = True
         items = list(iq_elt.unblock.elements(NS_BLOCKING, "item"))
@@ -193,13 +193,13 @@
     def connectionInitialized(self):
         self.xmlstream.addObserver(
             IQ_BLOCK_PUSH,
-            self.plugin_parent.onBlockPush,
+            self.plugin_parent.on_block_push,
             client=self.parent
 
         )
         self.xmlstream.addObserver(
             IQ_UNBLOCK_PUSH,
-            self.plugin_parent.onUnblockPush,
+            self.plugin_parent.on_unblock_push,
             client=self.parent
         )