Mercurial > libervia-backend
comparison sat/memory/disco.py @ 3718:16e36f0dd1cb
memory (disco), core (main): new `hasIdentity` method
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 25 Jan 2022 17:07:15 +0100 |
parents | be6d91572633 |
children | 193b56ef58e0 |
comparison
equal
deleted
inserted
replaced
3717:11f7ca8afd15 | 3718:16e36f0dd1cb |
---|---|
15 # GNU Affero General Public License for more details. | 15 # GNU Affero General Public License for more details. |
16 | 16 |
17 # You should have received a copy of the GNU Affero General Public License | 17 # You should have received a copy of the GNU Affero General Public License |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 from typing import Optional | |
20 from sat.core.i18n import _ | 21 from sat.core.i18n import _ |
21 from sat.core import exceptions | 22 from sat.core import exceptions |
22 from sat.core.log import getLogger | 23 from sat.core.log import getLogger |
23 | 24 from sat.core.core_types import SatXMPPEntity |
24 log = getLogger(__name__) | 25 |
25 from twisted.words.protocols.jabber import jid | 26 from twisted.words.protocols.jabber import jid |
26 from twisted.words.protocols.jabber.error import StanzaError | 27 from twisted.words.protocols.jabber.error import StanzaError |
27 from twisted.internet import defer | 28 from twisted.internet import defer |
28 from twisted.internet import reactor | 29 from twisted.internet import reactor |
29 from twisted.python import failure | 30 from twisted.python import failure |
31 from sat.tools import xml_tools | 32 from sat.tools import xml_tools |
32 from sat.memory import persistent | 33 from sat.memory import persistent |
33 from wokkel import disco | 34 from wokkel import disco |
34 from base64 import b64encode | 35 from base64 import b64encode |
35 from hashlib import sha1 | 36 from hashlib import sha1 |
37 | |
38 | |
39 log = getLogger(__name__) | |
36 | 40 |
37 | 41 |
38 TIMEOUT = 15 | 42 TIMEOUT = 15 |
39 CAP_HASH_ERROR = "ERROR" | 43 CAP_HASH_ERROR = "ERROR" |
40 | 44 |
159 if not set(features).issubset(disco_infos.features): | 163 if not set(features).issubset(disco_infos.features): |
160 raise failure.Failure(exceptions.FeatureNotFound()) | 164 raise failure.Failure(exceptions.FeatureNotFound()) |
161 | 165 |
162 if identity is not None and identity not in disco_infos.identities: | 166 if identity is not None and identity not in disco_infos.identities: |
163 raise failure.Failure(exceptions.FeatureNotFound()) | 167 raise failure.Failure(exceptions.FeatureNotFound()) |
168 | |
169 async def hasIdentity( | |
170 self, | |
171 client: SatXMPPEntity, | |
172 category: str, | |
173 type_: str, | |
174 jid_: Optional[jid.JID] = None, | |
175 node: str = "" | |
176 ) -> bool: | |
177 """Tell if an entity has the requested identity | |
178 | |
179 @param category: identity category | |
180 @param type_: identity type | |
181 @param jid_: jid of the target, or None for profile's server | |
182 @param node(unicode): optional node to use for disco request | |
183 @return: True if the entity has the given identity | |
184 """ | |
185 disco_infos = await self.getInfos(client, jid_, node) | |
186 return (category, type_) in disco_infos.identities | |
164 | 187 |
165 def getInfos(self, client, jid_=None, node="", use_cache=True): | 188 def getInfos(self, client, jid_=None, node="", use_cache=True): |
166 """get disco infos from jid_, filling capability hash if needed | 189 """get disco infos from jid_, filling capability hash if needed |
167 | 190 |
168 @param jid_: jid of the target, or None for profile's server | 191 @param jid_: jid of the target, or None for profile's server |