Mercurial > libervia-backend
diff sat/stdui/ui_profile_manager.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 |
line wrap: on
line diff
--- a/sat/stdui/ui_profile_manager.py Fri Apr 07 15:18:39 2023 +0200 +++ b/sat/stdui/ui_profile_manager.py Sat Apr 08 13:54:42 2023 +0200 @@ -38,18 +38,18 @@ self.host = host self.profile_ciphers = {} self._sessions = ProfileSessions() - host.registerCallback( - self._authenticateProfile, force_id=C.AUTHENTICATE_PROFILE_ID, with_data=True + host.register_callback( + self._authenticate_profile, force_id=C.AUTHENTICATE_PROFILE_ID, with_data=True ) - host.registerCallback( - self._changeXMPPPassword, force_id=C.CHANGE_XMPP_PASSWD_ID, with_data=True + host.register_callback( + self._change_xmpp_password, force_id=C.CHANGE_XMPP_PASSWD_ID, with_data=True ) - self.__new_xmpp_passwd_id = host.registerCallback( - self._changeXMPPPasswordCb, with_data=True + self.__new_xmpp_passwd_id = host.register_callback( + self._change_xmpp_password_cb, with_data=True ) - def _startSessionEb(self, fail, first, profile): - """Errback method for startSession during profile authentication + def _start_session_eb(self, fail, first, profile): + """Errback method for start_session during profile authentication @param first(bool): if True, this is the first try and we have tryied empty password in this case we ask for a password to the user. @@ -62,8 +62,8 @@ "form", title=D_("Profile password for {}").format(profile), submit_id="" ) form_ui.addPassword("profile_password", value="") - d = xml_tools.deferredUI(self.host, form_ui, chained=True) - d.addCallback(self._authenticateProfile, profile) + d = xml_tools.deferred_ui(self.host, form_ui, chained=True) + d.addCallback(self._authenticate_profile, profile) return {"xmlui": form_ui.toXml()} assert profile is None @@ -77,13 +77,13 @@ dialog.addText(D_("Internal error: {}".format(fail))) return {"xmlui": dialog.toXml(), "validated": C.BOOL_FALSE} - def _authenticateProfile(self, data, profile): + def _authenticate_profile(self, data, profile): if C.bool(data.get("cancelled", "false")): return {} - if self.host.memory.isSessionStarted(profile): + if self.host.memory.is_session_started(profile): return {"validated": C.BOOL_TRUE} try: - password = data[xml_tools.formEscape("profile_password")] + password = data[xml_tools.form_escape("profile_password")] except KeyError: # first request, we try empty password password = "" @@ -92,30 +92,30 @@ else: first = False eb_profile = None - d = self.host.memory.startSession(password, profile) + d = self.host.memory.start_session(password, profile) d.addCallback(lambda __: {"validated": C.BOOL_TRUE}) - d.addErrback(self._startSessionEb, first, eb_profile) + d.addErrback(self._start_session_eb, first, eb_profile) return d - def _changeXMPPPassword(self, data, profile): - session_data = self._sessions.profileGetUnique(profile) + def _change_xmpp_password(self, data, profile): + session_data = self._sessions.profile_get_unique(profile) if not session_data: - server = self.host.memory.getParamA( + server = self.host.memory.param_get_a( C.FORCE_SERVER_PARAM, "Connection", profile_key=profile ) if not server: server = jid.parse( - self.host.memory.getParamA( + self.host.memory.param_get_a( "JabberID", "Connection", profile_key=profile ) )[1] - session_id, session_data = self._sessions.newSession( + session_id, session_data = self._sessions.new_session( {"count": 0, "server": server}, profile=profile ) if ( session_data["count"] > 2 ): # 3 attempts with a new password after the initial try - self._sessions.profileDelUnique(profile) + self._sessions.profile_del_unique(profile) _dialog = xml_tools.XMLUI("popup", title=D_("Connection error")) _dialog.addText( D_("Can't connect to %s. Please check your connection details.") @@ -140,12 +140,12 @@ form_ui.addPassword("xmpp_password", value="") return {"xmlui": form_ui.toXml()} - def _changeXMPPPasswordCb(self, data, profile): - xmpp_password = data[xml_tools.formEscape("xmpp_password")] - d = self.host.memory.setParam( + def _change_xmpp_password_cb(self, data, profile): + xmpp_password = data[xml_tools.form_escape("xmpp_password")] + d = self.host.memory.param_set( "Password", xmpp_password, "Connection", profile_key=profile ) d.addCallback(lambda __: defer.ensureDeferred(self.host.connect(profile))) d.addCallback(lambda __: {}) - d.addErrback(lambda __: self._changeXMPPPassword({}, profile)) + d.addErrback(lambda __: self._change_xmpp_password({}, profile)) return d