diff sat/plugins/plugin_xep_0372.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 68a11b95a7d3
children c23cad65ae99
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0372.py	Fri Apr 07 15:18:39 2023 +0200
+++ b/sat/plugins/plugin_xep_0372.py	Sat Apr 08 13:54:42 2023 +0200
@@ -62,23 +62,23 @@
 
     def __init__(self, host):
         log.info(_("References plugin initialization"))
-        host.registerNamespace("refs", NS_REFS)
+        host.register_namespace("refs", NS_REFS)
         self.host = host
         self._h = host.plugins["XEP-0334"]
-        host.trigger.add("messageReceived", self._messageReceivedTrigger)
-        host.bridge.addMethod(
-            "referenceSend",
+        host.trigger.add("messageReceived", self._message_received_trigger)
+        host.bridge.add_method(
+            "reference_send",
             ".plugin",
             in_sign="sssss",
             out_sign="",
-            method=self._sendReference,
+            method=self._send_reference,
             async_=False,
         )
 
-    def getHandler(self, client):
+    def get_handler(self, client):
         return XEP_0372_Handler()
 
-    def refElementToRefData(
+    def ref_element_to_ref_data(
         self,
         reference_elt: domish.Element
     ) -> Dict[str, Union[str, int, dict]]:
@@ -88,7 +88,7 @@
         }
 
         if ref_data["uri"].startswith("xmpp:"):
-            ref_data["parsed_uri"] = xmpp_uri.parseXMPPUri(ref_data["uri"])
+            ref_data["parsed_uri"] = xmpp_uri.parse_xmpp_uri(ref_data["uri"])
 
         for attr in ("begin", "end"):
             try:
@@ -100,10 +100,10 @@
         if anchor is not None:
             ref_data["anchor"] = anchor
             if anchor.startswith("xmpp:"):
-                ref_data["parsed_anchor"] = xmpp_uri.parseXMPPUri(anchor)
+                ref_data["parsed_anchor"] = xmpp_uri.parse_xmpp_uri(anchor)
         return ref_data
 
-    async def _messageReceivedTrigger(
+    async def _message_received_trigger(
         self,
         client: SatXMPPEntity,
         message_elt: domish.Element,
@@ -114,18 +114,18 @@
         if reference_elt is None:
             return True
         try:
-            ref_data = self.refElementToRefData(reference_elt)
+            ref_data = self.ref_element_to_ref_data(reference_elt)
         except KeyError:
             log.warning("invalid <reference> element: {reference_elt.toXml}")
             return True
 
-        if not await self.host.trigger.asyncPoint(
+        if not await self.host.trigger.async_point(
             "XEP-0372_ref_received", client, message_elt, ref_data
         ):
             return False
         return True
 
-    def buildRefElement(
+    def build_ref_element(
         self,
         uri: str,
         type_: str = "mention",
@@ -148,7 +148,7 @@
             reference_elt["anchor"] = anchor
         return reference_elt
 
-    def _sendReference(
+    def _send_reference(
         self,
         recipient: str,
         anchor: str,
@@ -157,9 +157,9 @@
         profile_key: str
     ) -> defer.Deferred:
         recipient_jid = jid.JID(recipient)
-        client = self.host.getClient(profile_key)
+        client = self.host.get_client(profile_key)
         extra: dict = data_format.deserialise(extra_s, default={})
-        self.sendReference(
+        self.send_reference(
             client,
             uri=extra.get("uri"),
             type_=type_,
@@ -167,7 +167,7 @@
             to_jid=recipient_jid
         )
 
-    def sendReference(
+    def send_reference(
         self,
         client: "SatXMPPEntity",
         uri: Optional[str] = None,
@@ -200,7 +200,7 @@
                 raise exceptions.InternalError(
                     '"to_jid" must be set if "uri is None"'
                 )
-            uri = xmpp_uri.buildXMPPUri(path=to_jid.full())
+            uri = xmpp_uri.build_xmpp_uri(path=to_jid.full())
         if message_elt is None:
             message_elt = domish.Element((None, "message"))
 
@@ -215,8 +215,8 @@
                     '{message_elt.toXml()}'
                 )
 
-        message_elt.addChild(self.buildRefElement(uri, type_, begin, end, anchor))
-        self._h.addHintElements(message_elt, [self._h.HINT_STORE])
+        message_elt.addChild(self.build_ref_element(uri, type_, begin, end, anchor))
+        self._h.add_hint_elements(message_elt, [self._h.HINT_STORE])
         client.send(message_elt)