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.
This commit is contained in:
Goffi 2023-04-08 13:54:42 +02:00
commit 6a6f15707a

View file

@ -74,7 +74,7 @@ class XEP_0448:
def __init__(self, host):
self.host = host
log.info(_("XEP_0448 plugin initialization"))
host.registerNamespace("esfs", NS_ESFS)
host.register_namespace("esfs", NS_ESFS)
self._u = host.plugins["XEP-0103"]
self._h = host.plugins["XEP-0300"]
self._hints = host.plugins["XEP-0334"]
@ -92,7 +92,7 @@ class XEP_0448:
host.trigger.add("XEP-0363_upload_pre_slot", self._upload_pre_slot)
host.trigger.add("XEP-0363_upload", self._upload_trigger)
def getHandler(self, client):
def get_handler(self, client):
return XEP0448Handler()
def parse_encrypted_elt(self, encrypted_elt: domish.Element) -> Dict[str, Any]:
@ -123,7 +123,7 @@ class XEP_0448:
"invalid <encrypted/> element: {encrypted_elt.toXml()}"
)
try:
hash_algo, hash_value = self._h.parseHashElt(encrypted_elt)
hash_algo, hash_value = self._h.parse_hash_elt(encrypted_elt)
except exceptions.NotFound:
pass
else:
@ -237,7 +237,7 @@ class XEP_0448:
# handle the attachment if it's not activated
return False
try:
await self._http_upload.getHTTPUploadEntity(client)
await self._http_upload.get_http_upload_entity(client)
except exceptions.NotFound:
return False
else:
@ -279,7 +279,7 @@ class XEP_0448:
"There should not be more that one attachment at this point"
)
await self._attach.upload_files(client, data, upload_cb=self._upload_cb)
self._hints.addHintElements(data["xml"], [self._hints.HINT_STORE])
self._hints.add_hint_elements(data["xml"], [self._hints.HINT_STORE])
for attachment in attachments:
encryption_data = attachment.pop("encryption_data")
file_hash = (attachment["hash_algo"], attachment["hash"])
@ -301,7 +301,7 @@ class XEP_0448:
"iv",
content=base64.b64encode(encryption_data["iv"]).decode()
)
encrypted_elt.addChild(self._h.buildHashElt(
encrypted_elt.addChild(self._h.build_hash_elt(
attachment["encrypted_hash"],
attachment["encrypted_hash_algo"]
))
@ -446,9 +446,9 @@ class XEP_0448:
attachment.update({
"hash_algo": self._h.ALGO_DEFAULT,
"hasher": self._h.getHasher(),
"hasher": self._h.get_hasher(),
"encrypted_hash_algo": self._h.ALGO_DEFAULT,
"encrypted_hasher": self._h.getHasher(),
"encrypted_hasher": self._h.get_hasher(),
})
# with data_cb we encrypt the file on the fly