diff sat/plugins/plugin_sec_oxps.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 9badc46c5481
children c23cad65ae99
line wrap: on
line diff
--- a/sat/plugins/plugin_sec_oxps.py	Fri Apr 07 15:18:39 2023 +0200
+++ b/sat/plugins/plugin_sec_oxps.py	Sat Apr 08 13:54:42 2023 +0200
@@ -83,7 +83,7 @@
 
     def __init__(self, host):
         log.info(_("OpenPGP for XMPP Pubsub plugin initialization"))
-        host.registerNamespace("oxps", NS_OXPS)
+        host.register_namespace("oxps", NS_OXPS)
         self.host = host
         self._p = host.plugins["XEP-0060"]
         self._h = host.plugins["XEP-0334"]
@@ -94,32 +94,32 @@
             "messageReceived",
             self._message_received_trigger,
         )
-        host.bridge.addMethod(
-            "psSecretShare",
+        host.bridge.add_method(
+            "ps_secret_share",
             ".plugin",
             in_sign="sssass",
             out_sign="",
             method=self._ps_secret_share,
             async_=True,
         )
-        host.bridge.addMethod(
-            "psSecretRevoke",
+        host.bridge.add_method(
+            "ps_secret_revoke",
             ".plugin",
             in_sign="sssass",
             out_sign="",
             method=self._ps_secret_revoke,
             async_=True,
         )
-        host.bridge.addMethod(
-            "psSecretRotate",
+        host.bridge.add_method(
+            "ps_secret_rotate",
             ".plugin",
             in_sign="ssass",
             out_sign="",
             method=self._ps_secret_rotate,
             async_=True,
         )
-        host.bridge.addMethod(
-            "psSecretsList",
+        host.bridge.add_method(
+            "ps_secrets_list",
             ".plugin",
             in_sign="sss",
             out_sign="s",
@@ -127,10 +127,10 @@
             async_=True,
         )
 
-    def getHandler(self, client):
+    def get_handler(self, client):
         return PubsubEncryption_Handler()
 
-    async def profileConnecting(self, client):
+    async def profile_connecting(self, client):
         client.__storage = persistent.LazyPersistentBinaryDict(
             IMPORT_NAME, client.profile
         )
@@ -239,7 +239,7 @@
     ) -> defer.Deferred:
         return defer.ensureDeferred(
             self.revoke(
-                self.host.getClient(profile_key),
+                self.host.get_client(profile_key),
                 jid.JID(service) if service else None,
                 node,
                 secret_id,
@@ -267,7 +267,7 @@
         """
         if service is None:
             service = client.jid.userhostJID()
-        node_uri = uri.buildXMPPUri("pubsub", path=service.full(), node=node)
+        node_uri = uri.build_xmpp_uri("pubsub", path=service.full(), node=node)
         shared_secrets = await self.load_secrets(client, node_uri)
         if not shared_secrets:
             raise exceptions.NotFound(f"No shared secret is known for {node_uri}")
@@ -327,7 +327,7 @@
         message_elt["from"] = client.jid.full()
         message_elt["to"] = recipient.full()
         message_elt.addChild((openpgp_elt))
-        self._h.addHintElements(message_elt, [self._h.HINT_STORE])
+        self._h.add_hint_elements(message_elt, [self._h.HINT_STORE])
         client.send(message_elt)
 
     def _ps_secret_share(
@@ -340,7 +340,7 @@
     ) -> defer.Deferred:
         return defer.ensureDeferred(
             self.share_secrets(
-                self.host.getClient(profile_key),
+                self.host.get_client(profile_key),
                 jid.JID(recipient),
                 jid.JID(service) if service else None,
                 node,
@@ -377,7 +377,7 @@
         message_elt["from"] = client.jid.full()
         message_elt["to"] = recipient.full()
         message_elt.addChild((openpgp_elt))
-        self._h.addHintElements(message_elt, [self._h.HINT_STORE])
+        self._h.add_hint_elements(message_elt, [self._h.HINT_STORE])
         client.send(message_elt)
         shared_secret.shared_with.add(recipient)
 
@@ -399,7 +399,7 @@
         """
         if service is None:
             service = client.jid.userhostJID()
-        node_uri = uri.buildXMPPUri("pubsub", path=service.full(), node=node)
+        node_uri = uri.build_xmpp_uri("pubsub", path=service.full(), node=node)
         shared_secrets = await self.load_secrets(client, node_uri)
         if shared_secrets is None:
             # no secret shared yet, let's generate one
@@ -429,7 +429,7 @@
     ) -> defer.Deferred:
         return defer.ensureDeferred(
             self.rotate_secret(
-                self.host.getClient(profile_key),
+                self.host.get_client(profile_key),
                 jid.JID(service) if service else None,
                 node,
                 [jid.JID(r) for r in recipients] or None
@@ -453,7 +453,7 @@
         """
         if service is None:
             service = client.jid.userhostJID()
-        node_uri = uri.buildXMPPUri("pubsub", path=service.full(), node=node)
+        node_uri = uri.build_xmpp_uri("pubsub", path=service.full(), node=node)
         shared_secrets = await self.load_secrets(client, node_uri)
         if shared_secrets is None:
             shared_secrets = {}
@@ -489,7 +489,7 @@
     ) -> defer.Deferred:
         d = defer.ensureDeferred(
             self.list_shared_secrets(
-                self.host.getClient(profile_key),
+                self.host.get_client(profile_key),
                 jid.JID(service) if service else None,
                 node,
             )
@@ -512,7 +512,7 @@
         """
         if service is None:
             service = client.jid.userhostJID()
-        node_uri = uri.buildXMPPUri("pubsub", path=service.full(), node=node)
+        node_uri = uri.build_xmpp_uri("pubsub", path=service.full(), node=node)
         shared_secrets = await self.load_secrets(client, node_uri)
         if shared_secrets is None:
             raise exceptions.NotFound(f"No shared secrets found for {node_uri}")
@@ -541,7 +541,7 @@
                 f"ignoring invalid <revoke> element: {e}\n{revoke_elt.toXml()}"
             )
             return
-        node_uri = uri.buildXMPPUri("pubsub", path=service.full(), node=node)
+        node_uri = uri.build_xmpp_uri("pubsub", path=service.full(), node=node)
         shared_secrets = await self.load_secrets(client, node_uri)
         if shared_secrets is None:
             log.warning(
@@ -604,7 +604,7 @@
         shared_secret = SharedSecret(
             id=secret_id, key=key, timestamp=timestamp, origin=sender, revoked=revoked
         )
-        node_uri = uri.buildXMPPUri("pubsub", path=service.full(), node=node)
+        node_uri = uri.build_xmpp_uri("pubsub", path=service.full(), node=node)
         shared_secrets = await self.load_secrets(client, node_uri)
         if shared_secrets is None:
             shared_secrets = {}
@@ -636,7 +636,7 @@
     ) -> bool:
         if not items or not extra.get("encrypted"):
             return True
-        node_uri = uri.buildXMPPUri("pubsub", path=service.full(), node=node)
+        node_uri = uri.build_xmpp_uri("pubsub", path=service.full(), node=node)
         shared_secrets = await self.load_secrets(client, node_uri)
         if shared_secrets is None:
             shared_secrets = {}
@@ -713,7 +713,7 @@
                     )
                     continue
                 if shared_secrets is None:
-                    node_uri = uri.buildXMPPUri("pubsub", path=service.full(), node=node)
+                    node_uri = uri.build_xmpp_uri("pubsub", path=service.full(), node=node)
                     shared_secrets = await self.load_secrets(client, node_uri)
                     if shared_secrets is None:
                         log.warning(