Reformatted code base using black.

This commit is contained in:
Goffi 2024-06-19 18:44:57 +02:00
commit 53fdaa9d09

View file

@ -72,7 +72,7 @@ class PTE:
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 @@ class PTE:
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 @@ class PTE:
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 @@ class PTE:
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