diff sat_frontends/jp/cmd_invitation.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_invitation.py	Wed Jul 31 11:31:22 2019 +0200
+++ b/sat_frontends/jp/cmd_invitation.py	Tue Aug 13 19:08:41 2019 +0200
@@ -18,7 +18,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
-import base
+from . import base
 from sat.core.i18n import _
 from sat_frontends.jp.constants import Const as C
 from sat.tools.common.ansi import ANSI as A
@@ -36,7 +36,7 @@
             "create",
             use_profile=False,
             use_output=C.OUTPUT_DICT,
-            help=_(u"create and send an invitation"),
+            help=_("create and send an invitation"),
         )
         self.need_loop = True
 
@@ -44,28 +44,24 @@
         self.parser.add_argument(
             "-j",
             "--jid",
-            type=base.unicode_decoder,
             default="",
             help="jid of the invitee (default: generate one)",
         )
         self.parser.add_argument(
             "-P",
             "--password",
-            type=base.unicode_decoder,
             default="",
             help="password of the invitee profile/XMPP account (default: generate one)",
         )
         self.parser.add_argument(
             "-n",
             "--name",
-            type=base.unicode_decoder,
             default="",
             help="name of the invitee",
         )
         self.parser.add_argument(
             "-N",
             "--host-name",
-            type=base.unicode_decoder,
             default="",
             help="name of the host",
         )
@@ -73,7 +69,6 @@
             "-e",
             "--email",
             action="append",
-            type=base.unicode_decoder,
             default=[],
             help="email(s) to send the invitation to (if --no-email is set, email will just be saved)",
         )
@@ -83,28 +78,24 @@
         self.parser.add_argument(
             "-l",
             "--lang",
-            type=base.unicode_decoder,
             default="",
             help="main language spoken by the invitee",
         )
         self.parser.add_argument(
             "-u",
             "--url",
-            type=base.unicode_decoder,
             default="",
             help="template to construct the URL",
         )
         self.parser.add_argument(
             "-s",
             "--subject",
-            type=base.unicode_decoder,
             default="",
             help="subject of the invitation email (default: generic subject)",
         )
         self.parser.add_argument(
             "-b",
             "--body",
-            type=base.unicode_decoder,
             default="",
             help="body of the invitation email (default: generic body)",
         )
@@ -112,7 +103,6 @@
             "-x",
             "--extra",
             metavar=("KEY", "VALUE"),
-            type=base.unicode_decoder,
             action="append",
             nargs=2,
             default=[],
@@ -121,7 +111,6 @@
         self.parser.add_argument(
             "-p",
             "--profile",
-            type=base.unicode_decoder,
             default="",
             help="profile doing the invitation (default: don't associate profile)",
         )
@@ -132,7 +121,7 @@
 
     def invitationCreateEb(self, failure_):
         self.disp(
-            u"can't create invitation: {reason}".format(reason=failure_), error=True
+            "can't create invitation: {reason}".format(reason=failure_), error=True
         )
         self.host.quit(C.EXIT_BRIDGE_ERRBACK)
 
@@ -143,11 +132,11 @@
         if self.args.no_email:
             if email:
                 extra["email"] = email
-                data_format.iter2dict(u"emails_extra", emails_extra)
+                data_format.iter2dict("emails_extra", emails_extra)
         else:
             if not email:
                 self.parser.error(
-                    _(u"you need to specify an email address to send email invitation")
+                    _("you need to specify an email address to send email invitation")
                 )
 
         self.host.bridge.invitationCreate(
@@ -176,19 +165,19 @@
             "get",
             use_profile=False,
             use_output=C.OUTPUT_DICT,
-            help=_(u"get invitation data"),
+            help=_("get invitation data"),
         )
         self.need_loop = True
 
     def add_parser_options(self):
         self.parser.add_argument(
-            "id", type=base.unicode_decoder, help=_(u"invitation UUID")
+            "id", help=_("invitation UUID")
         )
         self.parser.add_argument(
             "-j",
             "--with-jid",
             action="store_true",
-            help=_(u"start profile session and retrieve jid"),
+            help=_("start profile session and retrieve jid"),
         )
 
     def output_data(self, data, jid_=None):
@@ -199,28 +188,28 @@
 
     def invitationGetCb(self, invitation_data):
         if self.args.with_jid:
-            profile = invitation_data[u"guest_profile"]
+            profile = invitation_data["guest_profile"]
 
             def session_started(__):
                 self.host.bridge.asyncGetParamA(
-                    u"JabberID",
-                    u"Connection",
+                    "JabberID",
+                    "Connection",
                     profile_key=profile,
                     callback=lambda jid_: self.output_data(invitation_data, jid_),
                     errback=partial(
                         self.errback,
-                        msg=_(u"can't retrieve jid: {}"),
+                        msg=_("can't retrieve jid: {}"),
                         exit_code=C.EXIT_BRIDGE_ERRBACK,
                     ),
                 )
 
             self.host.bridge.profileStartSession(
-                invitation_data[u"password"],
+                invitation_data["password"],
                 profile,
                 callback=session_started,
                 errback=partial(
                     self.errback,
-                    msg=_(u"can't start session: {}"),
+                    msg=_("can't start session: {}"),
                     exit_code=C.EXIT_BRIDGE_ERRBACK,
                 ),
             )
@@ -233,7 +222,7 @@
             callback=self.invitationGetCb,
             errback=partial(
                 self.errback,
-                msg=_(u"can't get invitation data: {}"),
+                msg=_("can't get invitation data: {}"),
                 exit_code=C.EXIT_BRIDGE_ERRBACK,
             ),
         )
@@ -242,7 +231,7 @@
 class Modify(base.CommandBase):
     def __init__(self, host):
         base.CommandBase.__init__(
-            self, host, "modify", use_profile=False, help=_(u"modify existing invitation")
+            self, host, "modify", use_profile=False, help=_("modify existing invitation")
         )
         self.need_loop = True
 
@@ -253,21 +242,18 @@
         self.parser.add_argument(
             "-n",
             "--name",
-            type=base.unicode_decoder,
             default="",
             help="name of the invitee",
         )
         self.parser.add_argument(
             "-N",
             "--host-name",
-            type=base.unicode_decoder,
             default="",
             help="name of the host",
         )
         self.parser.add_argument(
             "-e",
             "--email",
-            type=base.unicode_decoder,
             default="",
             help="email to send the invitation to (if --no-email is set, email will just be saved)",
         )
@@ -275,7 +261,6 @@
             "-l",
             "--lang",
             dest="language",
-            type=base.unicode_decoder,
             default="",
             help="main language spoken by the invitee",
         )
@@ -283,7 +268,6 @@
             "-x",
             "--extra",
             metavar=("KEY", "VALUE"),
-            type=base.unicode_decoder,
             action="append",
             nargs=2,
             default=[],
@@ -292,21 +276,20 @@
         self.parser.add_argument(
             "-p",
             "--profile",
-            type=base.unicode_decoder,
             default="",
             help="profile doing the invitation (default: don't associate profile",
         )
         self.parser.add_argument(
-            "id", type=base.unicode_decoder, help=_(u"invitation UUID")
+            "id", help=_("invitation UUID")
         )
 
     def invitationModifyCb(self):
-        self.disp(_(u"invitations have been modified correctly"))
+        self.disp(_("invitations have been modified correctly"))
         self.host.quit(C.EXIT_OK)
 
     def invitationModifyEb(self, failure_):
         self.disp(
-            u"can't create invitation: {reason}".format(reason=failure_), error=True
+            "can't create invitation: {reason}".format(reason=failure_), error=True
         )
         self.host.quit(C.EXIT_BRIDGE_ERRBACK)
 
@@ -319,7 +302,7 @@
             if arg_name in extra:
                 self.parser.error(
                     _(
-                        u"you can't set {arg_name} in both optional argument and extra"
+                        "you can't set {arg_name} in both optional argument and extra"
                     ).format(arg_name=arg_name)
                 )
             extra[arg_name] = value
@@ -342,26 +325,26 @@
             use_profile=False,
             use_output=C.OUTPUT_COMPLEX,
             extra_outputs=extra_outputs,
-            help=_(u"list invitations data"),
+            help=_("list invitations data"),
         )
         self.need_loop = True
 
     def default_output(self, data):
-        for idx, datum in enumerate(data.iteritems()):
+        for idx, datum in enumerate(data.items()):
             if idx:
-                self.disp(u"\n")
+                self.disp("\n")
             key, invitation_data = datum
             self.disp(A.color(C.A_HEADER, key))
-            indent = u"  "
-            for k, v in invitation_data.iteritems():
-                self.disp(indent + A.color(C.A_SUBHEADER, k + u":") + u" " + unicode(v))
+            indent = "  "
+            for k, v in invitation_data.items():
+                self.disp(indent + A.color(C.A_SUBHEADER, k + ":") + " " + str(v))
 
     def add_parser_options(self):
         self.parser.add_argument(
             "-p",
             "--profile",
             default=C.PROF_KEY_NONE,
-            help=_(u"return only invitations linked to this profile"),
+            help=_("return only invitations linked to this profile"),
         )
 
     def invitationListCb(self, data):
@@ -374,7 +357,7 @@
             callback=self.invitationListCb,
             errback=partial(
                 self.errback,
-                msg=_(u"can't list invitations: {}"),
+                msg=_("can't list invitations: {}"),
                 exit_code=C.EXIT_BRIDGE_ERRBACK,
             ),
         )
@@ -388,5 +371,5 @@
             host,
             "invitation",
             use_profile=False,
-            help=_(u"invitation of user(s) without XMPP account"),
+            help=_("invitation of user(s) without XMPP account"),
         )