diff sat/plugins/plugin_xep_0420.py @ 3933:cecf45416403

plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM: GPGME is used as the GPG provider. rel 374
author Syndace <me@syndace.dev>
date Tue, 20 Sep 2022 16:22:18 +0200
parents 626629781a53
children
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0420.py	Mon Oct 10 15:23:59 2022 +0200
+++ b/sat/plugins/plugin_xep_0420.py	Tue Sep 20 16:22:18 2022 +0200
@@ -22,8 +22,10 @@
 import secrets
 import string
 from typing import Dict, NamedTuple, Optional, Set, Tuple, cast
+from typing_extensions import Final
 
 from lxml import etree
+from sat.core import exceptions
 
 from sat.core.constants import Const as C
 from sat.core.i18n import D_
@@ -68,7 +70,7 @@
 }
 
 
-NS_SCE = "urn:xmpp:sce:1"
+NS_SCE: Final = "urn:xmpp:sce:1"
 
 
 class ProfileRequirementsNotMet(Exception):
@@ -114,7 +116,8 @@
             remain. Do not modify.
         @return: An affix element to include in the envelope. The element must have the
             name :attr:`element_name` and must validate using :attr:`element_schema`.
-        @raise ValueError: if the affix couldn't be built.
+        @raise ValueError: if the affix couldn't be built due to missing information on
+            the stanza.
         """
 
     @abstractmethod
@@ -384,7 +387,7 @@
             by the decryption scheme utilizing SCE.
         @return: The parsed and processed values of all affixes that were present on the
             envelope, notably including the timestamp.
-        @raise ValueError: if the serialized envelope element is malformed.
+        @raise exceptions.ParsingError: if the serialized envelope element is malformed.
         @raise ProfileRequirementsNotMet: if one or more affixes required by the profile
             are missing from the envelope.
         @raise AffixVerificationFailed: if an affix included in the envelope fails to
@@ -399,7 +402,9 @@
         try:
             envelope_serialized_string = envelope_serialized.decode("utf-8")
         except UnicodeError as e:
-            raise ValueError("Serialized envelope can't bare parsed as utf-8.") from e
+            raise exceptions.ParsingError(
+                "Serialized envelope can't bare parsed as utf-8."
+            ) from e
 
         custom_affixes = set(profile.custom_policies.keys())
 
@@ -420,7 +425,9 @@
         try:
             etree.fromstring(envelope_serialized_string, parser)
         except etree.XMLSyntaxError as e:
-            raise ValueError("Serialized envelope doesn't pass schema validation.") from e
+            raise exceptions.ParsingError(
+                "Serialized envelope doesn't pass schema validation."
+            ) from e
 
         # Prepare the envelope and content elements
         envelope = cast(domish.Element, ElementParser()(envelope_serialized_string))
@@ -452,7 +459,7 @@
             timestamp_value = None if time_element is None else \
                 XEP_0082.parse_datetime(time_element["stamp"])
         except ValueError as e:
-            raise AffixVerificationFailed("Malformed time affix") from e
+            raise AffixVerificationFailed("Malformed time affix.") from e
 
         # The to affix is verified by comparing the to attribute of the stanza with the
         # JID referenced by the affix. Note that only bare JIDs are compared as per the