Mercurial > libervia-backend
diff libervia/backend/memory/disco.py @ 4270:0d7bb4df2343
Reformatted code base using black.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 19 Jun 2024 18:44:57 +0200 |
parents | 4b842c1fb686 |
children | 94e0968987cd |
line wrap: on
line diff
--- a/libervia/backend/memory/disco.py Tue Jun 18 12:06:45 2024 +0200 +++ b/libervia/backend/memory/disco.py Wed Jun 19 18:44:57 2024 +0200 @@ -111,7 +111,7 @@ class Discovery(object): - """ Manage capabilities of entities """ + """Manage capabilities of entities""" def __init__(self, host): self.host = host @@ -172,7 +172,7 @@ category: str, type_: str, jid_: Optional[jid.JID] = None, - node: str = "" + node: str = "", ) -> bool: """Tell if an entity has the requested identity @@ -264,9 +264,9 @@ if jid_ == client.server_jid and not node: # we cache items only for our own server and if node is not set try: - items = self.host.memory.entity_data_get( - client, jid_, ["DISCO_ITEMS"] - )["DISCO_ITEMS"] + items = self.host.memory.entity_data_get(client, jid_, ["DISCO_ITEMS"])[ + "DISCO_ITEMS" + ] log.debug("[%s] disco items are in cache" % jid_.full()) if not use_cache: # we ignore cache, so we pretend we haven't found it @@ -274,9 +274,7 @@ except (KeyError, exceptions.UnknownEntityError): log.debug("Caching [%s] disco items" % jid_.full()) items = yield client.disco.requestItems(jid_, nodeIdentifier=node) - self.host.memory.update_entity_data( - client, jid_, "DISCO_ITEMS", items - ) + self.host.memory.update_entity_data(client, jid_, "DISCO_ITEMS", items) else: try: items = yield client.disco.requestItems(jid_, nodeIdentifier=node) @@ -381,7 +379,7 @@ return d def generate_hash(self, services): - """ Generate a unique hash for given service + """Generate a unique hash for given service hash algorithm is the one described in XEP-0115 @param services: iterable of disco.DiscoIdentity/disco.DiscoFeature, as returned by discoHandler.info @@ -413,22 +411,22 @@ # extensions ext = list(services.extensions.values()) - ext.sort(key=lambda f: f.formNamespace.encode('utf-8')) + ext.sort(key=lambda f: f.formNamespace.encode("utf-8")) for extension in ext: - s.append(extension.formNamespace.encode('utf-8')) + s.append(extension.formNamespace.encode("utf-8")) s.append(b"<") fields = extension.fieldList - fields.sort(key=lambda f: f.var.encode('utf-8')) + fields.sort(key=lambda f: f.var.encode("utf-8")) for field in fields: - s.append(field.var.encode('utf-8')) + s.append(field.var.encode("utf-8")) s.append(b"<") - values = [v.encode('utf-8') for v in field.values] + values = [v.encode("utf-8") for v in field.values] values.sort() for value in values: s.append(value) s.append(b"<") - cap_hash = b64encode(sha1(b"".join(s)).digest()).decode('utf-8') + cap_hash = b64encode(sha1(b"".join(s)).digest()).decode("utf-8") log.debug(_("Capability hash generated: [{cap_hash}]").format(cap_hash=cap_hash)) return cap_hash @@ -464,11 +462,16 @@ extensions[form_type or ""] = fields - defer.returnValue(( - [str(f) for f in disco_infos.features], - [(cat, type_, name or "") - for (cat, type_), name in list(disco_infos.identities.items())], - extensions)) + defer.returnValue( + ( + [str(f) for f in disco_infos.features], + [ + (cat, type_, name or "") + for (cat, type_), name in list(disco_infos.identities.items()) + ], + extensions, + ) + ) def items2tuples(self, disco_items): """convert disco items to tuple of strings @@ -486,7 +489,7 @@ def _disco_items( self, entity_jid_s, node="", use_cache=True, profile_key=C.PROF_KEY_NONE ): - """ Discovery method for the bridge + """Discovery method for the bridge @param entity_jid_s: entity we want to discover @param node(unicode): optional node to use