Mercurial > libervia-backend
diff sat/plugins/plugin_xep_0359.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 | 8289ac1b34f4 |
children |
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0359.py Fri Apr 07 15:18:39 2023 +0200 +++ b/sat/plugins/plugin_xep_0359.py Sat Apr 08 13:54:42 2023 +0200 @@ -50,29 +50,29 @@ def __init__(self, host): log.info(_("Unique and Stable Stanza IDs plugin initialization")) self.host = host - host.registerNamespace("stanza_id", NS_SID) - host.trigger.add("message_parse", self._message_parseTrigger) - host.trigger.add("sendMessageData", self._sendMessageDataTrigger) + host.register_namespace("stanza_id", NS_SID) + host.trigger.add("message_parse", self._message_parse_trigger) + host.trigger.add("send_message_data", self._send_message_data_trigger) - def _message_parseTrigger(self, client, message_elt, mess_data): + def _message_parse_trigger(self, client, message_elt, mess_data): """Check if message has a stanza-id""" - stanza_id = self.getStanzaId(message_elt, client.jid.userhostJID()) + stanza_id = self.get_stanza_id(message_elt, client.jid.userhostJID()) if stanza_id is not None: mess_data['extra']['stanza_id'] = stanza_id - origin_id = self.getOriginId(message_elt) + origin_id = self.get_origin_id(message_elt) if origin_id is not None: mess_data['extra']['origin_id'] = origin_id return True - def _sendMessageDataTrigger(self, client, mess_data): + def _send_message_data_trigger(self, client, mess_data): origin_id = mess_data["extra"].get("origin_id") if not origin_id: origin_id = str(uuid.uuid4()) mess_data["extra"]["origin_id"] = origin_id message_elt = mess_data["xml"] - self.addOriginId(message_elt, origin_id) + self.add_origin_id(message_elt, origin_id) - def getStanzaId(self, element, by): + def get_stanza_id(self, element, by): """Return stanza-id if found in element @param element(domish.Element): element to parse @@ -92,7 +92,7 @@ return stanza_id - def addStanzaId(self, client, element, stanza_id, by=None): + def add_stanza_id(self, client, element, stanza_id, by=None): """Add a <stanza-id/> to a stanza @param element(domish.Element): stanza where the <stanza-id/> must be added @@ -103,7 +103,7 @@ sid_elt["by"] = client.jid.userhost() if by is None else by.userhost() sid_elt["id"] = stanza_id - def getOriginId(self, element: domish.Element) -> Optional[str]: + def get_origin_id(self, element: domish.Element) -> Optional[str]: """Return origin-id if found in element @param element: element to parse @@ -116,7 +116,7 @@ else: return origin_elt.getAttribute("id") - def addOriginId(self, element, origin_id=None): + def add_origin_id(self, element, origin_id=None): """Add a <origin-id/> to a stanza @param element(domish.Element): stanza where the <origin-id/> must be added @@ -129,7 +129,7 @@ sid_elt["id"] = origin_id return origin_id - def getHandler(self, client): + def get_handler(self, client): return XEP_0359_handler()