Mercurial > libervia-backend
diff sat/plugins/plugin_xep_0092.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 | be6d91572633 |
children | e75827204fe0 |
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0092.py Fri Apr 07 15:18:39 2023 +0200 +++ b/sat/plugins/plugin_xep_0092.py Sat Apr 08 13:54:42 2023 +0200 @@ -47,29 +47,29 @@ def __init__(self, host): log.info(_("Plugin XEP_0092 initialization")) self.host = host - host.bridge.addMethod( - "getSoftwareVersion", + host.bridge.add_method( + "software_version_get", ".plugin", in_sign="ss", out_sign="(sss)", - method=self._getVersion, + method=self._get_version, async_=True, ) try: - self.host.plugins[C.TEXT_CMDS].addWhoIsCb(self._whois, 50) + self.host.plugins[C.TEXT_CMDS].add_who_is_cb(self._whois, 50) except KeyError: log.info(_("Text commands not available")) - def _getVersion(self, entity_jid_s, profile_key): - def prepareForBridge(data): + def _get_version(self, entity_jid_s, profile_key): + def prepare_for_bridge(data): name, version, os = data return (name or "", version or "", os or "") - d = self.getVersion(jid.JID(entity_jid_s), profile_key) - d.addCallback(prepareForBridge) + d = self.version_get(jid.JID(entity_jid_s), profile_key) + d.addCallback(prepare_for_bridge) return d - def getVersion(self, jid_, profile_key=C.PROF_KEY_NONE): + def version_get(self, jid_, profile_key=C.PROF_KEY_NONE): """ Ask version of the client that jid_ is running @param jid_: jid from who we want to know client's version @param profile_key: %(doc_profile_key)s @@ -78,24 +78,24 @@ - version: specific version of the software - os: operating system of the queried entity """ - client = self.host.getClient(profile_key) + client = self.host.get_client(profile_key) - def getVersion(__): + def version_get(__): iq_elt = compat.IQ(client.xmlstream, "get") iq_elt["to"] = jid_.full() iq_elt.addElement("query", NS_VERSION) d = iq_elt.send() - d.addCallback(self._gotVersion) + d.addCallback(self._got_version) return d - d = self.host.checkFeature(client, NS_VERSION, jid_) - d.addCallback(getVersion) + d = self.host.check_feature(client, NS_VERSION, jid_) + d.addCallback(version_get) reactor.callLater( TIMEOUT, d.cancel ) # XXX: timeout needed because some clients don't answer the IQ return d - def _gotVersion(self, iq_elt): + def _got_version(self, iq_elt): try: query_elt = next(iq_elt.elements(NS_VERSION, "query")) except StopIteration: @@ -113,7 +113,7 @@ def _whois(self, client, whois_msg, mess_data, target_jid): """ Add software/OS information to whois """ - def versionCb(version_data): + def version_cb(version_data): name, version, os = version_data if name: whois_msg.append(_("Client name: %s") % name) @@ -122,13 +122,13 @@ if os: whois_msg.append(_("Operating system: %s") % os) - def versionEb(failure): + def version_eb(failure): failure.trap(exceptions.FeatureNotFound, defer.CancelledError) if failure.check(failure, exceptions.FeatureNotFound): whois_msg.append(_("Software version not available")) else: whois_msg.append(_("Client software version request timeout")) - d = self.getVersion(target_jid, client.profile) - d.addCallbacks(versionCb, versionEb) + d = self.version_get(target_jid, client.profile) + d.addCallbacks(version_cb, version_eb) return d