massive refactoring to switch from camelCase to snake_case:
historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a pre-PEP8 code, to use the same coding style as in Twisted. However, snake_case is more readable and it's better to follow PEP8 best practices, so it has been decided to move on full snake_case. Because Libervia has a huge codebase, this ended with a ugly mix of camelCase and snake_case. To fix that, this patch does a big refactoring by renaming every function and method (including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case. This is a massive change, and may result in some bugs.
This commit is contained in:
parent
d50412c7f7
commit
6a6f15707a
1 changed files with 9945 additions and 9945 deletions
|
|
@ -57,39 +57,39 @@ class XEP_0048(object):
|
|||
def __init__(self, host):
|
||||
log.info(_("Bookmarks plugin initialization"))
|
||||
self.host = host
|
||||
# self.__menu_id = host.registerCallback(self._bookmarksMenu, with_data=True)
|
||||
self.__bm_save_id = host.registerCallback(self._bookmarksSaveCb, with_data=True)
|
||||
host.importMenu(
|
||||
# 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)
|
||||
host.import_menu(
|
||||
(D_("Groups"), D_("Bookmarks")),
|
||||
self._bookmarksMenu,
|
||||
self._bookmarks_menu,
|
||||
security_limit=0,
|
||||
help_string=D_("Use and manage bookmarks"),
|
||||
)
|
||||
self.__selected_id = host.registerCallback(
|
||||
self._bookmarkSelectedCb, with_data=True
|
||||
self.__selected_id = host.register_callback(
|
||||
self._bookmark_selected_cb, with_data=True
|
||||
)
|
||||
host.bridge.addMethod(
|
||||
"bookmarksList",
|
||||
host.bridge.add_method(
|
||||
"bookmarks_list",
|
||||
".plugin",
|
||||
in_sign="sss",
|
||||
out_sign="a{sa{sa{ss}}}",
|
||||
method=self._bookmarksList,
|
||||
method=self._bookmarks_list,
|
||||
async_=True,
|
||||
)
|
||||
host.bridge.addMethod(
|
||||
"bookmarksRemove",
|
||||
host.bridge.add_method(
|
||||
"bookmarks_remove",
|
||||
".plugin",
|
||||
in_sign="ssss",
|
||||
out_sign="",
|
||||
method=self._bookmarksRemove,
|
||||
method=self._bookmarks_remove,
|
||||
async_=True,
|
||||
)
|
||||
host.bridge.addMethod(
|
||||
"bookmarksAdd",
|
||||
host.bridge.add_method(
|
||||
"bookmarks_add",
|
||||
".plugin",
|
||||
in_sign="ssa{ss}ss",
|
||||
out_sign="",
|
||||
method=self._bookmarksAdd,
|
||||
method=self._bookmarks_add,
|
||||
async_=True,
|
||||
)
|
||||
try:
|
||||
|
|
@ -97,11 +97,11 @@ class XEP_0048(object):
|
|||
except KeyError:
|
||||
self.private_plg = None
|
||||
try:
|
||||
self.host.plugins[C.TEXT_CMDS].registerTextCommands(self)
|
||||
self.host.plugins[C.TEXT_CMDS].register_text_commands(self)
|
||||
except KeyError:
|
||||
log.info(_("Text commands not available"))
|
||||
|
||||
async def profileConnected(self, client):
|
||||
async def profile_connected(self, client):
|
||||
local = client.bookmarks_local = PersistentBinaryDict(
|
||||
NS_BOOKMARKS, client.profile
|
||||
)
|
||||
|
|
@ -109,7 +109,7 @@ class XEP_0048(object):
|
|||
if not local:
|
||||
local[XEP_0048.MUC_TYPE] = dict()
|
||||
local[XEP_0048.URL_TYPE] = dict()
|
||||
private = await self._getServerBookmarks("private", client.profile)
|
||||
private = await self._get_server_bookmarks("private", client.profile)
|
||||
pubsub = client.bookmarks_pubsub = None
|
||||
|
||||
for bookmarks in (local, private, pubsub):
|
||||
|
|
@ -125,7 +125,7 @@ class XEP_0048(object):
|
|||
# slow down a lot the connection process, and result in a bad user experience.
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def _getServerBookmarks(self, storage_type, profile):
|
||||
def _get_server_bookmarks(self, storage_type, profile):
|
||||
"""Get distants bookmarks
|
||||
|
||||
update also the client.bookmarks_[type] key, with None if service is not available
|
||||
|
|
@ -135,13 +135,13 @@ class XEP_0048(object):
|
|||
@param profile: %(doc_profile)s
|
||||
@return: data dictionary, or None if feature is not available
|
||||
"""
|
||||
client = self.host.getClient(profile)
|
||||
client = self.host.get_client(profile)
|
||||
if storage_type == "private":
|
||||
try:
|
||||
bookmarks_private_xml = yield self.private_plg.privateXMLGet(
|
||||
bookmarks_private_xml = yield self.private_plg.private_xml_get(
|
||||
"storage", NS_BOOKMARKS, profile
|
||||
)
|
||||
data = client.bookmarks_private = self._bookmarkElt2Dict(
|
||||
data = client.bookmarks_private = self._bookmark_elt_2_dict(
|
||||
bookmarks_private_xml
|
||||
)
|
||||
except (StanzaError, AttributeError):
|
||||
|
|
@ -154,7 +154,7 @@ class XEP_0048(object):
|
|||
defer.returnValue(data)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def _setServerBookmarks(self, storage_type, bookmarks_elt, profile):
|
||||
def _set_server_bookmarks(self, storage_type, bookmarks_elt, profile):
|
||||
"""Save bookmarks on server
|
||||
|
||||
@param storage_type: storage type, can be:
|
||||
|
|
@ -164,19 +164,19 @@ class XEP_0048(object):
|
|||
@param profile: %(doc_profile)s
|
||||
"""
|
||||
if storage_type == "private":
|
||||
yield self.private_plg.privateXMLStore(bookmarks_elt, profile)
|
||||
yield self.private_plg.private_xml_store(bookmarks_elt, profile)
|
||||
elif storage_type == "pubsub":
|
||||
raise NotImplementedError
|
||||
else:
|
||||
raise ValueError("storage_type must be 'private' or 'pubsub'")
|
||||
|
||||
def _bookmarkElt2Dict(self, storage_elt):
|
||||
def _bookmark_elt_2_dict(self, storage_elt):
|
||||
"""Parse bookmarks to get dictionary
|
||||
@param storage_elt (domish.Element): bookmarks storage
|
||||
@return (dict): bookmark data (key: bookmark type, value: list) where key can be:
|
||||
- XEP_0048.MUC_TYPE
|
||||
- XEP_0048.URL_TYPE
|
||||
- value (dict): data as for addBookmark
|
||||
- value (dict): data as for add_bookmark
|
||||
"""
|
||||
conf_data = {}
|
||||
url_data = {}
|
||||
|
|
@ -218,12 +218,12 @@ class XEP_0048(object):
|
|||
|
||||
return {XEP_0048.MUC_TYPE: conf_data, XEP_0048.URL_TYPE: url_data}
|
||||
|
||||
def _dict2BookmarkElt(self, type_, data):
|
||||
def _dict_2_bookmark_elt(self, type_, data):
|
||||
"""Construct a bookmark element from a data dict
|
||||
@param data (dict): bookmark data (key: bookmark type, value: list) where key can be:
|
||||
- XEP_0048.MUC_TYPE
|
||||
- XEP_0048.URL_TYPE
|
||||
- value (dict): data as for addBookmark
|
||||
- value (dict): data as for add_bookmark
|
||||
@return (domish.Element): bookmark element
|
||||
"""
|
||||
rooms_data = data.get(XEP_0048.MUC_TYPE, {})
|
||||
|
|
@ -253,7 +253,7 @@ class XEP_0048(object):
|
|||
|
||||
return storage_elt
|
||||
|
||||
def _bookmarkSelectedCb(self, data, profile):
|
||||
def _bookmark_selected_cb(self, data, profile):
|
||||
try:
|
||||
room_jid_s, nick = data["index"].split(" ", 1)
|
||||
room_jid = jid.JID(room_jid_s)
|
||||
|
|
@ -261,7 +261,7 @@ class XEP_0048(object):
|
|||
log.warning(_("No room jid selected"))
|
||||
return {}
|
||||
|
||||
client = self.host.getClient(profile)
|
||||
client = self.host.get_client(profile)
|
||||
d = self.host.plugins["XEP-0045"].join(client, room_jid, nick, {})
|
||||
|
||||
def join_eb(failure):
|
||||
|
|
@ -272,14 +272,14 @@ class XEP_0048(object):
|
|||
d.addCallbacks(lambda __: {}, join_eb)
|
||||
return d
|
||||
|
||||
def _bookmarksMenu(self, data, profile):
|
||||
def _bookmarks_menu(self, data, profile):
|
||||
""" XMLUI activated by menu: return Gateways UI
|
||||
@param profile: %(doc_profile)s
|
||||
|
||||
"""
|
||||
client = self.host.getClient(profile)
|
||||
client = self.host.get_client(profile)
|
||||
xmlui = xml_tools.XMLUI(title=_("Bookmarks manager"))
|
||||
adv_list = xmlui.changeContainer(
|
||||
adv_list = xmlui.change_container(
|
||||
"advanced_list",
|
||||
columns=3,
|
||||
selectable="single",
|
||||
|
|
@ -297,7 +297,7 @@ class XEP_0048(object):
|
|||
key=lambda item: item[1].get("name", item[0].user),
|
||||
):
|
||||
room_jid_s = room_jid.full()
|
||||
adv_list.setRowIndex(
|
||||
adv_list.set_row_index(
|
||||
"%s %s" % (room_jid_s, data.get("nick") or client.jid.user)
|
||||
)
|
||||
xmlui.addText(data.get("name", ""))
|
||||
|
|
@ -309,7 +309,7 @@ class XEP_0048(object):
|
|||
adv_list.end()
|
||||
xmlui.addDivider("dash")
|
||||
xmlui.addText(_("add a bookmark"))
|
||||
xmlui.changeContainer("pairs")
|
||||
xmlui.change_container("pairs")
|
||||
xmlui.addLabel(_("Name"))
|
||||
xmlui.addString("name")
|
||||
xmlui.addLabel(_("jid"))
|
||||
|
|
@ -318,22 +318,22 @@ class XEP_0048(object):
|
|||
xmlui.addString("nick", client.jid.user)
|
||||
xmlui.addLabel(_("Autojoin"))
|
||||
xmlui.addBool("autojoin")
|
||||
xmlui.changeContainer("vertical")
|
||||
xmlui.change_container("vertical")
|
||||
xmlui.addButton(self.__bm_save_id, _("Save"), ("name", "jid", "nick", "autojoin"))
|
||||
return {"xmlui": xmlui.toXml()}
|
||||
|
||||
def _bookmarksSaveCb(self, data, profile):
|
||||
bm_data = xml_tools.XMLUIResult2DataFormResult(data)
|
||||
def _bookmarks_save_cb(self, data, profile):
|
||||
bm_data = xml_tools.xmlui_result_2_data_form_result(data)
|
||||
try:
|
||||
location = jid.JID(bm_data.pop("jid"))
|
||||
except KeyError:
|
||||
raise exceptions.InternalError("Can't find mandatory key")
|
||||
d = self.addBookmark(XEP_0048.MUC_TYPE, location, bm_data, profile_key=profile)
|
||||
d = self.add_bookmark(XEP_0048.MUC_TYPE, location, bm_data, profile_key=profile)
|
||||
d.addCallback(lambda __: {})
|
||||
return d
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def addBookmark(
|
||||
def add_bookmark(
|
||||
self, type_, location, data, storage_type="auto", profile_key=C.PROF_KEY_NONE
|
||||
):
|
||||
"""Store a new bookmark
|
||||
|
|
@ -357,7 +357,7 @@ class XEP_0048(object):
|
|||
assert storage_type in ("auto", "pubsub", "private", "local")
|
||||
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.getClient(profile_key)
|
||||
client = self.host.get_client(profile_key)
|
||||
if storage_type == "auto":
|
||||
if client.bookmarks_pubsub is not None:
|
||||
storage_type = "pubsub"
|
||||
|
|
@ -372,13 +372,13 @@ class XEP_0048(object):
|
|||
client.bookmarks_local[type_][location] = data
|
||||
yield client.bookmarks_local.force(type_)
|
||||
else:
|
||||
bookmarks = yield self._getServerBookmarks(storage_type, client.profile)
|
||||
bookmarks = yield self._get_server_bookmarks(storage_type, client.profile)
|
||||
bookmarks[type_][location] = data
|
||||
bookmark_elt = self._dict2BookmarkElt(type_, bookmarks)
|
||||
yield self._setServerBookmarks(storage_type, bookmark_elt, client.profile)
|
||||
bookmark_elt = self._dict_2_bookmark_elt(type_, bookmarks)
|
||||
yield self._set_server_bookmarks(storage_type, bookmark_elt, client.profile)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def removeBookmark(
|
||||
def remove_bookmark(
|
||||
self, type_, location, storage_type="all", profile_key=C.PROF_KEY_NONE
|
||||
):
|
||||
"""Remove a stored bookmark
|
||||
|
|
@ -395,7 +395,7 @@ class XEP_0048(object):
|
|||
@param profile_key: %(doc_profile_key)s
|
||||
"""
|
||||
assert storage_type in ("all", "pubsub", "private", "local")
|
||||
client = self.host.getClient(profile_key)
|
||||
client = self.host.get_client(profile_key)
|
||||
|
||||
if storage_type in ("all", "local"):
|
||||
try:
|
||||
|
|
@ -405,18 +405,18 @@ class XEP_0048(object):
|
|||
log.debug("Bookmark is not present in local storage")
|
||||
|
||||
if storage_type in ("all", "private"):
|
||||
bookmarks = yield self._getServerBookmarks("private", client.profile)
|
||||
bookmarks = yield self._get_server_bookmarks("private", client.profile)
|
||||
try:
|
||||
del bookmarks[type_][location]
|
||||
bookmark_elt = self._dict2BookmarkElt(type_, bookmarks)
|
||||
yield self._setServerBookmarks("private", bookmark_elt, client.profile)
|
||||
bookmark_elt = self._dict_2_bookmark_elt(type_, bookmarks)
|
||||
yield self._set_server_bookmarks("private", bookmark_elt, client.profile)
|
||||
except KeyError:
|
||||
log.debug("Bookmark is not present in private storage")
|
||||
|
||||
if storage_type == "pubsub":
|
||||
raise NotImplementedError
|
||||
|
||||
def _bookmarksList(self, type_, storage_location, profile_key=C.PROF_KEY_NONE):
|
||||
def _bookmarks_list(self, type_, storage_location, profile_key=C.PROF_KEY_NONE):
|
||||
"""Return stored bookmarks
|
||||
|
||||
@param type_: bookmark type, one of:
|
||||
|
|
@ -431,11 +431,11 @@ class XEP_0048(object):
|
|||
@param return (dict): (key: storage_location, value dict) with:
|
||||
- value (dict): (key: bookmark_location, value: bookmark data)
|
||||
"""
|
||||
client = self.host.getClient(profile_key)
|
||||
client = self.host.get_client(profile_key)
|
||||
ret = {}
|
||||
ret_d = defer.succeed(ret)
|
||||
|
||||
def fillBookmarks(__, _storage_location):
|
||||
def fill_bookmarks(__, _storage_location):
|
||||
bookmarks_ori = getattr(client, "bookmarks_" + _storage_location)
|
||||
if bookmarks_ori is None:
|
||||
return ret
|
||||
|
|
@ -452,15 +452,15 @@ class XEP_0048(object):
|
|||
ret[_storage_location] = {}
|
||||
if _storage_location in ("private",):
|
||||
# we update distant bookmarks, just in case an other client added something
|
||||
d = self._getServerBookmarks(_storage_location, client.profile)
|
||||
d = self._get_server_bookmarks(_storage_location, client.profile)
|
||||
else:
|
||||
d = defer.succeed(None)
|
||||
d.addCallback(fillBookmarks, _storage_location)
|
||||
d.addCallback(fill_bookmarks, _storage_location)
|
||||
ret_d.addCallback(lambda __: d)
|
||||
|
||||
return ret_d
|
||||
|
||||
def _bookmarksRemove(
|
||||
def _bookmarks_remove(
|
||||
self, type_, location, storage_location, profile_key=C.PROF_KEY_NONE
|
||||
):
|
||||
"""Return stored bookmarks
|
||||
|
|
@ -478,14 +478,14 @@ class XEP_0048(object):
|
|||
"""
|
||||
if type_ == XEP_0048.MUC_TYPE:
|
||||
location = jid.JID(location)
|
||||
return self.removeBookmark(type_, location, storage_location, profile_key)
|
||||
return self.remove_bookmark(type_, location, storage_location, profile_key)
|
||||
|
||||
def _bookmarksAdd(
|
||||
def _bookmarks_add(
|
||||
self, type_, location, data, storage_type="auto", profile_key=C.PROF_KEY_NONE
|
||||
):
|
||||
if type_ == XEP_0048.MUC_TYPE:
|
||||
location = jid.JID(location)
|
||||
return self.addBookmark(type_, location, data, storage_type, profile_key)
|
||||
return self.add_bookmark(type_, location, data, storage_type, profile_key)
|
||||
|
||||
def cmd_bookmark(self, client, mess_data):
|
||||
"""(Un)bookmark a MUC room
|
||||
|
|
@ -498,14 +498,14 @@ class XEP_0048(object):
|
|||
|
||||
options = mess_data["unparsed"].strip().split()
|
||||
if options and options[0] not in ("autojoin", "remove"):
|
||||
txt_cmd.feedBack(client, _("Bad arguments"), mess_data)
|
||||
txt_cmd.feed_back(client, _("Bad arguments"), mess_data)
|
||||
return False
|
||||
|
||||
room_jid = mess_data["to"].userhostJID()
|
||||
|
||||
if "remove" in options:
|
||||
self.removeBookmark(XEP_0048.MUC_TYPE, room_jid, profile_key=client.profile)
|
||||
txt_cmd.feedBack(
|
||||
self.remove_bookmark(XEP_0048.MUC_TYPE, room_jid, profile_key=client.profile)
|
||||
txt_cmd.feed_back(
|
||||
client,
|
||||
_("All [%s] bookmarks are being removed") % room_jid.full(),
|
||||
mess_data,
|
||||
|
|
@ -517,7 +517,7 @@ class XEP_0048(object):
|
|||
"nick": client.jid.user,
|
||||
"autojoin": "true" if "autojoin" in options else "false",
|
||||
}
|
||||
self.addBookmark(XEP_0048.MUC_TYPE, room_jid, data, profile_key=client.profile)
|
||||
txt_cmd.feedBack(client, _("Bookmark added"), mess_data)
|
||||
self.add_bookmark(XEP_0048.MUC_TYPE, room_jid, data, profile_key=client.profile)
|
||||
txt_cmd.feed_back(client, _("Bookmark added"), mess_data)
|
||||
|
||||
return False
|
||||
|
|
|
|||
Loading…
Reference in a new issue