# HG changeset patch # User Goffi # Date 1665062348 -7200 # Node ID 40d47cc29ea4b896006a5637a044a14d804a352d # Parent 287938675461c7444a7d20040143e2e4be1685cd plugin XEP-0300: type hints diff -r 287938675461 -r 40d47cc29ea4 sat/plugins/plugin_xep_0300.py --- a/sat/plugins/plugin_xep_0300.py Thu Oct 06 14:59:49 2022 +0200 +++ b/sat/plugins/plugin_xep_0300.py Thu Oct 06 15:19:08 2022 +0200 @@ -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 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.constants import Const as C 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 @@ ("sha-512", hashlib.sha512), ) ) + ALGO_DEFAULT = ALGO_DEFAULT def __init__(self, host): log.info(_("plugin Hashes initialization")) @@ -176,12 +180,12 @@ 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