diff sat/plugins/plugin_xep_0300.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 40d47cc29ea4
children
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0300.py	Fri Apr 07 15:18:39 2023 +0200
+++ b/sat/plugins/plugin_xep_0300.py	Sat Apr 08 13:54:42 2023 +0200
@@ -68,12 +68,12 @@
 
     def __init__(self, host):
         log.info(_("plugin Hashes initialization"))
-        host.registerNamespace("hashes", NS_HASHES)
+        host.register_namespace("hashes", NS_HASHES)
 
-    def getHandler(self, client):
+    def get_handler(self, client):
         return XEP_0300_handler()
 
-    def getHasher(self, algo=ALGO_DEFAULT):
+    def get_hasher(self, algo=ALGO_DEFAULT):
         """Return hasher instance
 
         @param algo(unicode): one of the XEP_300.ALGOS keys
@@ -83,11 +83,11 @@
         """
         return self.ALGOS[algo]()
 
-    def getDefaultAlgo(self):
+    def get_default_algo(self):
         return ALGO_DEFAULT
 
     @defer.inlineCallbacks
-    def getBestPeerAlgo(self, to_jid, profile):
+    def get_best_peer_algo(self, to_jid, profile):
         """Return the best available hashing algorith of other peer
 
          @param to_jid(jid.JID): peer jid
@@ -95,7 +95,7 @@
          @return (D(unicode, None)): best available algorithm,
             or None if hashing is not possible
         """
-        client = self.host.getClient(profile)
+        client = self.host.get_client(profile)
         for algo in reversed(XEP_0300.ALGOS):
             has_feature = yield self.host.hasFeature(
                 client, NS_HASHES_FUNCTIONS.format(algo), to_jid
@@ -108,10 +108,10 @@
                 )
                 defer.returnValue(algo)
 
-    def _calculateHashBlocking(self, file_obj, hasher):
+    def _calculate_hash_blocking(self, file_obj, hasher):
         """Calculate hash in a blocking way
 
-        /!\\ blocking method, please use calculateHash instead
+        /!\\ blocking method, please use calculate_hash instead
         @param file_obj(file): a file-like object
         @param hasher(hash object): the method to call to initialise hash object
         @return (str): the hex digest of the hash
@@ -123,10 +123,10 @@
             hasher.update(buf)
         return hasher.hexdigest()
 
-    def calculateHash(self, file_obj, hasher):
-        return threads.deferToThread(self._calculateHashBlocking, file_obj, hasher)
+    def calculate_hash(self, file_obj, hasher):
+        return threads.deferToThread(self._calculate_hash_blocking, file_obj, hasher)
 
-    def calculateHashElt(self, file_obj=None, algo=ALGO_DEFAULT):
+    def calculate_hash_elt(self, file_obj=None, algo=ALGO_DEFAULT):
         """Compute hash and build hash element
 
         @param file_obj(file, None): file-like object to use to calculate the hash
@@ -134,20 +134,20 @@
         @return (D(domish.Element)): hash element
         """
 
-        def hashCalculated(hash_):
-            return self.buildHashElt(hash_, algo)
+        def hash_calculated(hash_):
+            return self.build_hash_elt(hash_, algo)
 
-        hasher = self.getHasher(algo)
-        hash_d = self.calculateHash(file_obj, hasher)
-        hash_d.addCallback(hashCalculated)
+        hasher = self.get_hasher(algo)
+        hash_d = self.calculate_hash(file_obj, hasher)
+        hash_d.addCallback(hash_calculated)
         return hash_d
 
-    def buildHashUsedElt(self, algo=ALGO_DEFAULT):
+    def build_hash_used_elt(self, algo=ALGO_DEFAULT):
         hash_used_elt = domish.Element((NS_HASHES, "hash-used"))
         hash_used_elt["algo"] = algo
         return hash_used_elt
 
-    def parseHashUsedElt(self, parent):
+    def parse_hash_used_elt(self, parent):
         """Find and parse a hash-used element
 
         @param (domish.Element): parent of <hash/> element
@@ -164,7 +164,7 @@
             raise exceptions.DataError
         return algo
 
-    def buildHashElt(self, hash_, algo=ALGO_DEFAULT):
+    def build_hash_elt(self, hash_, algo=ALGO_DEFAULT):
         """Compute hash and build hash element
 
         @param hash_(str): hash to use
@@ -180,7 +180,7 @@
         hash_elt["algo"] = algo
         return hash_elt
 
-    def parseHashElt(self, parent: domish.Element) -> Tuple[str, bytes]:
+    def parse_hash_elt(self, parent: domish.Element) -> Tuple[str, bytes]:
         """Find and parse a hash element
 
         if multiple elements are found, the strongest managed one is returned