diff libervia/backend/plugins/plugin_xep_0374.py @ 4270:0d7bb4df2343

Reformatted code base using black.
author Goffi <goffi@goffi.org>
date Wed, 19 Jun 2024 18:44:57 +0200
parents 7c5654c54fed
children
line wrap: on
line diff
--- a/libervia/backend/plugins/plugin_xep_0374.py	Tue Jun 18 12:06:45 2024 +0200
+++ b/libervia/backend/plugins/plugin_xep_0374.py	Wed Jun 19 18:44:57 2024 +0200
@@ -37,11 +37,7 @@
 from twisted.words.xish import domish
 
 
-__all__ = [  # pylint: disable=unused-variable
-    "PLUGIN_INFO",
-    "XEP_0374",
-    "NS_OXIM"
-]
+__all__ = ["PLUGIN_INFO", "XEP_0374", "NS_OXIM"]  # pylint: disable=unused-variable
 
 
 log = cast(Logger, getLogger(__name__))  # type: ignore[no-untyped-call]
@@ -51,9 +47,9 @@
     C.PI_NAME: "OXIM",
     C.PI_IMPORT_NAME: "XEP-0374",
     C.PI_TYPE: "SEC",
-    C.PI_PROTOCOLS: [ "XEP-0374" ],
-    C.PI_DEPENDENCIES: [ "XEP-0334", "XEP-0373" ],
-    C.PI_RECOMMENDATIONS: [ "XEP-0045" ],
+    C.PI_PROTOCOLS: ["XEP-0374"],
+    C.PI_DEPENDENCIES: ["XEP-0334", "XEP-0373"],
+    C.PI_RECOMMENDATIONS: ["XEP-0045"],
     C.PI_MAIN: "XEP_0374",
     C.PI_HANDLER: "no",
     C.PI_DESCRIPTION: _("""Implementation of OXIM"""),
@@ -85,9 +81,7 @@
 
         # Triggers
         sat.trigger.add(
-            "message_received",
-            self.__message_received_trigger,
-            priority=100050
+            "message_received", self.__message_received_trigger, priority=100050
         )
         sat.trigger.add("send", self.__send_trigger, priority=0)
 
@@ -95,9 +89,7 @@
         sat.register_encryption_plugin(self, "OXIM", NS_OX, 102)
 
     async def get_trust_ui(  # pylint: disable=invalid-name
-        self,
-        client: SatXMPPClient,
-        entity: jid.JID
+        self, client: SatXMPPClient, entity: jid.JID
     ) -> xml_tools.XMLUI:
         """
         @param client: The client.
@@ -110,9 +102,7 @@
 
     @staticmethod
     def __get_joined_muc_users(
-        client: SatXMPPClient,
-        xep_0045: XEP_0045,
-        room_jid: jid.JID
+        client: SatXMPPClient, xep_0045: XEP_0045, room_jid: jid.JID
     ) -> Set[jid.JID]:
         """
         @param client: The client.
@@ -148,7 +138,7 @@
         self,
         client: SatXMPPClient,
         message_elt: domish.Element,
-        post_treat: defer.Deferred
+        post_treat: defer.Deferred,
     ) -> bool:
         """
         @param client: The client which received the message.
@@ -216,10 +206,9 @@
 
         sender_bare_jid = sender_jid.userhost()
 
-        openpgp_elt = cast(Optional[domish.Element], next(
-            message_elt.elements(NS_OX, "openpgp"),
-            None
-        ))
+        openpgp_elt = cast(
+            Optional[domish.Element], next(message_elt.elements(NS_OX, "openpgp"), None)
+        )
 
         if openpgp_elt is None:
             # None of our business, let the flow continue
@@ -227,24 +216,22 @@
 
         try:
             payload_elt, timestamp = await self.__xep_0373.unpack_openpgp_element(
-                client,
-                openpgp_elt,
-                "signcrypt",
-                jid.JID(sender_bare_jid)
+                client, openpgp_elt, "signcrypt", jid.JID(sender_bare_jid)
             )
         except Exception as e:
             # TODO: More specific exception handling
-            log.warning(_("Can't decrypt message: {reason}\n{xml}").format(
-                reason=e,
-                xml=message_elt.toXml()
-            ))
+            log.warning(
+                _("Can't decrypt message: {reason}\n{xml}").format(
+                    reason=e, xml=message_elt.toXml()
+                )
+            )
             client.feedback(
                 feedback_jid,
                 D_(
                     f"An OXIM message from {sender_jid.full()} can't be decrypted:"
                     f" {e}"
                 ),
-                { C.MESS_EXTRA_INFO: C.EXTRA_INFO_DECR_ERR }
+                {C.MESS_EXTRA_INFO: C.EXTRA_INFO_DECR_ERR},
             )
             # No point in further processing this message
             return False
@@ -277,10 +264,7 @@
             post_treat.addCallback(client.encryption.mark_as_untrusted)
 
         # Mark the message as originally encrypted
-        post_treat.addCallback(
-            client.encryption.mark_as_encrypted,
-            namespace=NS_OX
-        )
+        post_treat.addCallback(client.encryption.mark_as_encrypted, namespace=NS_OX)
 
         # Message processed successfully, continue with the flow
         return True
@@ -322,11 +306,11 @@
             client,
             stanza,
             recipient_bare_jid,
-            stanza.getAttribute("type", "unkown") == C.MESS_TYPE_GROUPCHAT
+            stanza.getAttribute("type", "unkown") == C.MESS_TYPE_GROUPCHAT,
         )
 
         # Add a store hint if this is a message stanza
-        self.__xep_0334.add_hint_elements(stanza, [ "store" ])
+        self.__xep_0334.add_hint_elements(stanza, ["store"])
 
         # Let the flow continue.
         return True
@@ -336,7 +320,7 @@
         client: SatXMPPClient,
         stanza: domish.Element,
         recipient_jid: jid.JID,
-        is_muc_message: bool
+        is_muc_message: bool,
     ) -> None:
         """
         @param client: The client.
@@ -363,12 +347,10 @@
             room_jid = feedback_jid = recipient_jid.userhostJID()
 
             recipient_bare_jids = self.__get_joined_muc_users(
-                client,
-                self.__xep_0045,
-                room_jid
+                client, self.__xep_0045, room_jid
             )
         else:
-            recipient_bare_jids = { recipient_jid.userhostJID() }
+            recipient_bare_jids = {recipient_jid.userhostJID()}
             feedback_jid = recipient_jid.userhostJID()
 
         log.debug(
@@ -376,8 +358,9 @@
             f" {recipient_bare_jids}"
         )
 
-        signcrypt_elt, payload_elt = \
-            self.__xep_0373.build_signcrypt_element(recipient_bare_jids)
+        signcrypt_elt, payload_elt = self.__xep_0373.build_signcrypt_element(
+            recipient_bare_jids
+        )
 
         # Move elements from the stanza to the content element.
         # TODO: There should probably be explicitly forbidden elements here too, just as
@@ -404,22 +387,18 @@
 
         try:
             openpgp_elt = await self.__xep_0373.build_openpgp_element(
-                client,
-                signcrypt_elt,
-                recipient_bare_jids
+                client, signcrypt_elt, recipient_bare_jids
             )
         except Exception as e:
             msg = _(
                 # pylint: disable=consider-using-f-string
                 "Can't encrypt message for {entities}: {reason}".format(
-                    entities=', '.join(jid.userhost() for jid in recipient_bare_jids),
-                    reason=e
+                    entities=", ".join(jid.userhost() for jid in recipient_bare_jids),
+                    reason=e,
                 )
             )
             log.warning(msg)
-            client.feedback(feedback_jid, msg, {
-                C.MESS_EXTRA_INFO: C.EXTRA_INFO_ENCR_ERR
-            })
+            client.feedback(feedback_jid, msg, {C.MESS_EXTRA_INFO: C.EXTRA_INFO_ENCR_ERR})
             raise e
 
         stanza.addChild(openpgp_elt)