Mercurial > libervia-backend
comparison sat/plugins/plugin_xep_0280.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 | c23cad65ae99 |
comparison
equal
deleted
inserted
replaced
4036:c4464d7ae97b | 4037:524856bd7b19 |
---|---|
72 ) | 72 ) |
73 | 73 |
74 def __init__(self, host): | 74 def __init__(self, host): |
75 log.info(_("Plugin XEP_0280 initialization")) | 75 log.info(_("Plugin XEP_0280 initialization")) |
76 self.host = host | 76 self.host = host |
77 host.memory.updateParams(self.params) | 77 host.memory.update_params(self.params) |
78 host.trigger.add("messageReceived", self.messageReceivedTrigger, priority=200000) | 78 host.trigger.add("messageReceived", self.message_received_trigger, priority=200000) |
79 | 79 |
80 def getHandler(self, client): | 80 def get_handler(self, client): |
81 return XEP_0280_handler() | 81 return XEP_0280_handler() |
82 | 82 |
83 def setPrivate(self, message_elt): | 83 def set_private(self, message_elt): |
84 """Add a <private/> element to a message | 84 """Add a <private/> element to a message |
85 | 85 |
86 this method is intented to be called on final domish.Element by other plugins | 86 this method is intented to be called on final domish.Element by other plugins |
87 (in particular end 2 end encryption plugins) | 87 (in particular end 2 end encryption plugins) |
88 @param message_elt(domish.Element): <message> stanza | 88 @param message_elt(domish.Element): <message> stanza |
91 log.error("addPrivateElt must be used with <message> stanzas") | 91 log.error("addPrivateElt must be used with <message> stanzas") |
92 return | 92 return |
93 message_elt.addElement((NS_CARBONS, "private")) | 93 message_elt.addElement((NS_CARBONS, "private")) |
94 | 94 |
95 @defer.inlineCallbacks | 95 @defer.inlineCallbacks |
96 def profileConnected(self, client): | 96 def profile_connected(self, client): |
97 """activate message carbons on connection if possible and activated in config""" | 97 """activate message carbons on connection if possible and activated in config""" |
98 activate = self.host.memory.getParamA( | 98 activate = self.host.memory.param_get_a( |
99 PARAM_NAME, PARAM_CATEGORY, profile_key=client.profile | 99 PARAM_NAME, PARAM_CATEGORY, profile_key=client.profile |
100 ) | 100 ) |
101 if not activate: | 101 if not activate: |
102 log.info(_("Not activating message carbons as requested in params")) | 102 log.info(_("Not activating message carbons as requested in params")) |
103 return | 103 return |
104 try: | 104 try: |
105 yield self.host.checkFeatures(client, (NS_CARBONS,)) | 105 yield self.host.check_features(client, (NS_CARBONS,)) |
106 except exceptions.FeatureNotFound: | 106 except exceptions.FeatureNotFound: |
107 log.warning(_("server doesn't handle message carbons")) | 107 log.warning(_("server doesn't handle message carbons")) |
108 else: | 108 else: |
109 log.info(_("message carbons available, enabling it")) | 109 log.info(_("message carbons available, enabling it")) |
110 iq_elt = client.IQ() | 110 iq_elt = client.IQ() |
114 except StanzaError as e: | 114 except StanzaError as e: |
115 log.warning("Can't activate message carbons: {}".format(e)) | 115 log.warning("Can't activate message carbons: {}".format(e)) |
116 else: | 116 else: |
117 log.info(_("message carbons activated")) | 117 log.info(_("message carbons activated")) |
118 | 118 |
119 def messageReceivedTrigger(self, client, message_elt, post_treat): | 119 def message_received_trigger(self, client, message_elt, post_treat): |
120 """get message and handle it if carbons namespace is present""" | 120 """get message and handle it if carbons namespace is present""" |
121 carbons_elt = None | 121 carbons_elt = None |
122 for e in message_elt.elements(): | 122 for e in message_elt.elements(): |
123 if e.uri == NS_CARBONS: | 123 if e.uri == NS_CARBONS: |
124 carbons_elt = e | 124 carbons_elt = e |