Mercurial > libervia-backend
diff sat/plugins/plugin_xep_0380.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 | be6d91572633 |
children | c23cad65ae99 |
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0380.py Fri Apr 07 15:18:39 2023 +0200 +++ b/sat/plugins/plugin_xep_0380.py Sat Apr 08 13:54:42 2023 +0200 @@ -47,11 +47,11 @@ def __init__(self, host): self.host = host - host.trigger.add("sendMessage", self._sendMessageTrigger) - host.trigger.add("messageReceived", self._messageReceivedTrigger, priority=100) - host.registerNamespace("eme", NS_EME) + host.trigger.add("sendMessage", self._send_message_trigger) + host.trigger.add("messageReceived", self._message_received_trigger, priority=100) + host.register_namespace("eme", NS_EME) - def _addEMEElement(self, mess_data, namespace, name): + def _add_eme_element(self, mess_data, namespace, name): message_elt = mess_data['xml'] encryption_elt = message_elt.addElement((NS_EME, 'encryption')) encryption_elt['namespace'] = namespace @@ -59,7 +59,7 @@ encryption_elt['name'] = name return mess_data - def _sendMessageTrigger(self, client, mess_data, __, post_xml_treatments): + def _send_message_trigger(self, client, mess_data, __, post_xml_treatments): encryption = mess_data.get(C.MESS_KEY_ENCRYPTION) if encryption is not None: namespace = encryption['plugin'].namespace @@ -68,17 +68,17 @@ else: name = None post_xml_treatments.addCallback( - self._addEMEElement, namespace=namespace, name=name) + self._add_eme_element, namespace=namespace, name=name) return True - def _messageReceivedTrigger(self, client, message_elt, post_treat): + def _message_received_trigger(self, client, message_elt, post_treat): try: encryption_elt = next(message_elt.elements(NS_EME, 'encryption')) except StopIteration: return True namespace = encryption_elt['namespace'] - if namespace in client.encryption.getNamespaces(): + if namespace in client.encryption.get_namespaces(): # message is encrypted and we can decrypt it return True