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
|
|
@ -61,54 +61,54 @@ class XEP_0100(object):
|
|||
def __init__(self, host):
|
||||
log.info(_("Gateways plugin initialization"))
|
||||
self.host = host
|
||||
self.__gateways = {} # dict used to construct the answer to findGateways. Key = target jid
|
||||
host.bridge.addMethod(
|
||||
"findGateways",
|
||||
self.__gateways = {} # dict used to construct the answer to gateways_find. Key = target jid
|
||||
host.bridge.add_method(
|
||||
"gateways_find",
|
||||
".plugin",
|
||||
in_sign="ss",
|
||||
out_sign="s",
|
||||
method=self._findGateways,
|
||||
method=self._find_gateways,
|
||||
)
|
||||
host.bridge.addMethod(
|
||||
"gatewayRegister",
|
||||
host.bridge.add_method(
|
||||
"gateway_register",
|
||||
".plugin",
|
||||
in_sign="ss",
|
||||
out_sign="s",
|
||||
method=self._gatewayRegister,
|
||||
method=self._gateway_register,
|
||||
)
|
||||
self.__menu_id = host.registerCallback(self._gatewaysMenu, with_data=True)
|
||||
self.__selected_id = host.registerCallback(
|
||||
self._gatewaySelectedCb, with_data=True
|
||||
self.__menu_id = host.register_callback(self._gateways_menu, with_data=True)
|
||||
self.__selected_id = host.register_callback(
|
||||
self._gateway_selected_cb, with_data=True
|
||||
)
|
||||
host.importMenu(
|
||||
host.import_menu(
|
||||
(D_("Service"), D_("Gateways")),
|
||||
self._gatewaysMenu,
|
||||
self._gateways_menu,
|
||||
security_limit=1,
|
||||
help_string=D_("Find gateways"),
|
||||
)
|
||||
|
||||
def _gatewaysMenu(self, data, profile):
|
||||
def _gateways_menu(self, data, profile):
|
||||
""" XMLUI activated by menu: return Gateways UI
|
||||
|
||||
@param profile: %(doc_profile)s
|
||||
"""
|
||||
client = self.host.getClient(profile)
|
||||
client = self.host.get_client(profile)
|
||||
try:
|
||||
jid_ = jid.JID(
|
||||
data.get(xml_tools.formEscape("external_jid"), client.jid.host)
|
||||
data.get(xml_tools.form_escape("external_jid"), client.jid.host)
|
||||
)
|
||||
except RuntimeError:
|
||||
raise exceptions.DataError(_("Invalid JID"))
|
||||
d = self.findGateways(jid_, profile)
|
||||
d.addCallback(self._gatewaysResult2XMLUI, jid_)
|
||||
d = self.gateways_find(jid_, profile)
|
||||
d.addCallback(self._gateways_result_2_xmlui, jid_)
|
||||
d.addCallback(lambda xmlui: {"xmlui": xmlui.toXml()})
|
||||
return d
|
||||
|
||||
def _gatewaysResult2XMLUI(self, result, entity):
|
||||
def _gateways_result_2_xmlui(self, result, entity):
|
||||
xmlui = xml_tools.XMLUI(title=_("Gateways manager (%s)") % entity.full())
|
||||
xmlui.addText(_(WARNING_MSG))
|
||||
xmlui.addDivider("dash")
|
||||
adv_list = xmlui.changeContainer(
|
||||
adv_list = xmlui.change_container(
|
||||
"advanced_list",
|
||||
columns=3,
|
||||
selectable="single",
|
||||
|
|
@ -124,30 +124,30 @@ class XEP_0100(object):
|
|||
jid_, data = gateway_data
|
||||
for datum in data:
|
||||
identity, name = datum
|
||||
adv_list.setRowIndex(jid_.full())
|
||||
adv_list.set_row_index(jid_.full())
|
||||
xmlui.addJid(jid_)
|
||||
xmlui.addText(name)
|
||||
xmlui.addText(self._getIdentityDesc(identity))
|
||||
xmlui.addText(self._get_identity_desc(identity))
|
||||
adv_list.end()
|
||||
xmlui.addDivider("blank")
|
||||
xmlui.changeContainer("advanced_list", columns=3)
|
||||
xmlui.change_container("advanced_list", columns=3)
|
||||
xmlui.addLabel(_("Use external XMPP server"))
|
||||
xmlui.addString("external_jid")
|
||||
xmlui.addButton(self.__menu_id, _("Go !"), fields_back=("external_jid",))
|
||||
return xmlui
|
||||
|
||||
def _gatewaySelectedCb(self, data, profile):
|
||||
def _gateway_selected_cb(self, data, profile):
|
||||
try:
|
||||
target_jid = jid.JID(data["index"])
|
||||
except (KeyError, RuntimeError):
|
||||
log.warning(_("No gateway index selected"))
|
||||
return {}
|
||||
|
||||
d = self.gatewayRegister(target_jid, profile)
|
||||
d = self.gateway_register(target_jid, profile)
|
||||
d.addCallback(lambda xmlui: {"xmlui": xmlui.toXml()})
|
||||
return d
|
||||
|
||||
def _getIdentityDesc(self, identity):
|
||||
def _get_identity_desc(self, identity):
|
||||
""" Return a human readable description of identity
|
||||
@param identity: tuple as returned by Disco identities (category, type)
|
||||
|
||||
|
|
@ -165,27 +165,27 @@ class XEP_0100(object):
|
|||
except KeyError:
|
||||
return _("Unknown IM")
|
||||
|
||||
def _registrationSuccessful(self, jid_, profile):
|
||||
def _registration_successful(self, jid_, profile):
|
||||
"""Called when in_band registration is ok, we must now follow the rest of procedure"""
|
||||
log.debug(_("Registration successful, doing the rest"))
|
||||
self.host.addContact(jid_, profile_key=profile)
|
||||
self.host.setPresence(jid_, profile_key=profile)
|
||||
self.host.contact_add(jid_, profile_key=profile)
|
||||
self.host.presence_set(jid_, profile_key=profile)
|
||||
|
||||
def _gatewayRegister(self, target_jid_s, profile_key=C.PROF_KEY_NONE):
|
||||
d = self.gatewayRegister(jid.JID(target_jid_s), profile_key)
|
||||
def _gateway_register(self, target_jid_s, profile_key=C.PROF_KEY_NONE):
|
||||
d = self.gateway_register(jid.JID(target_jid_s), profile_key)
|
||||
d.addCallback(lambda xmlui: xmlui.toXml())
|
||||
return d
|
||||
|
||||
def gatewayRegister(self, target_jid, profile_key=C.PROF_KEY_NONE):
|
||||
def gateway_register(self, target_jid, profile_key=C.PROF_KEY_NONE):
|
||||
"""Register gateway using in-band registration, then log-in to gateway"""
|
||||
profile = self.host.memory.getProfileName(profile_key)
|
||||
profile = self.host.memory.get_profile_name(profile_key)
|
||||
assert profile
|
||||
d = self.host.plugins["XEP-0077"].inBandRegister(
|
||||
target_jid, self._registrationSuccessful, profile
|
||||
d = self.host.plugins["XEP-0077"].in_band_register(
|
||||
target_jid, self._registration_successful, profile
|
||||
)
|
||||
return d
|
||||
|
||||
def _infosReceived(self, dl_result, items, target, client):
|
||||
def _infos_received(self, dl_result, items, target, client):
|
||||
"""Find disco infos about entity, to check if it is a gateway"""
|
||||
|
||||
ret = []
|
||||
|
|
@ -224,7 +224,7 @@ class XEP_0100(object):
|
|||
)
|
||||
return ret
|
||||
|
||||
def _itemsReceived(self, disco, target, client):
|
||||
def _items_received(self, disco, target, client):
|
||||
"""Look for items with disco protocol, and ask infos for each one"""
|
||||
|
||||
if len(disco._items) == 0:
|
||||
|
|
@ -237,29 +237,29 @@ class XEP_0100(object):
|
|||
_defers.append(client.disco.requestInfo(item.entity))
|
||||
dl = defer.DeferredList(_defers)
|
||||
dl.addCallback(
|
||||
self._infosReceived, items=disco._items, target=target, client=client
|
||||
self._infos_received, items=disco._items, target=target, client=client
|
||||
)
|
||||
reactor.callLater(GATEWAY_TIMEOUT, dl.cancel)
|
||||
return dl
|
||||
|
||||
def _findGateways(self, target_jid_s, profile_key):
|
||||
def _find_gateways(self, target_jid_s, profile_key):
|
||||
target_jid = jid.JID(target_jid_s)
|
||||
profile = self.host.memory.getProfileName(profile_key)
|
||||
profile = self.host.memory.get_profile_name(profile_key)
|
||||
if not profile:
|
||||
raise exceptions.ProfileUnknownError
|
||||
d = self.findGateways(target_jid, profile)
|
||||
d.addCallback(self._gatewaysResult2XMLUI, target_jid)
|
||||
d = self.gateways_find(target_jid, profile)
|
||||
d.addCallback(self._gateways_result_2_xmlui, target_jid)
|
||||
d.addCallback(lambda xmlui: xmlui.toXml())
|
||||
return d
|
||||
|
||||
def findGateways(self, target, profile):
|
||||
def gateways_find(self, target, profile):
|
||||
"""Find gateways in the target JID, using discovery protocol
|
||||
"""
|
||||
client = self.host.getClient(profile)
|
||||
client = self.host.get_client(profile)
|
||||
log.debug(
|
||||
_("find gateways (target = %(target)s, profile = %(profile)s)")
|
||||
% {"target": target.full(), "profile": profile}
|
||||
)
|
||||
d = client.disco.requestItems(target)
|
||||
d.addCallback(self._itemsReceived, target=target, client=client)
|
||||
d.addCallback(self._items_received, target=target, client=client)
|
||||
return d
|
||||
|
|
|
|||
Loading…
Reference in a new issue