comparison sat/plugins/plugin_xep_0352.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 be6d91572633
children
comparison
equal deleted inserted replaced
4036:c4464d7ae97b 4037:524856bd7b19
42 class XEP_0352(object): 42 class XEP_0352(object):
43 43
44 def __init__(self, host): 44 def __init__(self, host):
45 log.info(_("Client State Indication plugin initialization")) 45 log.info(_("Client State Indication plugin initialization"))
46 self.host = host 46 self.host = host
47 host.registerNamespace("csi", NS_CSI) 47 host.register_namespace("csi", NS_CSI)
48 48
49 def isActive(self, client): 49 def is_active(self, client):
50 try: 50 try:
51 if not client._xep_0352_enabled: 51 if not client._xep_0352_enabled:
52 return True 52 return True
53 return client._xep_0352_active 53 return client._xep_0352_active
54 except AttributeError: 54 except AttributeError:
55 # _xep_0352_active can not be set if isActive is called before 55 # _xep_0352_active can not be set if is_active is called before
56 # profileConnected has been called 56 # profile_connected has been called
57 log.debug("isActive called when XEP-0352 plugin has not yet set the " 57 log.debug("is_active called when XEP-0352 plugin has not yet set the "
58 "attributes") 58 "attributes")
59 return True 59 return True
60 60
61 def profileConnected(self, client): 61 def profile_connected(self, client):
62 if (NS_CSI, 'csi') in client.xmlstream.features: 62 if (NS_CSI, 'csi') in client.xmlstream.features:
63 log.info(_("Client State Indication is available on this server")) 63 log.info(_("Client State Indication is available on this server"))
64 client._xep_0352_enabled = True 64 client._xep_0352_enabled = True
65 client._xep_0352_active = True 65 client._xep_0352_active = True
66 else: 66 else:
67 log.warning(_("Client State Indication is not available on this server, some" 67 log.warning(_("Client State Indication is not available on this server, some"
68 " bandwidth optimisations can't be used.")) 68 " bandwidth optimisations can't be used."))
69 client._xep_0352_enabled = False 69 client._xep_0352_enabled = False
70 70
71 def setInactive(self, client): 71 def set_inactive(self, client):
72 if self.isActive(client): 72 if self.is_active(client):
73 inactive_elt = domish.Element((NS_CSI, 'inactive')) 73 inactive_elt = domish.Element((NS_CSI, 'inactive'))
74 client.send(inactive_elt) 74 client.send(inactive_elt)
75 client._xep_0352_active = False 75 client._xep_0352_active = False
76 log.info("inactive state set") 76 log.info("inactive state set")
77 77
78 def setActive(self, client): 78 def set_active(self, client):
79 if not self.isActive(client): 79 if not self.is_active(client):
80 active_elt = domish.Element((NS_CSI, 'active')) 80 active_elt = domish.Element((NS_CSI, 'active'))
81 client.send(active_elt) 81 client.send(active_elt)
82 client._xep_0352_active = True 82 client._xep_0352_active = True
83 log.info("active state set") 83 log.info("active state set")