Mercurial > libervia-backend
comparison libervia/backend/plugins/plugin_xep_0055.py @ 4270:0d7bb4df2343
Reformatted code base using black.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 19 Jun 2024 18:44:57 +0200 |
parents | 4b842c1fb686 |
children | 94e0968987cd |
comparison
equal
deleted
inserted
replaced
4269:64a85ce8be70 | 4270:0d7bb4df2343 |
---|---|
59 | 59 |
60 DEFAULT_SERVICE_LIST = ["salut.libervia.org"] | 60 DEFAULT_SERVICE_LIST = ["salut.libervia.org"] |
61 | 61 |
62 FIELD_SINGLE = "field_single" # single text field for the simple search | 62 FIELD_SINGLE = "field_single" # single text field for the simple search |
63 FIELD_CURRENT_SERVICE = ( | 63 FIELD_CURRENT_SERVICE = ( |
64 "current_service_jid" | 64 "current_service_jid" # read-only text field for the advanced search |
65 ) # read-only text field for the advanced search | 65 ) |
66 | 66 |
67 | 67 |
68 class XEP_0055(object): | 68 class XEP_0055(object): |
69 def __init__(self, host): | 69 def __init__(self, host): |
70 log.info(_("Jabber search plugin initialization")) | 70 log.info(_("Jabber search plugin initialization")) |
122 @param profile (unicode): %(doc_profile)s | 122 @param profile (unicode): %(doc_profile)s |
123 @return: a deferred XMLUI string representation | 123 @return: a deferred XMLUI string representation |
124 """ | 124 """ |
125 # check if the user's server offers some search services | 125 # check if the user's server offers some search services |
126 d = self._get_host_services(profile) | 126 d = self._get_host_services(profile) |
127 return d.addCallback(lambda services: self.get_main_ui(services, raw_data, profile)) | 127 return d.addCallback( |
128 lambda services: self.get_main_ui(services, raw_data, profile) | |
129 ) | |
128 | 130 |
129 def get_main_ui(self, services, raw_data, profile): | 131 def get_main_ui(self, services, raw_data, profile): |
130 """Get the XMLUI for selecting a service and searching the directory. | 132 """Get the XMLUI for selecting a service and searching the directory. |
131 | 133 |
132 @param services (list[jid.JID]): search services offered by the user server | 134 @param services (list[jid.JID]): search services offered by the user server |
196 key: value for key, value in data.items() if key in (FIELD_SINGLE,) | 198 key: value for key, value in data.items() if key in (FIELD_SINGLE,) |
197 } | 199 } |
198 if simple_data: | 200 if simple_data: |
199 log.debug("Simple search with %s on %s" % (simple_data, service_jid)) | 201 log.debug("Simple search with %s on %s" % (simple_data, service_jid)) |
200 sub_cont.parent.set_selected(True) | 202 sub_cont.parent.set_selected(True) |
201 main_ui.change_container(sub_cont.append(xml_tools.VerticalContainer(main_ui))) | 203 main_ui.change_container( |
204 sub_cont.append(xml_tools.VerticalContainer(main_ui)) | |
205 ) | |
202 main_ui.addDivider("dash") | 206 main_ui.addDivider("dash") |
203 d = self.search_request(service_jid, simple_data, profile) | 207 d = self.search_request(service_jid, simple_data, profile) |
204 d.addCallbacks( | 208 d.addCallbacks( |
205 lambda elt: self._display_search_result(main_ui, elt), | 209 lambda elt: self._display_search_result(main_ui, elt), |
206 lambda failure: main_ui.addText(failure.getErrorMessage()), | 210 lambda failure: main_ui.addText(failure.getErrorMessage()), |
308 main_ui.addDivider("blank") # a blank line again after the button | 312 main_ui.addDivider("blank") # a blank line again after the button |
309 | 313 |
310 if adv_data: # display the search results | 314 if adv_data: # display the search results |
311 log.debug("Advanced search with %s on %s" % (adv_data, service_jid)) | 315 log.debug("Advanced search with %s on %s" % (adv_data, service_jid)) |
312 sub_cont.parent.set_selected(True) | 316 sub_cont.parent.set_selected(True) |
313 main_ui.change_container(sub_cont.append(xml_tools.VerticalContainer(main_ui))) | 317 main_ui.change_container( |
318 sub_cont.append(xml_tools.VerticalContainer(main_ui)) | |
319 ) | |
314 main_ui.addDivider("dash") | 320 main_ui.addDivider("dash") |
315 d = self.search_request(service_jid, adv_data, profile) | 321 d = self.search_request(service_jid, adv_data, profile) |
316 d.addCallbacks( | 322 d.addCallbacks( |
317 lambda elt: self._display_search_result(main_ui, elt), | 323 lambda elt: self._display_search_result(main_ui, elt), |
318 lambda failure: main_ui.addText(failure.getErrorMessage()), | 324 lambda failure: main_ui.addText(failure.getErrorMessage()), |