From 1fd553db40314f3de0cf35d9e345e7fa3c214de8 Mon Sep 17 00:00:00 2001 From: Goffi Date: Thu, 6 Oct 2022 15:19:08 +0200 Subject: [PATCH] plugin XEP-0300: type hints --- sat/plugins/plugin_xep_0300.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/sat/plugins/plugin_xep_0300.py b/sat/plugins/plugin_xep_0300.py index 28ee754c..34c1464f 100644 --- a/sat/plugins/plugin_xep_0300.py +++ b/sat/plugins/plugin_xep_0300.py @@ -17,21 +17,24 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from sat.core.i18n import _ +from typing import Tuple +import base64 +from collections import OrderedDict +import hashlib + +from twisted.internet import threads +from twisted.internet import defer +from twisted.words.protocols.jabber.xmlstream import XMPPHandler +from twisted.words.xish import domish +from wokkel import disco, iwokkel +from zope.interface import implementer + +from sat.core import exceptions from sat.core.constants import Const as C +from sat.core.i18n import _ from sat.core.log import getLogger log = getLogger(__name__) -from sat.core import exceptions -from twisted.words.xish import domish -from twisted.words.protocols.jabber.xmlstream import XMPPHandler -from twisted.internet import threads -from twisted.internet import defer -from zope.interface import implementer -from wokkel import disco, iwokkel -from collections import OrderedDict -import hashlib -import base64 PLUGIN_INFO = { @@ -61,6 +64,7 @@ class XEP_0300(object): ("sha-512", hashlib.sha512), ) ) + ALGO_DEFAULT = ALGO_DEFAULT def __init__(self, host): log.info(_("plugin Hashes initialization")) @@ -176,12 +180,12 @@ class XEP_0300(object): hash_elt["algo"] = algo return hash_elt - def parseHashElt(self, parent): + def parseHashElt(self, parent: domish.Element) -> Tuple[str, bytes]: """Find and parse a hash element if multiple elements are found, the strongest managed one is returned - @param (domish.Element): parent of element - @return (tuple[str, bytes]): (algo, hash) tuple + @param parent: parent of element + @return: (algo, hash) tuple both values can be None if is empty @raise exceptions.NotFound: the element is not present @raise exceptions.DataError: the element is invalid