comparison sat/plugins/plugin_xep_0447.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 78b5f356900c
children c23cad65ae99
comparison
equal deleted inserted replaced
4036:c4464d7ae97b 4037:524856bd7b19
57 namespace = NS_SFS 57 namespace = NS_SFS
58 58
59 def __init__(self, host): 59 def __init__(self, host):
60 self.host = host 60 self.host = host
61 log.info(_("XEP-0447 (Stateless File Sharing) plugin initialization")) 61 log.info(_("XEP-0447 (Stateless File Sharing) plugin initialization"))
62 host.registerNamespace("sfs", NS_SFS) 62 host.register_namespace("sfs", NS_SFS)
63 self._sources_handlers = {} 63 self._sources_handlers = {}
64 self._u = host.plugins["XEP-0103"] 64 self._u = host.plugins["XEP-0103"]
65 self._hints = host.plugins["XEP-0334"] 65 self._hints = host.plugins["XEP-0334"]
66 self._m = host.plugins["XEP-0446"] 66 self._m = host.plugins["XEP-0446"]
67 self._http_upload = host.plugins.get("XEP-0363") 67 self._http_upload = host.plugins.get("XEP-0363")
148 148
149 async def can_handle_attachment(self, client, data): 149 async def can_handle_attachment(self, client, data):
150 if self._http_upload is None: 150 if self._http_upload is None:
151 return False 151 return False
152 try: 152 try:
153 await self._http_upload.getHTTPUploadEntity(client) 153 await self._http_upload.get_http_upload_entity(client)
154 except exceptions.NotFound: 154 except exceptions.NotFound:
155 return False 155 return False
156 else: 156 else:
157 return True 157 return True
158 158
332 if len(attachments) > 1: 332 if len(attachments) > 1:
333 raise exceptions.InternalError( 333 raise exceptions.InternalError(
334 "There should not be more that one attachment at this point" 334 "There should not be more that one attachment at this point"
335 ) 335 )
336 await self._attach.upload_files(client, data) 336 await self._attach.upload_files(client, data)
337 self._hints.addHintElements(data["xml"], [self._hints.HINT_STORE]) 337 self._hints.add_hint_elements(data["xml"], [self._hints.HINT_STORE])
338 for attachment in attachments: 338 for attachment in attachments:
339 try: 339 try:
340 file_hash = (attachment["hash_algo"], attachment["hash"]) 340 file_hash = (attachment["hash_algo"], attachment["hash"])
341 except KeyError: 341 except KeyError:
342 file_hash = None 342 file_hash = None