diff sat/plugins/plugin_xep_0373.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 4836b81c5f31
children
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0373.py	Fri Apr 07 15:18:39 2023 +0200
+++ b/sat/plugins/plugin_xep_0373.py	Sat Apr 08 13:54:42 2023 +0200
@@ -197,7 +197,7 @@
 
     @abstractmethod
     def import_public_key(self, packet: bytes) -> GPGPublicKey:
-        """Import a public key from a key material packet according to RFC 4880 §5.5.
+        """import a public key from a key material packet according to RFC 4880 §5.5.
 
         OpenPGP's ASCII Armor is not used.
 
@@ -1013,7 +1013,7 @@
 
         # Add configuration option to choose between manual trust and BTBV as the trust
         # model
-        host.memory.updateParams(DEFAULT_TRUST_MODEL_PARAM)
+        host.memory.update_params(DEFAULT_TRUST_MODEL_PARAM)
 
         self.__xep_0045 = cast(Optional[XEP_0045], host.plugins.get("XEP-0045"))
         self.__xep_0060 = cast(XEP_0060, host.plugins["XEP-0060"])
@@ -1021,7 +1021,7 @@
         self.__storage: Dict[str, persistent.LazyPersistentBinaryDict] = {}
 
         xep_0163 = cast(XEP_0163, host.plugins["XEP-0163"])
-        xep_0163.addPEPEvent(
+        xep_0163.add_pep_event(
             "OX_PUBLIC_KEYS_LIST",
             PUBLIC_KEYS_LIST_NODE,
             lambda items_event, profile: defer.ensureDeferred(
@@ -1029,10 +1029,10 @@
             )
         )
 
-    async def profileConnecting(self, client):
+    async def profile_connecting(self, client):
         client.gpg_provider = get_gpg_provider(self.host, client)
 
-    async def profileConnected(  # pylint: disable=invalid-name
+    async def profile_connected(  # pylint: disable=invalid-name
         self,
         client: SatXMPPClient
     ) -> None:
@@ -1061,7 +1061,7 @@
         @param profile: The profile this event belongs to.
         """
 
-        client = self.host.getClient(profile)
+        client = self.host.get_client(profile)
 
         sender = cast(jid.JID, items_event.sender)
         items = cast(List[domish.Element], items_event.items)
@@ -1323,7 +1323,7 @@
         encryption_keys: Set[GPGPublicKey] = set()
 
         for recipient_jid in recipient_jids:
-            # Import all keys of the recipient
+            # import all keys of the recipient
             all_public_keys = await self.import_all_public_keys(client, recipient_jid)
 
             # Filter for keys that can encrypt
@@ -1379,7 +1379,7 @@
             self.list_secret_keys(client)
         ))
 
-        # Import all keys of the sender
+        # import all keys of the sender
         all_public_keys = await self.import_all_public_keys(client, sender_jid)
 
         # Filter for keys that can sign
@@ -1471,7 +1471,7 @@
         pubkey_elt.addElement("data", content=base64.b64encode(packet).decode("ASCII"))
 
         try:
-            await self.__xep_0060.sendItem(
+            await self.__xep_0060.send_item(
                 client,
                 client.jid.userhostJID(),
                 node,
@@ -1495,7 +1495,7 @@
         client: SatXMPPClient,
         entity_jid: jid.JID
     ) -> Set[GPGPublicKey]:
-        """Import all public keys of a JID that have not been imported before.
+        """import all public keys of a JID that have not been imported before.
 
         @param client: The client.
         @param jid: The JID. Can be a bare JID.
@@ -1539,7 +1539,7 @@
                 )
             except Exception as e:
                 log.warning(
-                    f"Import of public key {missing_key.fingerprint} owned by"
+                    f"import of public key {missing_key.fingerprint} owned by"
                     f" {entity_jid.userhost()} failed, ignoring: {e}"
                 )
 
@@ -1551,7 +1551,7 @@
         jid: jid.JID,
         fingerprint: str
     ) -> GPGPublicKey:
-        """Import a public key.
+        """import a public key.
 
         @param client: The client.
         @param jid: The JID owning the public key. Can be a bare JID.
@@ -1569,7 +1569,7 @@
         node = f"urn:xmpp:openpgp:0:public-keys:{fingerprint}"
 
         try:
-            items, __ = await self.__xep_0060.getItems(
+            items, __ = await self.__xep_0060.get_items(
                 client,
                 jid.userhostJID(),
                 node,
@@ -1644,7 +1644,7 @@
             pubkey_metadata_elt["date"] = format_datetime(public_key_metadata.timestamp)
 
         try:
-            await self.__xep_0060.sendItem(
+            await self.__xep_0060.send_item(
                 client,
                 client.jid.userhostJID(),
                 node,
@@ -1681,7 +1681,7 @@
         node = "urn:xmpp:openpgp:0:public-keys"
 
         try:
-            items, __ = await self.__xep_0060.getItems(
+            items, __ = await self.__xep_0060.get_items(
                 client,
                 jid.userhostJID(),
                 node,
@@ -1741,7 +1741,7 @@
         """
 
         try:
-            infos = cast(DiscoInfo, await self.host.memory.disco.getInfos(
+            infos = cast(DiscoInfo, await self.host.memory.disco.get_infos(
                 client,
                 client.jid.userhostJID()
             ))
@@ -1769,7 +1769,7 @@
         node = "urn:xmpp:openpgp:0:secret-key"
 
         try:
-            items, __ = await self.__xep_0060.getItems(
+            items, __ = await self.__xep_0060.get_items(
                 client,
                 client.jid.userhostJID(),
                 node,
@@ -1834,7 +1834,7 @@
         secretkey_elt.addContent(base64.b64encode(ciphertext).decode("ASCII"))
 
         try:
-            await self.__xep_0060.sendItem(
+            await self.__xep_0060.send_item(
                 client,
                 client.jid.userhostJID(),
                 node,
@@ -1888,7 +1888,7 @@
         ciphertext: bytes,
         backup_code: str
     ) -> Set[GPGSecretKey]:
-        """Import previously downloaded secret keys.
+        """import previously downloaded secret keys.
 
         The downloading and importing steps are separate since a backup code is required
         for the import and it should be possible to try multiple backup codes without
@@ -1930,7 +1930,7 @@
         bare_jids: Set[jid.JID] = set()
 
         try:
-            room = cast(muc.Room, xep_0045.getRoom(client, room_jid))
+            room = cast(muc.Room, xep_0045.get_room(client, room_jid))
         except exceptions.NotFound as e:
             raise exceptions.InternalError(
                 "Participant list of unjoined MUC requested."
@@ -1988,7 +1988,7 @@
 
         await self.__storage[client.profile].force(key, trust_level.name)
 
-    async def getTrustUI(  # pylint: disable=invalid-name
+    async def get_trust_ui(  # pylint: disable=invalid-name
         self,
         client: SatXMPPClient,
         entity: jid.JID
@@ -2004,7 +2004,7 @@
             raise ValueError("A bare JID is expected.")
 
         bare_jids: Set[jid.JID]
-        if self.__xep_0045 is not None and self.__xep_0045.isJoinedRoom(client, entity):
+        if self.__xep_0045 is not None and self.__xep_0045.is_joined_room(client, entity):
             bare_jids = self.__get_joined_muc_users(client, self.__xep_0045, entity)
         else:
             bare_jids = { entity.userhostJID() }
@@ -2031,7 +2031,7 @@
 
             data_form_result = cast(
                 Dict[str, str],
-                xml_tools.XMLUIResult2DataFormResult(data)
+                xml_tools.xmlui_result_2_data_form_result(data)
             )
             for key, value in data_form_result.items():
                 if not key.startswith("trust_"):
@@ -2048,7 +2048,7 @@
 
             return {}
 
-        submit_id = self.host.registerCallback(callback, with_data=True, one_shot=True)
+        submit_id = self.host.register_callback(callback, with_data=True, one_shot=True)
 
         result = xml_tools.XMLUI(
             panel_type=C.XMLUI_FORM,
@@ -2070,7 +2070,7 @@
 
         own_secret_keys = self.list_secret_keys(client)
 
-        trust_ui.changeContainer("label")
+        trust_ui.change_container("label")
         for index, secret_key in enumerate(own_secret_keys):
             trust_ui.addLabel(D_(f"Own secret key {index} fingerprint"))
             trust_ui.addText(secret_key.public_key.fingerprint)