diff sat/plugins/plugin_misc_register_account.py @ 2624:56f94936df1e

code style reformatting using black
author Goffi <goffi@goffi.org>
date Wed, 27 Jun 2018 20:14:46 +0200
parents 26edcf3a30eb
children 378188abe941
line wrap: on
line diff
--- a/sat/plugins/plugin_misc_register_account.py	Wed Jun 27 07:51:29 2018 +0200
+++ b/sat/plugins/plugin_misc_register_account.py	Wed Jun 27 20:14:46 2018 +0200
@@ -20,6 +20,7 @@
 
 from sat.core.i18n import _, D_
 from sat.core.log import getLogger
+
 log = getLogger(__name__)
 from sat.core.constants import Const as C
 from twisted.words.protocols.jabber import jid
@@ -37,7 +38,7 @@
     C.PI_RECOMMENDATIONS: [],
     C.PI_MAIN: "RegisterAccount",
     C.PI_HANDLER: "no",
-    C.PI_DESCRIPTION: _(u"""Register XMPP account""")
+    C.PI_DESCRIPTION: _(u"""Register XMPP account"""),
 }
 
 
@@ -48,8 +49,12 @@
         log.info(_(u"Plugin Register Account initialization"))
         self.host = host
         self._sessions = Sessions()
-        host.registerCallback(self.registerNewAccountCB, with_data=True, force_id="registerNewAccount")
-        self.__register_account_id = host.registerCallback(self._registerConfirmation, with_data=True)
+        host.registerCallback(
+            self.registerNewAccountCB, with_data=True, force_id="registerNewAccount"
+        )
+        self.__register_account_id = host.registerCallback(
+            self._registerConfirmation, with_data=True
+        )
 
     def registerNewAccountCB(self, data, profile):
         """Called when the user click on the "New account" button."""
@@ -57,57 +62,92 @@
 
         # FIXME: following loop is overcomplicated, hard to read
         # FIXME: while used with parameters, hashed password is used and overwrite clear one
-        for param in (u'JabberID', u'Password', C.FORCE_PORT_PARAM, C.FORCE_SERVER_PARAM):
+        for param in (u"JabberID", u"Password", C.FORCE_PORT_PARAM, C.FORCE_SERVER_PARAM):
             try:
-                session_data[param] = data[SAT_FORM_PREFIX + u"Connection" + SAT_PARAM_SEPARATOR + param]
+                session_data[param] = data[
+                    SAT_FORM_PREFIX + u"Connection" + SAT_PARAM_SEPARATOR + param
+                ]
             except KeyError:
                 if param in (C.FORCE_PORT_PARAM, C.FORCE_SERVER_PARAM):
-                    session_data[param] = ''
+                    session_data[param] = ""
 
-        for param in (u'JabberID', u'Password'):
+        for param in (u"JabberID", u"Password"):
             if not session_data[param]:
                 form_ui = xml_tools.XMLUI(u"popup", title=D_(u"Missing values"))
-                form_ui.addText(D_(u"No user JID or password given: can't register new account."))
-                return  {u'xmlui': form_ui.toXml()}
+                form_ui.addText(
+                    D_(u"No user JID or password given: can't register new account.")
+                )
+                return {u"xmlui": form_ui.toXml()}
 
-        session_data['user'], host, resource = jid.parse(session_data['JabberID'])
-        session_data['server'] = session_data[C.FORCE_SERVER_PARAM] or host
+        session_data["user"], host, resource = jid.parse(session_data["JabberID"])
+        session_data["server"] = session_data[C.FORCE_SERVER_PARAM] or host
         session_id, dummy = self._sessions.newSession(session_data, profile=profile)
-        form_ui = xml_tools.XMLUI("form", title=D_("Register new account"), submit_id=self.__register_account_id, session_id=session_id)
-        form_ui.addText(D_(u"Do you want to register a new XMPP account {jid}?").format(
-            jid = session_data['JabberID']))
-        return  {'xmlui': form_ui.toXml()}
+        form_ui = xml_tools.XMLUI(
+            "form",
+            title=D_("Register new account"),
+            submit_id=self.__register_account_id,
+            session_id=session_id,
+        )
+        form_ui.addText(
+            D_(u"Do you want to register a new XMPP account {jid}?").format(
+                jid=session_data["JabberID"]
+            )
+        )
+        return {"xmlui": form_ui.toXml()}
 
     def _registerConfirmation(self, data, profile):
         """Save the related parameters and proceed the registration."""
-        session_data = self._sessions.profileGet(data['session_id'], profile)
+        session_data = self._sessions.profileGet(data["session_id"], profile)
 
-        self.host.memory.setParam("JabberID", session_data["JabberID"], "Connection", profile_key=profile)
-        self.host.memory.setParam("Password", session_data["Password"], "Connection", profile_key=profile)
-        self.host.memory.setParam(C.FORCE_SERVER_PARAM, session_data[C.FORCE_SERVER_PARAM], "Connection", profile_key=profile)
-        self.host.memory.setParam(C.FORCE_PORT_PARAM, session_data[C.FORCE_PORT_PARAM], "Connection", profile_key=profile)
+        self.host.memory.setParam(
+            "JabberID", session_data["JabberID"], "Connection", profile_key=profile
+        )
+        self.host.memory.setParam(
+            "Password", session_data["Password"], "Connection", profile_key=profile
+        )
+        self.host.memory.setParam(
+            C.FORCE_SERVER_PARAM,
+            session_data[C.FORCE_SERVER_PARAM],
+            "Connection",
+            profile_key=profile,
+        )
+        self.host.memory.setParam(
+            C.FORCE_PORT_PARAM,
+            session_data[C.FORCE_PORT_PARAM],
+            "Connection",
+            profile_key=profile,
+        )
 
-        d = self._registerNewAccount(jid.JID(session_data['JabberID']), session_data["Password"], None, session_data['server'])
-        del self._sessions[data['session_id']]
+        d = self._registerNewAccount(
+            jid.JID(session_data["JabberID"]),
+            session_data["Password"],
+            None,
+            session_data["server"],
+        )
+        del self._sessions[data["session_id"]]
         return d
 
     def _registerNewAccount(self, client, jid_, password, email, server):
-        # FIXME: port is not set here
+        #  FIXME: port is not set here
         def registeredCb(dummy):
             xmlui = xml_tools.XMLUI(u"popup", title=D_(u"Confirmation"))
             xmlui.addText(D_("Registration successful."))
-            return ({'xmlui': xmlui.toXml()})
+            return {"xmlui": xmlui.toXml()}
 
         def registeredEb(failure):
             xmlui = xml_tools.XMLUI("popup", title=D_("Failure"))
             xmlui.addText(D_("Registration failed: %s") % failure.getErrorMessage())
             try:
-                if failure.value.condition == 'conflict':
-                    xmlui.addText(D_("Username already exists, please choose an other one."))
+                if failure.value.condition == "conflict":
+                    xmlui.addText(
+                        D_("Username already exists, please choose an other one.")
+                    )
             except AttributeError:
                 pass
-            return ({'xmlui': xmlui.toXml()})
+            return {"xmlui": xmlui.toXml()}
 
-        registered_d = self.host.plugins['XEP-0077'].registerNewAccount(client, jid_, password, email=email, host=server, port=C.XMPP_C2S_PORT)
+        registered_d = self.host.plugins["XEP-0077"].registerNewAccount(
+            client, jid_, password, email=email, host=server, port=C.XMPP_C2S_PORT
+        )
         registered_d.addCallbacks(registeredCb, registeredEb)
         return registered_d