diff libervia/backend/plugins/plugin_xep_0048.py @ 4270:0d7bb4df2343

Reformatted code base using black.
author Goffi <goffi@goffi.org>
date Wed, 19 Jun 2024 18:44:57 +0200
parents 3fbd1a1285c1
children
line wrap: on
line diff
--- a/libervia/backend/plugins/plugin_xep_0048.py	Tue Jun 18 12:06:45 2024 +0200
+++ b/libervia/backend/plugins/plugin_xep_0048.py	Wed Jun 19 18:44:57 2024 +0200
@@ -59,7 +59,9 @@
         log.info(_("Bookmarks plugin initialization"))
         self.host = host
         # self.__menu_id = host.register_callback(self._bookmarks_menu, with_data=True)
-        self.__bm_save_id = host.register_callback(self._bookmarks_save_cb, with_data=True)
+        self.__bm_save_id = host.register_callback(
+            self._bookmarks_save_cb, with_data=True
+        )
         host.import_menu(
             (D_("Groups"), D_("Bookmarks")),
             self._bookmarks_menu,
@@ -107,18 +109,15 @@
             NS_BOOKMARKS, client.profile
         )
         await local.load()
-        local = cast(dict[str, dict|None]|None, local)
+        local = cast(dict[str, dict | None] | None, local)
         if not local:
-            local = {
-                XEP_0048.MUC_TYPE: {},
-                XEP_0048.URL_TYPE: {}
-            }
+            local = {XEP_0048.MUC_TYPE: {}, XEP_0048.URL_TYPE: {}}
         private = await self._get_server_bookmarks("private", client.profile)
         pubsub = client.bookmarks_pubsub = None
 
         for bookmarks in (local, private, pubsub):
             if bookmarks is not None:
-                for (room_jid, data) in list(bookmarks[XEP_0048.MUC_TYPE].items()):
+                for room_jid, data in list(bookmarks[XEP_0048.MUC_TYPE].items()):
                     if data.get("autojoin", "false") == "true":
                         nick = data.get("nick", client.jid.user)
                         defer.ensureDeferred(
@@ -201,9 +200,7 @@
                 if conference_elt.hasAttribute(attr):
                     data[attr] = conference_elt[attr]
             try:
-                data["nick"] = str(
-                    next(conference_elt.elements(NS_BOOKMARKS, "nick"))
-                )
+                data["nick"] = str(next(conference_elt.elements(NS_BOOKMARKS, "nick")))
             except StopIteration:
                 pass
             # TODO: manage password (need to be secured, see XEP-0049 ยง4)
@@ -277,7 +274,7 @@
         return d
 
     def _bookmarks_menu(self, data, profile):
-        """ XMLUI activated by menu: return Gateways UI
+        """XMLUI activated by menu: return Gateways UI
         @param profile: %(doc_profile)s
 
         """
@@ -296,7 +293,7 @@
         ):
             if bookmarks is None:
                 continue
-            for (room_jid, data) in sorted(
+            for room_jid, data in sorted(
                 list(bookmarks[XEP_0048.MUC_TYPE].items()),
                 key=lambda item: item[1].get("name", item[0].user),
             ):
@@ -359,7 +356,9 @@
         @param profile_key: %(doc_profile_key)s
         """
         assert storage_type in ("auto", "pubsub", "private", "local")
-        if type_ == XEP_0048.URL_TYPE and {"autojoin", "nick"}.intersection(list(data.keys())):
+        if type_ == XEP_0048.URL_TYPE and {"autojoin", "nick"}.intersection(
+            list(data.keys())
+        ):
             raise ValueError("autojoin or nick can't be used with URLs")
         client = self.host.get_client(profile_key)
         if storage_type == "auto":
@@ -446,9 +445,7 @@
             try:
                 data = bookmarks_ori[type_]
             except KeyError:
-                log.warning(
-                    f"{type_!r} missing in {storage_location} storage."
-                )
+                log.warning(f"{type_!r} missing in {storage_location} storage.")
                 data = bookmarks_ori[type_] = {}
             for bookmark in data:
                 if type_ == XEP_0048.MUC_TYPE: