Mercurial > libervia-backend
comparison libervia/backend/core/xmpp.py @ 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 | 0d7bb4df2343 |
children | 94e0968987cd |
comparison
equal
deleted
inserted
replaced
4296:ffc43219e0b2 | 4297:0f953ce5f0a8 |
---|---|
688 | 688 |
689 @param post_xml_treatments(D): the same Deferred as in sendMessage trigger | 689 @param post_xml_treatments(D): the same Deferred as in sendMessage trigger |
690 """ | 690 """ |
691 raise NotImplementedError | 691 raise NotImplementedError |
692 | 692 |
693 async def a_send(self, obj): | 693 async def a_send(self, obj: domish.Element) -> None: |
694 # original send method accept string | 694 # original send method accept string |
695 # but we restrict to domish.Element to make trigger treatments easier | 695 # but we restrict to domish.Element to make trigger treatments easier |
696 assert isinstance(obj, domish.Element) | 696 assert isinstance(obj, domish.Element) |
697 # XXX: this trigger is the last one before sending stanza on wire | 697 # XXX: this trigger is the last one before sending stanza on wire |
698 # it is intended for things like end 2 end encryption. | 698 # it is intended for things like end 2 end encryption. |
702 # a lower priority | 702 # a lower priority |
703 if not (await self.host_app.trigger.async_point("send", self, obj)): | 703 if not (await self.host_app.trigger.async_point("send", self, obj)): |
704 return | 704 return |
705 super().send(obj) | 705 super().send(obj) |
706 | 706 |
707 def send(self, obj): | 707 def send(self, obj: domish.Element): |
708 defer.ensureDeferred(self.a_send(obj)) | 708 defer.ensureDeferred(self.a_send(obj)) |
709 | 709 |
710 async def send_message_data(self, mess_data): | 710 async def send_message_data(self, mess_data): |
711 """Convenient method to send message data to stream | 711 """Convenient method to send message data to stream |
712 | 712 |
1149 | 1149 |
1150 @property | 1150 @property |
1151 def is_admin(self) -> bool: | 1151 def is_admin(self) -> bool: |
1152 return False | 1152 return False |
1153 | 1153 |
1154 def is_local(self, jid_: jid.JID) -> bool: | |
1155 """Returns True if jid_ use a domain or subdomain of component's host""" | |
1156 local_host = self.host.split(".") | |
1157 assert local_host | |
1158 return jid_.host.split(".")[-len(local_host) :] == local_host | |
1159 | |
1154 def _create_sub_protocols(self): | 1160 def _create_sub_protocols(self): |
1155 self.messageProt = SatMessageProtocol(self.host_app) | 1161 self.messageProt = SatMessageProtocol(self.host_app) |
1156 self.messageProt.setHandlerParent(self) | 1162 self.messageProt.setHandlerParent(self) |
1157 | 1163 |
1158 def _build_dependencies(self, current, plugins, required=True): | 1164 def _build_dependencies(self, current, plugins, required=True): |
1308 @param client(SatXMPPClient, None): client to map message id to uid | 1314 @param client(SatXMPPClient, None): client to map message id to uid |
1309 if None, mapping will not be done | 1315 if None, mapping will not be done |
1310 @return(dict): message data | 1316 @return(dict): message data |
1311 """ | 1317 """ |
1312 if message_elt.name != "message": | 1318 if message_elt.name != "message": |
1313 log.warning( | 1319 log.error( |
1314 _( | 1320 _( |
1315 "parse_message used with a non <message/> stanza, ignoring: {xml}".format( | 1321 "parse_message used with a non <message/> stanza, ignoring: {xml}".format( |
1316 xml=message_elt.toXml() | 1322 xml=message_elt.toXml() |
1317 ) | 1323 ) |
1318 ) | 1324 ) |
1321 | 1327 |
1322 if message_elt.uri == None: | 1328 if message_elt.uri == None: |
1323 # xmlns may be None when wokkel element parsing strip out root namespace | 1329 # xmlns may be None when wokkel element parsing strip out root namespace |
1324 self.normalize_ns(message_elt, None) | 1330 self.normalize_ns(message_elt, None) |
1325 elif message_elt.uri != C.NS_CLIENT: | 1331 elif message_elt.uri != C.NS_CLIENT: |
1326 log.warning( | 1332 log.error( |
1327 _( | 1333 _( |
1328 "received <message> with a wrong namespace: {xml}".format( | 1334 "received <message> with a wrong namespace: {xml}".format( |
1329 xml=message_elt.toXml() | 1335 xml=message_elt.toXml() |
1330 ) | 1336 ) |
1331 ) | 1337 ) |