comparison libervia/backend/plugins/plugin_xep_0334.py @ 4270:0d7bb4df2343

Reformatted code base using black.
author Goffi <goffi@goffi.org>
date Wed, 19 Jun 2024 18:44:57 +0200
parents 3b3cd9453d9b
children
comparison
equal deleted inserted replaced
4269:64a85ce8be70 4270:0d7bb4df2343
66 66
67 def __init__(self, host): 67 def __init__(self, host):
68 log.info(_("Message Processing Hints plugin initialization")) 68 log.info(_("Message Processing Hints plugin initialization"))
69 self.host = host 69 self.host = host
70 host.trigger.add("sendMessage", self.send_message_trigger) 70 host.trigger.add("sendMessage", self.send_message_trigger)
71 host.trigger.add("message_received", self.message_received_trigger, priority=-1000) 71 host.trigger.add(
72 "message_received", self.message_received_trigger, priority=-1000
73 )
72 74
73 def get_handler(self, client): 75 def get_handler(self, client):
74 return XEP_0334_handler() 76 return XEP_0334_handler()
75 77
76 def add_hint(self, mess_data, hint): 78 def add_hint(self, mess_data, hint):
83 if hint in self.HINTS: 85 if hint in self.HINTS:
84 hints.add(hint) 86 hints.add(hint)
85 else: 87 else:
86 log.error("Unknown hint: {}".format(hint)) 88 log.error("Unknown hint: {}".format(hint))
87 89
88 def add_hint_elements(self, message_elt: domish.Element, hints: Iterable[str]) -> None: 90 def add_hint_elements(
91 self, message_elt: domish.Element, hints: Iterable[str]
92 ) -> None:
89 """Add hints elements to message stanza 93 """Add hints elements to message stanza
90 94
91 @param message_elt: stanza where hints must be added 95 @param message_elt: stanza where hints must be added
92 @param hints: hints to add 96 @param hints: hints to add
93 """ 97 """
94 for hint in hints: 98 for hint in hints:
95 if not list(message_elt.elements(NS_HINTS, hint)): 99 if not list(message_elt.elements(NS_HINTS, hint)):
96 message_elt.addElement((NS_HINTS, hint)) 100 message_elt.addElement((NS_HINTS, hint))
97 else: 101 else:
98 log.debug(f'Not adding {hint!r} hint: it is already present in <message>') 102 log.debug(f"Not adding {hint!r} hint: it is already present in <message>")
99 103
100 def _send_post_xml_treatment(self, mess_data): 104 def _send_post_xml_treatment(self, mess_data):
101 if "hints" in mess_data: 105 if "hints" in mess_data:
102 self.add_hint_elements(mess_data["xml"], mess_data["hints"]) 106 self.add_hint_elements(mess_data["xml"], mess_data["hints"])
103 return mess_data 107 return mess_data