Mercurial > libervia-backend
diff sat/plugins/plugin_xep_0465.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 | 56e5b18f4d06 |
children |
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0465.py Fri Apr 07 15:18:39 2023 +0200 +++ b/sat/plugins/plugin_xep_0465.py Sat Apr 08 13:54:42 2023 +0200 @@ -61,34 +61,34 @@ def __init__(self, host): log.info(_("Pubsub Public Subscriptions initialization")) - host.registerNamespace("pps", NS_PPS) + host.register_namespace("pps", NS_PPS) self.host = host - host.bridge.addMethod( - "psPublicSubscriptionsGet", + host.bridge.add_method( + "ps_public_subscriptions_get", ".plugin", in_sign="sss", out_sign="s", method=self._subscriptions, async_=True, ) - host.bridge.addMethod( - "psPublicSubscriptionsGet", + host.bridge.add_method( + "ps_public_subscriptions_get", ".plugin", in_sign="sss", out_sign="s", method=self._subscriptions, async_=True, ) - host.bridge.addMethod( - "psPublicNodeSubscriptionsGet", + host.bridge.add_method( + "ps_public_node_subscriptions_get", ".plugin", in_sign="sss", out_sign="a{ss}", - method=self._getPublicNodeSubscriptions, + method=self._get_public_node_subscriptions, async_=True, ) - def getHandler(self, client): + def get_handler(self, client): return XEP_0465_Handler() @property @@ -99,7 +99,7 @@ def subscribers_node_prefix(self) -> str: return SUBSCRIBERS_NODE_PREFIX - def buildSubscriptionElt(self, node: str, service: jid.JID) -> domish.Element: + def build_subscription_elt(self, node: str, service: jid.JID) -> domish.Element: """Generate a <subscriptions> element This is the element that a service returns on public subscriptions request @@ -109,7 +109,7 @@ subscription_elt["service"] = service.full() return subscription_elt - def buildSubscriberElt(self, subscriber: jid.JID) -> domish.Element: + def build_subscriber_elt(self, subscriber: jid.JID) -> domish.Element: """Generate a <subscriber> element This is the element that a service returns on node public subscriptions request @@ -125,7 +125,7 @@ nodeIdentifier="", profile_key=C.PROF_KEY_NONE ) -> str: - client = self.host.getClient(profile_key) + client = self.host.get_client(profile_key) service = None if not service else jid.JID(service) subs = await self.subscriptions(client, service, nodeIdentifier or None) return data_format.serialise(subs) @@ -145,7 +145,7 @@ if service is None: service = client.jid.userhostJID() try: - items, __ = await self.host.plugins["XEP-0060"].getItems( + items, __ = await self.host.plugins["XEP-0060"].get_items( client, service, NS_PPS_SUBSCRIPTIONS ) except error.StanzaError as e: @@ -182,23 +182,23 @@ return ret @utils.ensure_deferred - async def _getPublicNodeSubscriptions( + async def _get_public_node_subscriptions( self, service: str, node: str, profile_key: str ) -> Dict[str, str]: - client = self.host.getClient(profile_key) - subs = await self.getPublicNodeSubscriptions( + client = self.host.get_client(profile_key) + subs = await self.get_public_node_subscriptions( client, jid.JID(service) if service else None, node ) return {j.full(): a for j, a in subs.items()} - def getPublicSubscribersNode(self, node: str) -> str: + def get_public_subscribers_node(self, node: str) -> str: """Return prefixed node to retrieve public subscribers""" return f"{NS_PPS_SUBSCRIBERS}/{node}" - async def getPublicNodeSubscriptions( + async def get_public_node_subscriptions( self, client: SatXMPPEntity, service: Optional[jid.JID], @@ -214,10 +214,10 @@ if service is None: service = client.jid.userhostJID() - subscribers_node = self.getPublicSubscribersNode(nodeIdentifier) + subscribers_node = self.get_public_subscribers_node(nodeIdentifier) try: - items, __ = await self.host.plugins["XEP-0060"].getItems( + items, __ = await self.host.plugins["XEP-0060"].get_items( client, service, subscribers_node ) except error.StanzaError as e: @@ -243,7 +243,7 @@ continue return ret - def setPublicOpt(self, options: Optional[dict] = None) -> dict: + def set_public_opt(self, options: Optional[dict] = None) -> dict: """Set option to make a subscription public @param options: dict where the option must be set