# HG changeset patch # User Goffi # Date 1725637327 -7200 # Node ID 0f953ce5f0a8667e8e3e86f719434fb17922aa2e # Parent ffc43219e0b21dcd1f28aab502d4b3272fa578ca core (xmpp): move `is_local` to `SatXMPPEntity` + type hints + some log level changes. diff -r ffc43219e0b2 -r 0f953ce5f0a8 libervia/backend/core/xmpp.py --- 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 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 with a wrong namespace: {xml}".format( xml=message_elt.toXml() diff -r ffc43219e0b2 -r 0f953ce5f0a8 libervia/backend/plugins/plugin_comp_ap_gateway/__init__.py --- 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"""