comparison sat/plugins/plugin_xep_0374.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 f461f11ea176
children c23cad65ae99
comparison
equal deleted inserted replaced
4036:c4464d7ae97b 4037:524856bd7b19
90 priority=100050 90 priority=100050
91 ) 91 )
92 sat.trigger.add("send", self.__send_trigger, priority=0) 92 sat.trigger.add("send", self.__send_trigger, priority=0)
93 93
94 # Register the encryption plugin 94 # Register the encryption plugin
95 sat.registerEncryptionPlugin(self, "OXIM", NS_OX, 102) 95 sat.register_encryption_plugin(self, "OXIM", NS_OX, 102)
96 96
97 async def getTrustUI( # pylint: disable=invalid-name 97 async def get_trust_ui( # pylint: disable=invalid-name
98 self, 98 self,
99 client: SatXMPPClient, 99 client: SatXMPPClient,
100 entity: jid.JID 100 entity: jid.JID
101 ) -> xml_tools.XMLUI: 101 ) -> xml_tools.XMLUI:
102 """ 102 """
104 @param entity: The entity whose device trust levels to manage. 104 @param entity: The entity whose device trust levels to manage.
105 @return: An XMLUI instance which opens a form to manage the trust level of all 105 @return: An XMLUI instance which opens a form to manage the trust level of all
106 devices belonging to the entity. 106 devices belonging to the entity.
107 """ 107 """
108 108
109 return await self.__xep_0373.getTrustUI(client, entity) 109 return await self.__xep_0373.get_trust_ui(client, entity)
110 110
111 @staticmethod 111 @staticmethod
112 def __get_joined_muc_users( 112 def __get_joined_muc_users(
113 client: SatXMPPClient, 113 client: SatXMPPClient,
114 xep_0045: XEP_0045, 114 xep_0045: XEP_0045,
124 """ 124 """
125 125
126 bare_jids: Set[jid.JID] = set() 126 bare_jids: Set[jid.JID] = set()
127 127
128 try: 128 try:
129 room = cast(muc.Room, xep_0045.getRoom(client, room_jid)) 129 room = cast(muc.Room, xep_0045.get_room(client, room_jid))
130 except exceptions.NotFound as e: 130 except exceptions.NotFound as e:
131 raise exceptions.InternalError( 131 raise exceptions.InternalError(
132 "Participant list of unjoined MUC requested." 132 "Participant list of unjoined MUC requested."
133 ) from e 133 ) from e
134 134
174 return True 174 return True
175 175
176 room_jid = feedback_jid = sender_jid.userhostJID() 176 room_jid = feedback_jid = sender_jid.userhostJID()
177 177
178 try: 178 try:
179 room = cast(muc.Room, self.__xep_0045.getRoom(client, room_jid)) 179 room = cast(muc.Room, self.__xep_0045.get_room(client, room_jid))
180 except exceptions.NotFound: 180 except exceptions.NotFound:
181 log.warning( 181 log.warning(
182 f"Ignoring MUC message from a room that has not been joined:" 182 f"Ignoring MUC message from a room that has not been joined:"
183 f" {room_jid}" 183 f" {room_jid}"
184 ) 184 )
270 message_elt.addChild(child) 270 message_elt.addChild(child)
271 271
272 # Mark the message as trusted or untrusted. Undecided counts as untrusted here. 272 # Mark the message as trusted or untrusted. Undecided counts as untrusted here.
273 trust_level = TrustLevel.UNDECIDED # TODO: Load the actual trust level 273 trust_level = TrustLevel.UNDECIDED # TODO: Load the actual trust level
274 if trust_level is TrustLevel.TRUSTED: 274 if trust_level is TrustLevel.TRUSTED:
275 post_treat.addCallback(client.encryption.markAsTrusted) 275 post_treat.addCallback(client.encryption.mark_as_trusted)
276 else: 276 else:
277 post_treat.addCallback(client.encryption.markAsUntrusted) 277 post_treat.addCallback(client.encryption.mark_as_untrusted)
278 278
279 # Mark the message as originally encrypted 279 # Mark the message as originally encrypted
280 post_treat.addCallback( 280 post_treat.addCallback(
281 client.encryption.markAsEncrypted, 281 client.encryption.mark_as_encrypted,
282 namespace=NS_OX 282 namespace=NS_OX
283 ) 283 )
284 284
285 # Message processed successfully, continue with the flow 285 # Message processed successfully, continue with the flow
286 return True 286 return True
324 recipient_bare_jid, 324 recipient_bare_jid,
325 stanza.getAttribute("type", "unkown") == C.MESS_TYPE_GROUPCHAT 325 stanza.getAttribute("type", "unkown") == C.MESS_TYPE_GROUPCHAT
326 ) 326 )
327 327
328 # Add a store hint if this is a message stanza 328 # Add a store hint if this is a message stanza
329 self.__xep_0334.addHintElements(stanza, [ "store" ]) 329 self.__xep_0334.add_hint_elements(stanza, [ "store" ])
330 330
331 # Let the flow continue. 331 # Let the flow continue.
332 return True 332 return True
333 333
334 async def __encrypt( 334 async def __encrypt(