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

Reformatted code base using black.
author Goffi <goffi@goffi.org>
date Wed, 19 Jun 2024 18:44:57 +0200
parents 4b842c1fb686
children
line wrap: on
line diff
--- a/libervia/backend/plugins/plugin_sec_pte.py	Tue Jun 18 12:06:45 2024 +0200
+++ b/libervia/backend/plugins/plugin_sec_pte.py	Wed Jun 19 18:44:57 2024 +0200
@@ -72,7 +72,7 @@
         items: Optional[List[domish.Element]],
         options: Optional[dict],
         sender: jid.JID,
-        extra: Dict[str, Any]
+        extra: Dict[str, Any],
     ) -> bool:
         if not items or extra.get("encrypted_for") is None:
             return True
@@ -95,7 +95,7 @@
                 item,
                 targets,
                 is_muc_message=False,
-                stanza_id=None
+                stanza_id=None,
             )
             item_elts = list(item.elements())
             if len(item_elts) != 1:
@@ -126,9 +126,11 @@
             service = client.jid.userhostJID()
         for item in items:
             payload = item.firstChildElement()
-            if (payload is not None
+            if (
+                payload is not None
                 and payload.name == "encrypted"
-                and payload.uri == NS_PTE):
+                and payload.uri == NS_PTE
+            ):
                 encrypted_elt = payload
                 item.children.clear()
                 try:
@@ -138,25 +140,26 @@
                     raise exceptions.DataError(
                         f"invalid <encrypted> element: {encrypted_elt.toXml()}"
                     )
-                if encryption_type!= self._o.NS_TWOMEMO:
+                if encryption_type != self._o.NS_TWOMEMO:
                     raise NotImplementedError("only TWOMEMO is supported for now")
                 log.debug(f"decrypting item {item.getAttribute('id', '')}")
 
                 # FIXME: we do use _message_received_trigger now to decrypt the stanza, a
                 #   cleaner separated decrypt method should be used
                 encrypted_elt["from"] = encrypted_by.full()
-                if not await self._o._message_received_trigger(
-                    client,
-                    encrypted_elt,
-                    defer.Deferred()
-                ) or not encrypted_elt.children:
+                if (
+                    not await self._o._message_received_trigger(
+                        client, encrypted_elt, defer.Deferred()
+                    )
+                    or not encrypted_elt.children
+                ):
                     raise exceptions.EncryptionError("can't decrypt the message")
 
                 item.addChild(encrypted_elt.firstChildElement())
 
                 extra.setdefault("encrypted", {})[item["id"]] = {
                     "type": NS_PTE,
-                    "algorithm": encryption_type
+                    "algorithm": encryption_type,
                 }
         return True