Mercurial > libervia-backend
comparison libervia/backend/core/xmpp.py @ 4342:17fa953c8cd7
core (types): improve `SatXMPPEntity` core type and type hints.
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 13 Jan 2025 01:23:10 +0100 |
parents | e94799a0908f |
children |
comparison
equal
deleted
inserted
replaced
4341:e9971a4b0627 | 4342:17fa953c8cd7 |
---|---|
516 xs.add_hook(C.STREAM_HOOK_RECEIVE, hook) | 516 xs.add_hook(C.STREAM_HOOK_RECEIVE, hook) |
517 for hook in send_hooks: | 517 for hook in send_hooks: |
518 xs.add_hook(C.STREAM_HOOK_SEND, hook) | 518 xs.add_hook(C.STREAM_HOOK_SEND, hook) |
519 super(SatXMPPEntity, self)._connected(xs) | 519 super(SatXMPPEntity, self)._connected(xs) |
520 | 520 |
521 def disconnect_profile(self, reason): | 521 def disconnect_profile(self, reason: failure.Failure|None) -> None: |
522 if self._connected_d is not None: | 522 if self._connected_d is not None: |
523 self.host_app.bridge.disconnected( | 523 self.host_app.bridge.disconnected( |
524 self.profile | 524 self.profile |
525 ) # we send the signal to the clients | 525 ) # we send the signal to the clients |
526 log.info( | 526 log.info( |
579 for plugin in self._get_plugins_list(): | 579 for plugin in self._get_plugins_list(): |
580 disconnected_cb = getattr(plugin, trigger_name, None) | 580 disconnected_cb = getattr(plugin, trigger_name, None) |
581 if disconnected_cb is not None: | 581 if disconnected_cb is not None: |
582 yield disconnected_cb(self) | 582 yield disconnected_cb(self) |
583 | 583 |
584 def is_connected(self): | 584 def is_connected(self) -> bool: |
585 """Return True is client is fully connected | 585 """Return True is client is fully connected |
586 | 586 |
587 client is considered fully connected if transport is started and all plugins | 587 client is considered fully connected if transport is started and all plugins |
588 are initialised | 588 are initialised |
589 """ | 589 """ |
592 except AttributeError: | 592 except AttributeError: |
593 return False | 593 return False |
594 | 594 |
595 return self._connected_d is not None and transport_connected | 595 return self._connected_d is not None and transport_connected |
596 | 596 |
597 def entity_disconnect(self): | 597 def entity_disconnect(self) -> defer.Deferred[None]: |
598 if not self.host_app.trigger.point("disconnecting", self): | 598 if not self.host_app.trigger.point("disconnecting", self): |
599 return | 599 return |
600 log.info(_("Disconnecting...")) | 600 log.info(_("Disconnecting...")) |
601 self.stopService() | 601 self.stopService() |
602 if self._connected_d is not None: | 602 if self._connected_d is not None: |
604 else: | 604 else: |
605 return defer.succeed(None) | 605 return defer.succeed(None) |
606 | 606 |
607 ## sending ## | 607 ## sending ## |
608 | 608 |
609 def IQ(self, type_="set", timeout=60): | 609 def IQ(self, type_="set", timeout=60) -> xmlstream.IQ: |
610 """shortcut to create an IQ element managing deferred | 610 """shortcut to create an IQ element managing deferred |
611 | 611 |
612 @param type_(unicode): IQ type ('set' or 'get') | 612 @param type_(unicode): IQ type ('set' or 'get') |
613 @param timeout(None, int): timeout in seconds | 613 @param timeout(None, int): timeout in seconds |
614 @return((D)domish.Element: result stanza | 614 @return((D)domish.Element: result stanza |
616 """ | 616 """ |
617 iq_elt = xmlstream.IQ(self.xmlstream, type_) | 617 iq_elt = xmlstream.IQ(self.xmlstream, type_) |
618 iq_elt.timeout = timeout | 618 iq_elt.timeout = timeout |
619 return iq_elt | 619 return iq_elt |
620 | 620 |
621 def sendError(self, iq_elt, condition, text=None, appCondition=None): | 621 def sendError( |
622 self, | |
623 iq_elt: domish.Element, | |
624 condition: str, | |
625 text: str|None = None, | |
626 appCondition: str|None = None | |
627 ) -> None: | |
622 """Send error stanza build from iq_elt | 628 """Send error stanza build from iq_elt |
623 | 629 |
624 @param iq_elt(domish.Element): initial IQ element | 630 @param iq_elt(domish.Element): initial IQ element |
625 @param condition(unicode): error condition | 631 @param condition(unicode): error condition |
626 """ | 632 """ |
852 | 858 |
853 def _cancel_error_trap(self, failure): | 859 def _cancel_error_trap(self, failure): |
854 """A message sending can be cancelled by a plugin treatment""" | 860 """A message sending can be cancelled by a plugin treatment""" |
855 failure.trap(exceptions.CancelError) | 861 failure.trap(exceptions.CancelError) |
856 | 862 |
857 def is_message_printable(self, mess_data): | 863 def is_message_printable(self, mess_data: MessageData) -> bool: |
858 """Return True if a message contain payload to show in frontends""" | 864 """Return True if a message contain payload to show in frontends""" |
859 return ( | 865 return bool( |
860 mess_data["message"] | 866 mess_data["message"] |
861 or mess_data["subject"] | 867 or mess_data["subject"] |
862 or mess_data["extra"].get(C.KEY_ATTACHMENTS) | 868 or mess_data["extra"].get(C.KEY_ATTACHMENTS) |
863 or mess_data["type"] == C.MESS_TYPE_INFO | 869 or mess_data["type"] == C.MESS_TYPE_INFO |
864 ) | 870 ) |