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

@ -67,10 +67,10 @@ class AESGCM(object):
"aesgcm", self.download
)
self._attach.register(
self.canHandleAttachment, self.attach, encrypted=True)
self.can_handle_attachment, self.attach, encrypted=True)
host.trigger.add("XEP-0363_upload_pre_slot", self._upload_pre_slot)
host.trigger.add("XEP-0363_upload", self._upload_trigger)
host.trigger.add("messageReceived", self._messageReceivedTrigger)
host.trigger.add("messageReceived", self._message_received_trigger)
async def download(self, client, uri_parsed, dest_path, options):
fragment = bytes.fromhex(uri_parsed.fragment)
@ -123,7 +123,7 @@ class AESGCM(object):
resp = await treq_client.get(download_url, unbuffered=True)
if resp.code == 200:
d = treq.collect(resp, partial(
self.onDataDownload,
self.on_data_download,
client=client,
file_obj=file_obj,
decryptor=decryptor))
@ -132,9 +132,9 @@ class AESGCM(object):
self.host.plugins["DOWNLOAD"].errback_download(file_obj, d, resp)
return progress_id, d
async def canHandleAttachment(self, client, data):
async def can_handle_attachment(self, client, data):
try:
await self._http_upload.getHTTPUploadEntity(client)
await self._http_upload.get_http_upload_entity(client)
except exceptions.NotFound:
return False
else:
@ -190,7 +190,7 @@ class AESGCM(object):
# nothing left to send, we can cancel the message
raise exceptions.CancelError("Cancelled by AESGCM attachment handling")
def onDataDownload(self, data, client, file_obj, decryptor):
def on_data_download(self, data, client, file_obj, decryptor):
if file_obj.tell() + len(data) > file_obj.size:
# we're reaching end of file with this bunch of data
# we may still have a last bunch if the tag is incomplete
@ -277,20 +277,20 @@ class AESGCM(object):
return True
def _popAESGCMLinks(self, match, links):
def _pop_aesgcm_links(self, match, links):
link = match.group()
if link not in links:
links.append(link)
return ""
def _checkAESGCMAttachments(self, client, data):
def _check_aesgcm_attachments(self, client, data):
if not data.get('message'):
return data
links = []
for lang, message in list(data['message'].items()):
message = AESGCM_RE.sub(
partial(self._popAESGCMLinks, links=links),
partial(self._pop_aesgcm_links, links=links),
message)
if links:
message = message.strip()
@ -319,9 +319,9 @@ class AESGCM(object):
return data
def _messageReceivedTrigger(self, client, message_elt, post_treat):
def _message_received_trigger(self, client, message_elt, post_treat):
# we use a post_treat callback instead of "message_parse" trigger because we need
# to check if the "encrypted" flag is set to decide if we add the same flag to the
# attachment
post_treat.addCallback(partial(self._checkAESGCMAttachments, client))
post_treat.addCallback(partial(self._check_aesgcm_attachments, client))
return True