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:
Goffi 2023-04-08 13:54:42 +02:00
commit 6a6f15707a

View file

@ -62,26 +62,26 @@ class forums(object):
self._p.OPT_SEND_ITEM_SUBSCRIBE: 1,
self._p.OPT_PUBLISH_MODEL: self._p.ACCESS_OPEN,
}
host.registerNamespace('forums', NS_FORUMS)
host.bridge.addMethod("forumsGet", ".plugin",
host.register_namespace('forums', NS_FORUMS)
host.bridge.add_method("forums_get", ".plugin",
in_sign='ssss', out_sign='s',
method=self._get,
async_=True)
host.bridge.addMethod("forumsSet", ".plugin",
host.bridge.add_method("forums_set", ".plugin",
in_sign='sssss', out_sign='',
method=self._set,
async_=True)
host.bridge.addMethod("forumTopicsGet", ".plugin",
host.bridge.add_method("forum_topics_get", ".plugin",
in_sign='ssa{ss}s', out_sign='(aa{ss}s)',
method=self._getTopics,
method=self._get_topics,
async_=True)
host.bridge.addMethod("forumTopicCreate", ".plugin",
host.bridge.add_method("forum_topic_create", ".plugin",
in_sign='ssa{ss}s', out_sign='',
method=self._createTopic,
method=self._create_topic,
async_=True)
@defer.inlineCallbacks
def _createForums(self, client, forums, service, node, forums_elt=None, names=None):
def _create_forums(self, client, forums, service, node, forums_elt=None, names=None):
"""Recursively create <forums> element(s)
@param forums(list): forums which may have subforums
@ -115,7 +115,7 @@ class forums(object):
log.info(_("creating missing forum node"))
forum_node = FORUM_TOPICS_NODE_TPL.format(node=node, uuid=shortuuid.uuid())
yield self._p.createNode(client, service, forum_node, self._node_options)
value = uri.buildXMPPUri('pubsub',
value = uri.build_xmpp_uri('pubsub',
path=service.full(),
node=forum_node)
if key in FORUM_ATTR:
@ -124,7 +124,7 @@ class forums(object):
forum_elt.addElement(key, content=value)
elif key == 'sub-forums':
sub_forums_elt = forum_elt.addElement('forums')
yield self._createForums(client, value, service, node, sub_forums_elt, names=names)
yield self._create_forums(client, value, service, node, sub_forums_elt, names=names)
else:
log.warning(_("Unknown forum attribute: {key}").format(key=key))
if not forum_elt.getAttribute('title'):
@ -137,7 +137,7 @@ class forums(object):
raise ValueError(_("forum need uri or sub-forums"))
defer.returnValue(forums_elt)
def _parseForums(self, parent_elt=None, forums=None):
def _parse_forums(self, parent_elt=None, forums=None):
"""Recursivly parse a <forums> elements and return corresponding forums data
@param item(domish.Element): item with <forums> element
@ -170,7 +170,7 @@ class forums(object):
data[elt.name] = str(elt)
elif elt.name == 'forums':
sub_forums = data['sub-forums'] = []
self._parseForums(elt, sub_forums)
self._parse_forums(elt, sub_forums)
if not 'title' in data or not {'uri', 'sub-forums'}.intersection(data):
log.warning(_("invalid forum, ignoring: {xml}").format(xml=forum_elt.toXml()))
else:
@ -181,7 +181,7 @@ class forums(object):
return forums
def _get(self, service=None, node=None, forums_key=None, profile_key=C.PROF_KEY_NONE):
client = self.host.getClient(profile_key)
client = self.host.get_client(profile_key)
if service.strip():
service = jid.JID(service)
else:
@ -199,14 +199,14 @@ class forums(object):
node = NS_FORUMS
if forums_key is None:
forums_key = 'default'
items_data = await self._p.getItems(client, service, node, item_ids=[forums_key])
items_data = await self._p.get_items(client, service, node, item_ids=[forums_key])
item = items_data[0][0]
# we have the item and need to convert it to json
forums = self._parseForums(item)
forums = self._parse_forums(item)
return forums
def _set(self, forums, service=None, node=None, forums_key=None, profile_key=C.PROF_KEY_NONE):
client = self.host.getClient(profile_key)
client = self.host.get_client(profile_key)
forums = json.loads(forums)
if service.strip():
service = jid.JID(service)
@ -241,16 +241,16 @@ class forums(object):
node = NS_FORUMS
if forums_key is None:
forums_key = 'default'
forums_elt = await self._createForums(client, forums, service, node)
return await self._p.sendItem(
forums_elt = await self._create_forums(client, forums, service, node)
return await self._p.send_item(
client, service, node, forums_elt, item_id=forums_key
)
def _getTopics(self, service, node, extra=None, profile_key=C.PROF_KEY_NONE):
client = self.host.getClient(profile_key)
extra = self._p.parseExtra(extra)
def _get_topics(self, service, node, extra=None, profile_key=C.PROF_KEY_NONE):
client = self.host.get_client(profile_key)
extra = self._p.parse_extra(extra)
d = defer.ensureDeferred(
self.getTopics(
self.get_topics(
client, jid.JID(service), node, rsm_request=extra.rsm_request,
extra=extra.extra
)
@ -260,12 +260,12 @@ class forums(object):
)
return d
async def getTopics(self, client, service, node, rsm_request=None, extra=None):
async def get_topics(self, client, service, node, rsm_request=None, extra=None):
"""Retrieve topics data
Topics are simple microblog URIs with some metadata duplicated from first post
"""
topics_data = await self._p.getItems(
topics_data = await self._p.get_items(
client, service, node, rsm_request=rsm_request, extra=extra
)
topics = []
@ -279,13 +279,13 @@ class forums(object):
topics.append(topic)
return (topics, metadata)
def _createTopic(self, service, node, mb_data, profile_key):
client = self.host.getClient(profile_key)
def _create_topic(self, service, node, mb_data, profile_key):
client = self.host.get_client(profile_key)
return defer.ensureDeferred(
self.createTopic(client, jid.JID(service), node, mb_data)
self.create_topic(client, jid.JID(service), node, mb_data)
)
async def createTopic(self, client, service, node, mb_data):
async def create_topic(self, client, service, node, mb_data):
try:
title = mb_data['title']
content = mb_data.pop('content')
@ -296,7 +296,7 @@ class forums(object):
topic_node = FORUM_TOPIC_NODE_TPL.format(node=node, uuid=shortuuid.uuid())
await self._p.createNode(client, service, topic_node, self._node_options)
await self._m.send(client, mb_data, service, topic_node)
topic_uri = uri.buildXMPPUri('pubsub',
topic_uri = uri.build_xmpp_uri('pubsub',
subtype='microblog',
path=service.full(),
node=topic_node)
@ -304,4 +304,4 @@ class forums(object):
topic_elt['uri'] = topic_uri
topic_elt['author'] = client.jid.userhost()
topic_elt.addElement('title', content = title)
await self._p.sendItem(client, service, node, topic_elt)
await self._p.send_item(client, service, node, topic_elt)