Reformatted code base using black.

This commit is contained in:
Goffi 2024-06-19 18:44:57 +02:00
commit 53fdaa9d09

View file

@ -59,7 +59,9 @@ class XEP_0048(object):
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 @@ class XEP_0048(object):
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 @@ class XEP_0048(object):
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 @@ class XEP_0048(object):
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 @@ class XEP_0048(object):
):
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 @@ class XEP_0048(object):
@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 @@ class XEP_0048(object):
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: