Mercurial > libervia-backend
changeset 4297:0f953ce5f0a8
core (xmpp): move `is_local` to `SatXMPPEntity` + type hints + some log level changes.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 06 Sep 2024 17:42:07 +0200 |
parents | ffc43219e0b2 |
children | 060d695ae98e |
files | libervia/backend/core/xmpp.py libervia/backend/plugins/plugin_comp_ap_gateway/__init__.py |
diffstat | 2 files changed, 14 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/libervia/backend/core/xmpp.py Fri Sep 06 17:40:32 2024 +0200 +++ b/libervia/backend/core/xmpp.py Fri Sep 06 17:42:07 2024 +0200 @@ -690,7 +690,7 @@ """ raise NotImplementedError - async def a_send(self, obj): + async def a_send(self, obj: domish.Element) -> None: # original send method accept string # but we restrict to domish.Element to make trigger treatments easier assert isinstance(obj, domish.Element) @@ -704,7 +704,7 @@ return super().send(obj) - def send(self, obj): + def send(self, obj: domish.Element): defer.ensureDeferred(self.a_send(obj)) async def send_message_data(self, mess_data): @@ -1151,6 +1151,12 @@ def is_admin(self) -> bool: return False + def is_local(self, jid_: jid.JID) -> bool: + """Returns True if jid_ use a domain or subdomain of component's host""" + local_host = self.host.split(".") + assert local_host + return jid_.host.split(".")[-len(local_host) :] == local_host + def _create_sub_protocols(self): self.messageProt = SatMessageProtocol(self.host_app) self.messageProt.setHandlerParent(self) @@ -1310,7 +1316,7 @@ @return(dict): message data """ if message_elt.name != "message": - log.warning( + log.error( _( "parse_message used with a non <message/> stanza, ignoring: {xml}".format( xml=message_elt.toXml() @@ -1323,7 +1329,7 @@ # xmlns may be None when wokkel element parsing strip out root namespace self.normalize_ns(message_elt, None) elif message_elt.uri != C.NS_CLIENT: - log.warning( + log.error( _( "received <message> with a wrong namespace: {xml}".format( xml=message_elt.toXml()
--- a/libervia/backend/plugins/plugin_comp_ap_gateway/__init__.py Fri Sep 06 17:40:32 2024 +0200 +++ b/libervia/backend/plugins/plugin_comp_ap_gateway/__init__.py Fri Sep 06 17:42:07 2024 +0200 @@ -764,9 +764,10 @@ def is_local(self, jid_: jid.JID) -> bool: """Returns True if jid_ use a domain or subdomain of gateway's host""" - local_host = self.client.host.split(".") - assert local_host - return jid_.host.split(".")[-len(local_host) :] == local_host + # FIXME: kept for compatiblity, need to be removed in favor of + # "self.client.is_local". + + return self.client.is_local(jid_) async def is_pubsub(self, jid_: jid.JID) -> bool: """Indicate if a JID is a Pubsub service"""