Mercurial > libervia-backend
comparison sat/plugins/plugin_xep_0376.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 | b7cef1b24f83 |
children |
comparison
equal
deleted
inserted
replaced
4036:c4464d7ae97b | 4037:524856bd7b19 |
---|---|
47 class XEP_0376: | 47 class XEP_0376: |
48 | 48 |
49 def __init__(self, host): | 49 def __init__(self, host): |
50 log.info(_("Pubsub Account Management initialization")) | 50 log.info(_("Pubsub Account Management initialization")) |
51 self.host = host | 51 self.host = host |
52 host.registerNamespace("pam", NS_PAM) | 52 host.register_namespace("pam", NS_PAM) |
53 self._p = self.host.plugins["XEP-0060"] | 53 self._p = self.host.plugins["XEP-0060"] |
54 host.trigger.add("XEP-0060_subscribe", self.subscribe) | 54 host.trigger.add("XEP-0060_subscribe", self.subscribe) |
55 host.trigger.add("XEP-0060_unsubscribe", self.unsubscribe) | 55 host.trigger.add("XEP-0060_unsubscribe", self.unsubscribe) |
56 host.trigger.add("XEP-0060_subscriptions", self.subscriptions) | 56 host.trigger.add("XEP-0060_subscriptions", self.subscriptions) |
57 | 57 |
58 def getHandler(self, client): | 58 def get_handler(self, client): |
59 return XEP_0376_Handler() | 59 return XEP_0376_Handler() |
60 | 60 |
61 async def profileConnected(self, client): | 61 async def profile_connected(self, client): |
62 if not self.host.hasFeature(client, NS_PAM): | 62 if not self.host.hasFeature(client, NS_PAM): |
63 log.warning( | 63 log.warning( |
64 "Your server doesn't support Pubsub Account Management, this is used to " | 64 "Your server doesn't support Pubsub Account Management, this is used to " |
65 "track all your subscriptions. You may ask your server administrator to " | 65 "track all your subscriptions. You may ask your server administrator to " |
66 "install it." | 66 "install it." |
67 ) | 67 ) |
68 | 68 |
69 async def _subRequest( | 69 async def _sub_request( |
70 self, | 70 self, |
71 client: SatXMPPEntity, | 71 client: SatXMPPEntity, |
72 service: jid.JID, | 72 service: jid.JID, |
73 nodeIdentifier: str, | 73 nodeIdentifier: str, |
74 sub_jid: Optional[jid.JID], | 74 sub_jid: Optional[jid.JID], |
107 options: Optional[dict] = None | 107 options: Optional[dict] = None |
108 ) -> Tuple[bool, Optional[pubsub.Subscription]]: | 108 ) -> Tuple[bool, Optional[pubsub.Subscription]]: |
109 if not self.host.hasFeature(client, NS_PAM) or client.is_component: | 109 if not self.host.hasFeature(client, NS_PAM) or client.is_component: |
110 return True, None | 110 return True, None |
111 | 111 |
112 await self._subRequest(client, service, nodeIdentifier, sub_jid, options, True) | 112 await self._sub_request(client, service, nodeIdentifier, sub_jid, options, True) |
113 | 113 |
114 # TODO: actual result is sent with <message> stanza, we have to get and use them | 114 # TODO: actual result is sent with <message> stanza, we have to get and use them |
115 # to known the actual result. XEP-0376 returns an empty <iq> result, thus we don't | 115 # to known the actual result. XEP-0376 returns an empty <iq> result, thus we don't |
116 # know here is the subscription actually succeeded | 116 # know here is the subscription actually succeeded |
117 | 117 |
128 subscriptionIdentifier: Optional[str], | 128 subscriptionIdentifier: Optional[str], |
129 sender: Optional[jid.JID] = None, | 129 sender: Optional[jid.JID] = None, |
130 ) -> bool: | 130 ) -> bool: |
131 if not self.host.hasFeature(client, NS_PAM) or client.is_component: | 131 if not self.host.hasFeature(client, NS_PAM) or client.is_component: |
132 return True | 132 return True |
133 await self._subRequest(client, service, nodeIdentifier, sub_jid, None, False) | 133 await self._sub_request(client, service, nodeIdentifier, sub_jid, None, False) |
134 return False | 134 return False |
135 | 135 |
136 async def subscriptions( | 136 async def subscriptions( |
137 self, | 137 self, |
138 client: SatXMPPEntity, | 138 client: SatXMPPEntity, |