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.
This commit is contained in:
Goffi 2023-04-08 13:54:42 +02:00
commit 6a6f15707a

View file

@ -47,11 +47,11 @@ class XEP_0380(object):
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 @@ class XEP_0380(object):
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 @@ class XEP_0380(object):
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