comparison 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
comparison
equal deleted inserted replaced
4036:c4464d7ae97b 4037:524856bd7b19
45 45
46 class XEP_0380(object): 46 class XEP_0380(object):
47 47
48 def __init__(self, host): 48 def __init__(self, host):
49 self.host = host 49 self.host = host
50 host.trigger.add("sendMessage", self._sendMessageTrigger) 50 host.trigger.add("sendMessage", self._send_message_trigger)
51 host.trigger.add("messageReceived", self._messageReceivedTrigger, priority=100) 51 host.trigger.add("messageReceived", self._message_received_trigger, priority=100)
52 host.registerNamespace("eme", NS_EME) 52 host.register_namespace("eme", NS_EME)
53 53
54 def _addEMEElement(self, mess_data, namespace, name): 54 def _add_eme_element(self, mess_data, namespace, name):
55 message_elt = mess_data['xml'] 55 message_elt = mess_data['xml']
56 encryption_elt = message_elt.addElement((NS_EME, 'encryption')) 56 encryption_elt = message_elt.addElement((NS_EME, 'encryption'))
57 encryption_elt['namespace'] = namespace 57 encryption_elt['namespace'] = namespace
58 if name is not None: 58 if name is not None:
59 encryption_elt['name'] = name 59 encryption_elt['name'] = name
60 return mess_data 60 return mess_data
61 61
62 def _sendMessageTrigger(self, client, mess_data, __, post_xml_treatments): 62 def _send_message_trigger(self, client, mess_data, __, post_xml_treatments):
63 encryption = mess_data.get(C.MESS_KEY_ENCRYPTION) 63 encryption = mess_data.get(C.MESS_KEY_ENCRYPTION)
64 if encryption is not None: 64 if encryption is not None:
65 namespace = encryption['plugin'].namespace 65 namespace = encryption['plugin'].namespace
66 if namespace not in KNOWN_NAMESPACES: 66 if namespace not in KNOWN_NAMESPACES:
67 name = encryption['plugin'].name 67 name = encryption['plugin'].name
68 else: 68 else:
69 name = None 69 name = None
70 post_xml_treatments.addCallback( 70 post_xml_treatments.addCallback(
71 self._addEMEElement, namespace=namespace, name=name) 71 self._add_eme_element, namespace=namespace, name=name)
72 return True 72 return True
73 73
74 def _messageReceivedTrigger(self, client, message_elt, post_treat): 74 def _message_received_trigger(self, client, message_elt, post_treat):
75 try: 75 try:
76 encryption_elt = next(message_elt.elements(NS_EME, 'encryption')) 76 encryption_elt = next(message_elt.elements(NS_EME, 'encryption'))
77 except StopIteration: 77 except StopIteration:
78 return True 78 return True
79 79
80 namespace = encryption_elt['namespace'] 80 namespace = encryption_elt['namespace']
81 if namespace in client.encryption.getNamespaces(): 81 if namespace in client.encryption.get_namespaces():
82 # message is encrypted and we can decrypt it 82 # message is encrypted and we can decrypt it
83 return True 83 return True
84 84
85 name = KNOWN_NAMESPACES.get(namespace, encryption_elt.getAttribute("name")) 85 name = KNOWN_NAMESPACES.get(namespace, encryption_elt.getAttribute("name"))
86 86