diff sat_frontends/jp/cmd_account.py @ 3028:ab2696e34d29

Python 3 port: /!\ this is a huge commit /!\ starting from this commit, SàT is needs Python 3.6+ /!\ SàT maybe be instable or some feature may not work anymore, this will improve with time This patch port backend, bridge and frontends to Python 3. Roughly this has been done this way: - 2to3 tools has been applied (with python 3.7) - all references to python2 have been replaced with python3 (notably shebangs) - fixed files not handled by 2to3 (notably the shell script) - several manual fixes - fixed issues reported by Python 3 that where not handled in Python 2 - replaced "async" with "async_" when needed (it's a reserved word from Python 3.7) - replaced zope's "implements" with @implementer decorator - temporary hack to handle data pickled in database, as str or bytes may be returned, to be checked later - fixed hash comparison for password - removed some code which is not needed anymore with Python 3 - deactivated some code which needs to be checked (notably certificate validation) - tested with jp, fixed reported issues until some basic commands worked - ported Primitivus (after porting dependencies like urwid satext) - more manual fixes
author Goffi <goffi@goffi.org>
date Tue, 13 Aug 2019 19:08:41 +0200
parents 003b8b4b56a7
children fee60f17ebac
line wrap: on
line diff
--- a/sat_frontends/jp/cmd_account.py	Wed Jul 31 11:31:22 2019 +0200
+++ b/sat_frontends/jp/cmd_account.py	Tue Aug 13 19:08:41 2019 +0200
@@ -37,45 +37,42 @@
             "create",
             use_profile=False,
             use_verbose=True,
-            help=_(u"create a XMPP account"),
+            help=_("create a XMPP account"),
         )
         self.need_loop = True
 
     def add_parser_options(self):
         self.parser.add_argument(
-            "jid", type=base.unicode_decoder, help=_(u"jid to create")
+            "jid", help=_("jid to create")
         )
         self.parser.add_argument(
-            "password", type=base.unicode_decoder, help=_(u"password of the account")
+            "password", help=_("password of the account")
         )
         self.parser.add_argument(
             "-p",
             "--profile",
-            type=base.unicode_decoder,
             help=_(
-                u"create a profile to use this account (default: don't create profile)"
+                "create a profile to use this account (default: don't create profile)"
             ),
         )
         self.parser.add_argument(
             "-e",
             "--email",
-            type=base.unicode_decoder,
             default="",
-            help=_(u"email (usage depends of XMPP server)"),
+            help=_("email (usage depends of XMPP server)"),
         )
         self.parser.add_argument(
             "-H",
             "--host",
-            type=base.unicode_decoder,
             default="",
-            help=_(u"server host (IP address or domain, default: use localhost)"),
+            help=_("server host (IP address or domain, default: use localhost)"),
         )
         self.parser.add_argument(
             "-P",
             "--port",
             type=int,
             default=0,
-            help=_(u"server port (IP address or domain, default: use localhost)"),
+            help=_("server port (IP address or domain, default: use localhost)"),
         )
 
     def _setParamCb(self):
@@ -99,7 +96,7 @@
         )
 
     def _profileCreateCb(self):
-        self.disp(_(u"profile created"), 1)
+        self.disp(_("profile created"), 1)
         self.host.bridge.profileStartSession(
             self.args.password,
             self.args.profile,
@@ -110,16 +107,16 @@
     def _profileCreateEb(self, failure_):
         self.disp(
             _(
-                u"Can't create profile {profile} to associate with jid {jid}: {msg}"
+                "Can't create profile {profile} to associate with jid {jid}: {msg}"
             ).format(profile=self.args.profile, jid=self.args.jid, msg=failure_),
             error=True,
         )
         self.host.quit(C.EXIT_BRIDGE_ERRBACK)
 
     def accountNewCb(self):
-        self.disp(_(u"XMPP account created"), 1)
+        self.disp(_("XMPP account created"), 1)
         if self.args.profile is not None:
-            self.disp(_(u"creating profile"), 2)
+            self.disp(_("creating profile"), 2)
             self.host.bridge.profileCreate(
                 self.args.profile,
                 self.args.password,
@@ -132,8 +129,8 @@
 
     def accountNewEb(self, failure_):
         self.disp(
-            _(u"Can't create new account on server {host} with jid {jid}: {msg}").format(
-                host=self.args.host or u"localhost", jid=self.args.jid, msg=failure_
+            _("Can't create new account on server {host} with jid {jid}: {msg}").format(
+                host=self.args.host or "localhost", jid=self.args.jid, msg=failure_
             ),
             error=True,
         )
@@ -154,13 +151,13 @@
 class AccountModify(base.CommandBase):
     def __init__(self, host):
         super(AccountModify, self).__init__(
-            host, "modify", help=_(u"change password for XMPP account")
+            host, "modify", help=_("change password for XMPP account")
         )
         self.need_loop = True
 
     def add_parser_options(self):
         self.parser.add_argument(
-            "password", type=base.unicode_decoder, help=_(u"new XMPP password")
+            "password", help=_("new XMPP password")
         )
 
     def start(self):
@@ -175,7 +172,7 @@
 class AccountDelete(base.CommandBase):
     def __init__(self, host):
         super(AccountDelete, self).__init__(
-            host, "delete", help=_(u"delete a XMPP account")
+            host, "delete", help=_("delete a XMPP account")
         )
         self.need_loop = True
 
@@ -184,22 +181,22 @@
             "-f",
             "--force",
             action="store_true",
-            help=_(u"delete account without confirmation"),
+            help=_("delete account without confirmation"),
         )
 
     def _got_jid(self, jid_str):
         jid_ = jid.JID(jid_str)
         if not self.args.force:
             message = (
-                u"You are about to delete the XMPP account with jid {jid_}\n"
-                u'This is the XMPP account of profile "{profile}"\n'
-                u"Are you sure that you want to delete this account ?".format(
+                "You are about to delete the XMPP account with jid {jid_}\n"
+                'This is the XMPP account of profile "{profile}"\n'
+                "Are you sure that you want to delete this account ?".format(
                     jid_=jid_, profile=self.profile
                 )
             )
-            res = raw_input("{} (y/N)? ".format(message))
+            res = input("{} (y/N)? ".format(message))
             if res not in ("y", "Y"):
-                self.disp(_(u"Account deletion cancelled"))
+                self.disp(_("Account deletion cancelled"))
                 self.host.quit(2)
         self.host.bridge.inBandUnregister(
             jid_.domain, self.args.profile, callback=self.host.quit, errback=self.errback
@@ -220,5 +217,5 @@
 
     def __init__(self, host):
         super(Account, self).__init__(
-            host, "account", use_profile=False, help=(u"XMPP account management")
+            host, "account", use_profile=False, help=("XMPP account management")
         )