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

@ -208,16 +208,16 @@ class PubsubLists:
log.info(_("Pubsub lists plugin initialization"))
self.host = host
self._s = self.host.plugins["XEP-0346"]
self.namespace = self._s.getSubmittedNS(APP_NS_TICKETS)
host.registerNamespace("tickets", APP_NS_TICKETS)
host.registerNamespace("tickets_type", NS_TICKETS_TYPE)
self.namespace = self._s.get_submitted_ns(APP_NS_TICKETS)
host.register_namespace("tickets", APP_NS_TICKETS)
host.register_namespace("tickets_type", NS_TICKETS_TYPE)
self.host.plugins["PUBSUB_INVITATION"].register(
APP_NS_TICKETS, self
)
self._p = self.host.plugins["XEP-0060"]
self._m = self.host.plugins["XEP-0277"]
host.bridge.addMethod(
"listGet",
host.bridge.add_method(
"list_get",
".plugin",
in_sign="ssiassss",
out_sign="s",
@ -232,68 +232,68 @@ class PubsubLists:
default_node=self.namespace,
form_ns=APP_NS_TICKETS,
filters={
"author": self._s.valueOrPublisherFilter,
"created": self._s.dateFilter,
"updated": self._s.dateFilter,
"time_limit": self._s.dateFilter,
"author": self._s.value_or_publisher_filter,
"created": self._s.date_filter,
"updated": self._s.date_filter,
"time_limit": self._s.date_filter,
},
profile_key=profile_key),
async_=True,
)
host.bridge.addMethod(
"listSet",
host.bridge.add_method(
"list_set",
".plugin",
in_sign="ssa{sas}ssss",
out_sign="s",
method=self._set,
async_=True,
)
host.bridge.addMethod(
"listDeleteItem",
host.bridge.add_method(
"list_delete_item",
".plugin",
in_sign="sssbs",
out_sign="",
method=self._delete,
async_=True,
)
host.bridge.addMethod(
"listSchemaGet",
host.bridge.add_method(
"list_schema_get",
".plugin",
in_sign="sss",
out_sign="s",
method=lambda service, nodeIdentifier, profile_key: self._s._getUISchema(
method=lambda service, nodeIdentifier, profile_key: self._s._get_ui_schema(
service, nodeIdentifier, default_node=self.namespace,
profile_key=profile_key),
async_=True,
)
host.bridge.addMethod(
"listsList",
host.bridge.add_method(
"lists_list",
".plugin",
in_sign="sss",
out_sign="s",
method=self._listsList,
method=self._lists_list,
async_=True,
)
host.bridge.addMethod(
"listTemplatesNamesGet",
host.bridge.add_method(
"list_templates_names_get",
".plugin",
in_sign="ss",
out_sign="s",
method=self._getTemplatesNames,
method=self._get_templates_names,
)
host.bridge.addMethod(
"listTemplateGet",
host.bridge.add_method(
"list_template_get",
".plugin",
in_sign="sss",
out_sign="s",
method=self._getTemplate,
method=self._get_template,
)
host.bridge.addMethod(
"listTemplateCreate",
host.bridge.add_method(
"list_template_create",
".plugin",
in_sign="ssss",
out_sign="(ss)",
method=self._createTemplate,
method=self._create_template,
async_=True,
)
@ -309,7 +309,7 @@ class PubsubLists:
item_elt: domish.Element
) -> None:
try:
schema = await self._s.getSchemaForm(client, service, node)
schema = await self._s.get_schema_form(client, service, node)
except Exception as e:
log.warning(f"Can't retrive node schema as {node!r} [{service}]: {e}")
else:
@ -323,7 +323,7 @@ class PubsubLists:
def _set(self, service, node, values, schema=None, item_id=None, extra_s='',
profile_key=C.PROF_KEY_NONE):
client, service, node, schema, item_id, extra = self._s.prepareBridgeSet(
client, service, node, schema, item_id, extra = self._s.prepare_bridge_set(
service, node, schema, item_id, extra_s, profile_key
)
d = defer.ensureDeferred(self.set(
@ -346,22 +346,22 @@ class PubsubLists:
'created' and 'updated' will be forced to current time:
- 'created' is set if item_id is None, i.e. if it's a new ticket
- 'updated' is set everytime
@param extra(dict, None): same as for [XEP-0060.sendItem] with additional keys:
@param extra(dict, None): same as for [XEP-0060.send_item] with additional keys:
- update(bool): if True, get previous item data to merge with current one
if True, item_id must be set
other arguments are same as for [self._s.sendDataFormItem]
other arguments are same as for [self._s.send_data_form_item]
@return (unicode): id of the created item
"""
if not node:
node = self.namespace
if not item_id:
comments_service = await self._m.getCommentsService(client, service)
comments_service = await self._m.get_comments_service(client, service)
# we need to use uuid for comments node, because we don't know item id in
# advance (we don't want to set it ourselves to let the server choose, so we
# can have a nicer id if serial ids is activated)
comments_node = self._m.getCommentsNode(
comments_node = self._m.get_comments_node(
node + "_" + str(shortuuid.uuid())
)
options = {
@ -372,7 +372,7 @@ class PubsubLists:
self._p.OPT_PUBLISH_MODEL: self._p.ACCESS_OPEN,
}
await self._p.createNode(client, comments_service, comments_node, options)
values["comments_uri"] = uri.buildXMPPUri(
values["comments_uri"] = uri.build_xmpp_uri(
"pubsub",
subtype="microblog",
path=comments_service.full(),
@ -386,7 +386,7 @@ class PubsubLists:
def _delete(
self, service_s, nodeIdentifier, itemIdentifier, notify, profile_key
):
client = self.host.getClient(profile_key)
client = self.host.get_client(profile_key)
return defer.ensureDeferred(self.delete(
client,
jid.JID(service_s) if service_s else None,
@ -405,26 +405,26 @@ class PubsubLists:
) -> None:
if not node:
node = self.namespace
return await self._p.retractItems(
return await self._p.retract_items(
service, node, (itemIdentifier,), notify, client.profile
)
def _listsList(self, service, node, profile):
def _lists_list(self, service, node, profile):
service = jid.JID(service) if service else None
node = node or None
client = self.host.getClient(profile)
d = defer.ensureDeferred(self.listsList(client, service, node))
client = self.host.get_client(profile)
d = defer.ensureDeferred(self.lists_list(client, service, node))
d.addCallback(data_format.serialise)
return d
async def listsList(
async def lists_list(
self, client, service: Optional[jid.JID], node: Optional[str]=None
) -> List[dict]:
"""Retrieve list of pubsub lists registered in personal interests
@return list: list of lists metadata
"""
items, metadata = await self.host.plugins['LIST_INTEREST'].listInterests(
items, metadata = await self.host.plugins['LIST_INTEREST'].list_interests(
client, service, node, namespace=APP_NS_TICKETS)
lists = []
for item in items:
@ -454,34 +454,34 @@ class PubsubLists:
return lists
def _getTemplatesNames(self, language, profile):
client = self.host.getClient(profile)
return data_format.serialise(self.getTemplatesNames(client, language))
def _get_templates_names(self, language, profile):
client = self.host.get_client(profile)
return data_format.serialise(self.get_templates_names(client, language))
def getTemplatesNames(self, client, language: str) -> list:
def get_templates_names(self, client, language: str) -> list:
"""Retrieve well known list templates"""
templates = [{"id": tpl_id, "name": d["name"], "icon": d["icon"]}
for tpl_id, d in TEMPLATES.items()]
return templates
def _getTemplate(self, name, language, profile):
client = self.host.getClient(profile)
return data_format.serialise(self.getTemplate(client, name, language))
def _get_template(self, name, language, profile):
client = self.host.get_client(profile)
return data_format.serialise(self.get_template(client, name, language))
def getTemplate(self, client, name: str, language: str) -> dict:
def get_template(self, client, name: str, language: str) -> dict:
"""Retrieve a well known template"""
return TEMPLATES[name]
def _createTemplate(self, template_id, name, access_model, profile):
client = self.host.getClient(profile)
d = defer.ensureDeferred(self.createTemplate(
def _create_template(self, template_id, name, access_model, profile):
client = self.host.get_client(profile)
d = defer.ensureDeferred(self.create_template(
client, template_id, name, access_model
))
d.addCallback(lambda node_data: (node_data[0].full(), node_data[1]))
return d
async def createTemplate(
async def create_template(
self, client, template_id: str, name: str, access_model: str
) -> Tuple[jid.JID, str]:
"""Create a list from a template"""
@ -493,12 +493,12 @@ class PubsubLists:
0,
{"type": "hidden", "name": NS_TICKETS_TYPE, "value": template_id}
)
schema = xml_tools.dataDict2dataForm(
schema = xml_tools.data_dict_2_data_form(
{"namespace": APP_NS_TICKETS, "fields": fields}
).toElement()
service = client.jid.userhostJID()
node = self._s.getSubmittedNS(f"{APP_NS_TICKETS}_{name}")
node = self._s.get_submitted_ns(f"{APP_NS_TICKETS}_{name}")
options = {
self._p.OPT_ACCESS_MODEL: access_model,
}
@ -507,11 +507,11 @@ class PubsubLists:
# XXX: should node options be in TEMPLATE?
options[self._p.OPT_OVERWRITE_POLICY] = self._p.OWPOL_ANY_PUB
await self._p.createNode(client, service, node, options)
await self._s.setSchema(client, service, node, schema)
await self._s.set_schema(client, service, node, schema)
list_elt = domish.Element((APP_NS_TICKETS, "list"))
list_elt["type"] = template_id
try:
await self.host.plugins['LIST_INTEREST'].registerPubsub(
await self.host.plugins['LIST_INTEREST'].register_pubsub(
client, APP_NS_TICKETS, service, node, creator=True,
name=name, element=list_elt)
except Exception as e: