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:
parent
d50412c7f7
commit
6a6f15707a
1 changed files with 9945 additions and 9945 deletions
|
|
@ -77,15 +77,15 @@ class RegisteringAuthenticator(xmlstream.ConnectAuthenticator):
|
|||
def register(self, xmlstream):
|
||||
log.debug(_("Stream started with {server}, now registering"
|
||||
.format(server=self.jid.host)))
|
||||
iq = XEP_0077.buildRegisterIQ(self.xmlstream, self.jid, self.password, self.email)
|
||||
d = iq.send(self.jid.host).addCallbacks(self.registrationCb, self.registrationEb)
|
||||
iq = XEP_0077.build_register_iq(self.xmlstream, self.jid, self.password, self.email)
|
||||
d = iq.send(self.jid.host).addCallbacks(self.registration_cb, self.registration_eb)
|
||||
d.chainDeferred(self.registered)
|
||||
|
||||
def registrationCb(self, answer):
|
||||
def registration_cb(self, answer):
|
||||
log.debug(_("Registration answer: {}").format(answer.toXml()))
|
||||
self.xmlstream.sendFooter()
|
||||
|
||||
def registrationEb(self, failure_):
|
||||
def registration_eb(self, failure_):
|
||||
log.info(_("Registration failure: {}").format(str(failure_.value)))
|
||||
self.xmlstream.sendFooter()
|
||||
raise failure_
|
||||
|
|
@ -115,41 +115,41 @@ class XEP_0077(object):
|
|||
def __init__(self, host):
|
||||
log.info(_("Plugin XEP_0077 initialization"))
|
||||
self.host = host
|
||||
host.bridge.addMethod(
|
||||
"inBandRegister",
|
||||
host.bridge.add_method(
|
||||
"in_band_register",
|
||||
".plugin",
|
||||
in_sign="ss",
|
||||
out_sign="",
|
||||
method=self._inBandRegister,
|
||||
method=self._in_band_register,
|
||||
async_=True,
|
||||
)
|
||||
host.bridge.addMethod(
|
||||
"inBandAccountNew",
|
||||
host.bridge.add_method(
|
||||
"in_band_account_new",
|
||||
".plugin",
|
||||
in_sign="ssssi",
|
||||
out_sign="",
|
||||
method=self._registerNewAccount,
|
||||
method=self._register_new_account,
|
||||
async_=True,
|
||||
)
|
||||
host.bridge.addMethod(
|
||||
"inBandUnregister",
|
||||
host.bridge.add_method(
|
||||
"in_band_unregister",
|
||||
".plugin",
|
||||
in_sign="ss",
|
||||
out_sign="",
|
||||
method=self._unregister,
|
||||
async_=True,
|
||||
)
|
||||
host.bridge.addMethod(
|
||||
"inBandPasswordChange",
|
||||
host.bridge.add_method(
|
||||
"in_band_password_change",
|
||||
".plugin",
|
||||
in_sign="ss",
|
||||
out_sign="",
|
||||
method=self._changePassword,
|
||||
method=self._change_password,
|
||||
async_=True,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def buildRegisterIQ(xmlstream_, jid_, password, email=None):
|
||||
def build_register_iq(xmlstream_, jid_, password, email=None):
|
||||
iq_elt = xmlstream.IQ(xmlstream_, "set")
|
||||
iq_elt["to"] = jid_.host
|
||||
query_elt = iq_elt.addElement(("jabber:iq:register", "query"))
|
||||
|
|
@ -162,7 +162,7 @@ class XEP_0077(object):
|
|||
email_elt.addContent(email)
|
||||
return iq_elt
|
||||
|
||||
def _regCb(self, answer, client, post_treat_cb):
|
||||
def _reg_cb(self, answer, client, post_treat_cb):
|
||||
"""Called after the first get IQ"""
|
||||
try:
|
||||
query_elt = next(answer.elements(NS_REG, "query"))
|
||||
|
|
@ -178,8 +178,8 @@ class XEP_0077(object):
|
|||
_("This gateway can't be managed by SàT, sorry :(")
|
||||
)
|
||||
|
||||
def submitForm(data, profile):
|
||||
form_elt = xml_tools.XMLUIResultToElt(data)
|
||||
def submit_form(data, profile):
|
||||
form_elt = xml_tools.xmlui_result_to_elt(data)
|
||||
|
||||
iq_elt = client.IQ()
|
||||
iq_elt["id"] = answer["id"]
|
||||
|
|
@ -187,28 +187,28 @@ class XEP_0077(object):
|
|||
query_elt = iq_elt.addElement("query", NS_REG)
|
||||
query_elt.addChild(form_elt)
|
||||
d = iq_elt.send()
|
||||
d.addCallback(self._regSuccess, client, post_treat_cb)
|
||||
d.addErrback(self._regFailure, client)
|
||||
d.addCallback(self._reg_success, client, post_treat_cb)
|
||||
d.addErrback(self._reg_failure, client)
|
||||
return d
|
||||
|
||||
form = data_form.Form.fromElement(x_elem)
|
||||
submit_reg_id = self.host.registerCallback(
|
||||
submitForm, with_data=True, one_shot=True
|
||||
submit_reg_id = self.host.register_callback(
|
||||
submit_form, with_data=True, one_shot=True
|
||||
)
|
||||
return xml_tools.dataForm2XMLUI(form, submit_reg_id)
|
||||
return xml_tools.data_form_2_xmlui(form, submit_reg_id)
|
||||
|
||||
def _regEb(self, failure, client):
|
||||
def _reg_eb(self, failure, client):
|
||||
"""Called when something is wrong with registration"""
|
||||
log.info(_("Registration failure: %s") % str(failure.value))
|
||||
raise failure
|
||||
|
||||
def _regSuccess(self, answer, client, post_treat_cb):
|
||||
def _reg_success(self, answer, client, post_treat_cb):
|
||||
log.debug(_("registration answer: %s") % answer.toXml())
|
||||
if post_treat_cb is not None:
|
||||
post_treat_cb(jid.JID(answer["from"]), client.profile)
|
||||
return {}
|
||||
|
||||
def _regFailure(self, failure, client):
|
||||
def _reg_failure(self, failure, client):
|
||||
log.info(_("Registration failure: %s") % str(failure.value))
|
||||
if failure.value.condition == "conflict":
|
||||
raise exceptions.ConflictError(
|
||||
|
|
@ -216,30 +216,30 @@ class XEP_0077(object):
|
|||
)
|
||||
raise failure
|
||||
|
||||
def _inBandRegister(self, to_jid_s, profile_key=C.PROF_KEY_NONE):
|
||||
return self.inBandRegister, jid.JID(to_jid_s, profile_key)
|
||||
def _in_band_register(self, to_jid_s, profile_key=C.PROF_KEY_NONE):
|
||||
return self.in_band_register, jid.JID(to_jid_s, profile_key)
|
||||
|
||||
def inBandRegister(self, to_jid, post_treat_cb=None, profile_key=C.PROF_KEY_NONE):
|
||||
def in_band_register(self, to_jid, post_treat_cb=None, profile_key=C.PROF_KEY_NONE):
|
||||
"""register to a service
|
||||
|
||||
@param to_jid(jid.JID): jid of the service to register to
|
||||
"""
|
||||
# FIXME: this post_treat_cb arguments seems wrong, check it
|
||||
client = self.host.getClient(profile_key)
|
||||
client = self.host.get_client(profile_key)
|
||||
log.debug(_("Asking registration for {}").format(to_jid.full()))
|
||||
reg_request = client.IQ("get")
|
||||
reg_request["from"] = client.jid.full()
|
||||
reg_request["to"] = to_jid.full()
|
||||
reg_request.addElement("query", NS_REG)
|
||||
d = reg_request.send(to_jid.full()).addCallbacks(
|
||||
self._regCb,
|
||||
self._regEb,
|
||||
self._reg_cb,
|
||||
self._reg_eb,
|
||||
callbackArgs=[client, post_treat_cb],
|
||||
errbackArgs=[client],
|
||||
)
|
||||
return d
|
||||
|
||||
def _registerNewAccount(self, jid_, password, email, host, port):
|
||||
def _register_new_account(self, jid_, password, email, host, port):
|
||||
kwargs = {}
|
||||
if email:
|
||||
kwargs["email"] = email
|
||||
|
|
@ -247,9 +247,9 @@ class XEP_0077(object):
|
|||
kwargs["host"] = host
|
||||
if port:
|
||||
kwargs["port"] = port
|
||||
return self.registerNewAccount(jid.JID(jid_), password, **kwargs)
|
||||
return self.register_new_account(jid.JID(jid_), password, **kwargs)
|
||||
|
||||
def registerNewAccount(
|
||||
def register_new_account(
|
||||
self, jid_, password, email=None, host=None, port=C.XMPP_C2S_PORT
|
||||
):
|
||||
"""register a new account on a XMPP server
|
||||
|
|
@ -261,7 +261,7 @@ class XEP_0077(object):
|
|||
@param port(int): port of the server to register to
|
||||
"""
|
||||
if host is None:
|
||||
host = self.host.memory.getConfig("", "xmpp_domain", "127.0.0.1")
|
||||
host = self.host.memory.config_get("", "xmpp_domain", "127.0.0.1")
|
||||
check_certificate = host != "127.0.0.1"
|
||||
authenticator = RegisteringAuthenticator(
|
||||
jid_, password, email, check_certificate=check_certificate)
|
||||
|
|
@ -270,22 +270,22 @@ class XEP_0077(object):
|
|||
reactor.connectTCP(host, port, server_register)
|
||||
return registered_d
|
||||
|
||||
def _changePassword(self, new_password, profile_key):
|
||||
client = self.host.getClient(profile_key)
|
||||
return self.changePassword(client, new_password)
|
||||
def _change_password(self, new_password, profile_key):
|
||||
client = self.host.get_client(profile_key)
|
||||
return self.change_password(client, new_password)
|
||||
|
||||
def changePassword(self, client, new_password):
|
||||
iq_elt = self.buildRegisterIQ(client.xmlstream, client.jid, new_password)
|
||||
def change_password(self, client, new_password):
|
||||
iq_elt = self.build_register_iq(client.xmlstream, client.jid, new_password)
|
||||
d = iq_elt.send(client.jid.host)
|
||||
d.addCallback(
|
||||
lambda __: self.host.memory.setParam(
|
||||
lambda __: self.host.memory.param_set(
|
||||
"Password", new_password, "Connection", profile_key=client.profile
|
||||
)
|
||||
)
|
||||
return d
|
||||
|
||||
def _unregister(self, to_jid_s, profile_key):
|
||||
client = self.host.getClient(profile_key)
|
||||
client = self.host.get_client(profile_key)
|
||||
return self.unregister(client, jid.JID(to_jid_s))
|
||||
|
||||
def unregister(
|
||||
|
|
@ -307,6 +307,6 @@ class XEP_0077(object):
|
|||
query_elt.addElement("remove")
|
||||
d = iq_elt.send()
|
||||
if not to_jid or to_jid == jid.JID(client.jid.host):
|
||||
d.addCallback(lambda __: client.entityDisconnect())
|
||||
d.addCallback(lambda __: client.entity_disconnect())
|
||||
return d
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue