Mercurial > libervia-backend
diff sat/plugins/plugin_exp_invitation_pubsub.py @ 4037:524856bd7b19
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.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 08 Apr 2023 13:54:42 +0200 |
parents | 26c3e1bc7fb7 |
children |
line wrap: on
line diff
--- a/sat/plugins/plugin_exp_invitation_pubsub.py Fri Apr 07 15:18:39 2023 +0200 +++ b/sat/plugins/plugin_exp_invitation_pubsub.py Sat Apr 08 13:54:42 2023 +0200 @@ -51,12 +51,12 @@ self._p = host.plugins["XEP-0060"] # namespace to handler map self._ns_handler = {} - host.bridge.addMethod( - "psInvite", + host.bridge.add_method( + "ps_invite", ".plugin", in_sign="sssssss", out_sign="", - method=self._sendPubsubInvitation, + method=self._send_pubsub_invitation, async_=True ) @@ -66,12 +66,12 @@ handler ) -> None: self._ns_handler[namespace] = handler - self.host.plugins["INVITATION"].registerNamespace(namespace, self.onInvitation) + self.host.plugins["INVITATION"].register_namespace(namespace, self.on_invitation) - def _sendPubsubInvitation( + def _send_pubsub_invitation( self, invitee_jid_s, service_s, node, item_id=None, name=None, extra_s='', profile_key=C.PROF_KEY_NONE): - client = self.host.getClient(profile_key) + client = self.host.get_client(profile_key) invitee_jid = jid.JID(invitee_jid_s) service = jid.JID(service_s) extra = data_format.deserialise(extra_s) @@ -104,13 +104,13 @@ if namespace: try: handler = self._ns_handler[namespace] - preflight = handler.invitePreflight + preflight = handler.invite_preflight except KeyError: pass except AttributeError: - log.debug(f"no invitePreflight method found for {namespace!r}") + log.debug(f"no invite_preflight method found for {namespace!r}") else: - await utils.asDeferred( + await utils.as_deferred( preflight, client, invitee_jid, service, node, item_id, name, extra ) @@ -118,11 +118,11 @@ item_id = extra.pop("default_item_id", None) # we authorize our invitee to see the nodes of interest - await self._p.setNodeAffiliations(client, service, node, {invitee_jid: "member"}) + await self._p.set_node_affiliations(client, service, node, {invitee_jid: "member"}) log.debug(f"affiliation set on {service}'s {node!r} node") # now we send the invitation - self.host.plugins["INVITATION"].sendPubsubInvitation( + self.host.plugins["INVITATION"].send_pubsub_invitation( client, invitee_jid, service, @@ -132,7 +132,7 @@ extra=extra ) - async def onInvitation( + async def on_invitation( self, client: SatXMPPEntity, namespace: str, @@ -153,7 +153,7 @@ except AttributeError: log.debug(f"no on_invitation_preflight method found for {namespace!r}") else: - await utils.asDeferred( + await utils.as_deferred( preflight, client, namespace, name, extra, service, node, item_id, item_elt ) @@ -164,6 +164,6 @@ if not name: name = extra.pop("name", "") - return await self.host.plugins['LIST_INTEREST'].registerPubsub( + return await self.host.plugins['LIST_INTEREST'].register_pubsub( client, namespace, service, node, item_id, creator, name, element, extra)