# HG changeset patch # User Goffi # Date 1643126835 -3600 # Node ID 16e36f0dd1cb5fdd03c61a40a89c4851d06a448d # Parent 11f7ca8afd15ed7c56b1b02f46faf77b09cb1b27 memory (disco), core (main): new `hasIdentity` method diff -r 11f7ca8afd15 -r 16e36f0dd1cb sat/core/sat_main.py --- a/sat/core/sat_main.py Tue Jan 25 17:06:28 2022 +0100 +++ b/sat/core/sat_main.py Tue Jan 25 17:07:15 2022 +0100 @@ -1095,6 +1095,9 @@ def checkFeatures(self, *args, **kwargs): return self.memory.disco.checkFeatures(*args, **kwargs) + def hasIdentity(self, *args, **kwargs): + return self.memory.disco.hasIdentity(*args, **kwargs) + def getDiscoInfos(self, *args, **kwargs): return self.memory.disco.getInfos(*args, **kwargs) diff -r 11f7ca8afd15 -r 16e36f0dd1cb sat/memory/disco.py --- a/sat/memory/disco.py Tue Jan 25 17:06:28 2022 +0100 +++ b/sat/memory/disco.py Tue Jan 25 17:07:15 2022 +0100 @@ -17,11 +17,12 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +from typing import Optional from sat.core.i18n import _ from sat.core import exceptions from sat.core.log import getLogger +from sat.core.core_types import SatXMPPEntity -log = getLogger(__name__) from twisted.words.protocols.jabber import jid from twisted.words.protocols.jabber.error import StanzaError from twisted.internet import defer @@ -35,6 +36,9 @@ from hashlib import sha1 +log = getLogger(__name__) + + TIMEOUT = 15 CAP_HASH_ERROR = "ERROR" @@ -162,6 +166,25 @@ if identity is not None and identity not in disco_infos.identities: raise failure.Failure(exceptions.FeatureNotFound()) + async def hasIdentity( + self, + client: SatXMPPEntity, + category: str, + type_: str, + jid_: Optional[jid.JID] = None, + node: str = "" + ) -> bool: + """Tell if an entity has the requested identity + + @param category: identity category + @param type_: identity type + @param jid_: jid of the target, or None for profile's server + @param node(unicode): optional node to use for disco request + @return: True if the entity has the given identity + """ + disco_infos = await self.getInfos(client, jid_, node) + return (category, type_) in disco_infos.identities + def getInfos(self, client, jid_=None, node="", use_cache=True): """get disco infos from jid_, filling capability hash if needed