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

@ -71,7 +71,7 @@ class XEP_0292:
# it is not done here. It is expected that this dedicated protocol will be removed
# from a future version of the XEP.
log.info(_("vCard4 Over XMPP initialization"))
host.registerNamespace("vcard4", NS_VCARD4)
host.register_namespace("vcard4", NS_VCARD4)
self.host = host
self._p = host.plugins["XEP-0060"]
self._i = host.plugins['IDENTITY']
@ -79,21 +79,21 @@ class XEP_0292:
IMPORT_NAME,
'nicknames',
partial(self.getValue, field="nicknames"),
partial(self.setValue, field="nicknames"),
partial(self.set_value, field="nicknames"),
priority=1000
)
self._i.register(
IMPORT_NAME,
'description',
partial(self.getValue, field="description"),
partial(self.setValue, field="description"),
partial(self.set_value, field="description"),
priority=1000
)
def getHandler(self, client):
def get_handler(self, client):
return XEP_0292_Handler()
def vcard2Dict(self, vcard_elt: domish.Element) -> Dict[str, Any]:
def vcard_2_dict(self, vcard_elt: domish.Element) -> Dict[str, Any]:
"""Convert vcard element to equivalent identity metadata"""
vcard: Dict[str, Any] = {}
@ -102,7 +102,7 @@ class XEP_0292:
for source_field, dest_field in text_fields.items():
if metadata_elt.name == source_field:
if metadata_elt.text is not None:
dest_type = self._i.getFieldType(dest_field)
dest_type = self._i.get_field_type(dest_field)
value = str(metadata_elt.text)
if dest_type is str:
if dest_field in vcard:
@ -122,7 +122,7 @@ class XEP_0292:
)
return vcard
def dict2VCard(self, vcard: dict[str, Any]) -> domish.Element:
def dict_2_v_card(self, vcard: dict[str, Any]) -> domish.Element:
"""Convert vcard metadata to vCard4 element"""
vcard_elt = domish.Element((NS_VCARD4, "vcard"))
for field, elt_name in text_fields_inv.items():
@ -142,9 +142,9 @@ class XEP_0292:
return vcard_elt
@async_lru(5)
async def getCard(self, client: SatXMPPEntity, entity: jid.JID) -> dict:
async def get_card(self, client: SatXMPPEntity, entity: jid.JID) -> dict:
try:
items, metadata = await self._p.getItems(
items, metadata = await self._p.get_items(
client, entity, VCARD4_NODE, item_ids=["current"]
)
except exceptions.NotFound:
@ -157,9 +157,9 @@ class XEP_0292:
log.info(f"vCard element is not present for {entity}")
return {}
return self.vcard2Dict(vcard_elt)
return self.vcard_2_dict(vcard_elt)
async def updateVCardElt(
async def update_vcard_elt(
self,
client: SatXMPPEntity,
vcard_elt: domish.Element,
@ -176,12 +176,12 @@ class XEP_0292:
self._p.OPT_ACCESS_MODEL: self._p.ACCESS_OPEN,
self._p.OPT_PUBLISH_MODEL: self._p.PUBLISH_MODEL_PUBLISHERS
}
await self._p.createIfNewNode(client, service, VCARD4_NODE, node_options)
await self._p.sendItem(
await self._p.create_if_new_node(client, service, VCARD4_NODE, node_options)
await self._p.send_item(
client, service, VCARD4_NODE, vcard_elt, item_id=self._p.ID_SINGLETON
)
async def updateVCard(
async def update_v_card(
self,
client: SatXMPPEntity,
vcard: Dict[str, Any],
@ -198,11 +198,11 @@ class XEP_0292:
"""
service = entity or client.jid.userhostJID()
if update:
current_vcard = await self.getCard(client, service)
current_vcard = await self.get_card(client, service)
current_vcard.update(vcard)
vcard = current_vcard
vcard_elt = self.dict2VCard(vcard)
await self.updateVCardElt(client, vcard_elt, service)
vcard_elt = self.dict_2_v_card(vcard)
await self.update_vcard_elt(client, vcard_elt, service)
async def getValue(
self,
@ -217,10 +217,10 @@ class XEP_0292:
This has to be a string field
@return request value
"""
vcard_data = await self.getCard(client, entity)
vcard_data = await self.get_card(client, entity)
return vcard_data.get(field)
async def setValue(
async def set_value(
self,
client: SatXMPPEntity,
value: Union[str, List[str]],
@ -233,7 +233,7 @@ class XEP_0292:
@param field: name of the field to get
This has to be a string field
"""
await self.updateVCard(client, {field: value}, entity)
await self.update_v_card(client, {field: value}, entity)
@implementer(iwokkel.IDisco)