diff sat_frontends/jp/cmd_encryption.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_encryption.py	Wed Jul 31 11:31:22 2019 +0200
+++ b/sat_frontends/jp/cmd_encryption.py	Tue Aug 13 19:08:41 2019 +0200
@@ -48,10 +48,10 @@
 
     def default_output(self, plugins):
         if not plugins:
-            self.disp(_(u"No encryption plugin registered!"))
+            self.disp(_("No encryption plugin registered!"))
             self.host.quit(C.EXIT_NOT_FOUND)
         else:
-            self.disp(_(u"Following encryption algorithms are available: {algos}").format(
+            self.disp(_("Following encryption algorithms are available: {algos}").format(
                 algos=', '.join([p['name'] for p in plugins])))
             self.host.quit()
 
@@ -60,7 +60,7 @@
             callback=self.encryptionPluginsGetCb,
             errback=partial(
                 self.errback,
-                msg=_(u"can't retrieve plugins: {}"),
+                msg=_("can't retrieve plugins: {}"),
                 exit_code=C.EXIT_BRIDGE_ERRBACK,
             ),
         )
@@ -72,20 +72,20 @@
         super(EncryptionGet, self).__init__(
             host, "get",
             use_output=C.OUTPUT_DICT,
-            help=_(u"get encryption session data"))
+            help=_("get encryption session data"))
         self.need_loop = True
 
     def add_parser_options(self):
         self.parser.add_argument(
-            "jid", type=base.unicode_decoder,
-            help=_(u"jid of the entity to check")
+            "jid",
+            help=_("jid of the entity to check")
         )
 
     def messageEncryptionGetCb(self, serialised):
         session_data = data_format.deserialise(serialised)
         if session_data is None:
             self.disp(
-                u"No encryption session found, the messages are sent in plain text.")
+                "No encryption session found, the messages are sent in plain text.")
             self.host.quit(C.EXIT_NOT_FOUND)
         self.output(session_data)
         self.host.quit()
@@ -98,7 +98,7 @@
             callback=self.messageEncryptionGetCb,
             errback=partial(
                 self.errback,
-                msg=_(u"can't get session: {}"),
+                msg=_("can't get session: {}"),
                 exit_code=C.EXIT_BRIDGE_ERRBACK,
             ),
         )
@@ -109,23 +109,23 @@
     def __init__(self, host):
         super(EncryptionStart, self).__init__(
             host, "start",
-            help=_(u"start encrypted session with an entity"))
+            help=_("start encrypted session with an entity"))
         self.need_loop = True
 
     def add_parser_options(self):
         self.parser.add_argument(
             "--encrypt-noreplace",
             action="store_true",
-            help=_(u"don't replace encryption algorithm if an other one is already used"))
+            help=_("don't replace encryption algorithm if an other one is already used"))
         algorithm = self.parser.add_mutually_exclusive_group()
         algorithm.add_argument(
-            "-n", "--name", help=_(u"algorithm name (DEFAULT: choose automatically)"))
+            "-n", "--name", help=_("algorithm name (DEFAULT: choose automatically)"))
         algorithm.add_argument(
             "-N", "--namespace",
-            help=_(u"algorithm namespace (DEFAULT: choose automatically)"))
+            help=_("algorithm namespace (DEFAULT: choose automatically)"))
         self.parser.add_argument(
-            "jid", type=base.unicode_decoder,
-            help=_(u"jid of the entity to stop encrypted session with")
+            "jid",
+            help=_("jid of the entity to stop encrypted session with")
         )
 
     def encryptionNamespaceGetCb(self, namespace):
@@ -136,7 +136,7 @@
             self.profile,
             callback=self.host.quit,
             errback=partial(self.errback,
-                            msg=_(u"Can't start encryption session: {}"),
+                            msg=_("Can't start encryption session: {}"),
                             exit_code=C.EXIT_BRIDGE_ERRBACK,
                             ))
 
@@ -145,13 +145,13 @@
             self.host.bridge.encryptionNamespaceGet(self.args.name,
                 callback=self.encryptionNamespaceGetCb,
                 errback=partial(self.errback,
-                                msg=_(u"Can't get encryption namespace: {}"),
+                                msg=_("Can't get encryption namespace: {}"),
                                 exit_code=C.EXIT_BRIDGE_ERRBACK,
                                 ))
         elif self.args.namespace is not None:
             self.encryptionNamespaceGetCb(self.args.namespace)
         else:
-            self.encryptionNamespaceGetCb(u"")
+            self.encryptionNamespaceGetCb("")
 
 
 class EncryptionStop(base.CommandBase):
@@ -159,13 +159,13 @@
     def __init__(self, host):
         super(EncryptionStop, self).__init__(
             host, "stop",
-            help=_(u"stop encrypted session with an entity"))
+            help=_("stop encrypted session with an entity"))
         self.need_loop = True
 
     def add_parser_options(self):
         self.parser.add_argument(
-            "jid", type=base.unicode_decoder,
-            help=_(u"jid of the entity to stop encrypted session with")
+            "jid",
+            help=_("jid of the entity to stop encrypted session with")
         )
 
     def start(self):
@@ -176,7 +176,7 @@
             callback=self.host.quit,
             errback=partial(
                 self.errback,
-                msg=_(u"can't end encrypted session: {}"),
+                msg=_("can't end encrypted session: {}"),
                 exit_code=C.EXIT_BRIDGE_ERRBACK,
             ),
         )
@@ -187,20 +187,20 @@
     def __init__(self, host):
         super(TrustUI, self).__init__(
             host, "ui",
-            help=_(u"get UI to manage trust"))
+            help=_("get UI to manage trust"))
         self.need_loop = True
 
     def add_parser_options(self):
         self.parser.add_argument(
-            "jid", type=base.unicode_decoder,
-            help=_(u"jid of the entity to stop encrypted session with")
+            "jid",
+            help=_("jid of the entity to stop encrypted session with")
         )
         algorithm = self.parser.add_mutually_exclusive_group()
         algorithm.add_argument(
-            "-n", "--name", help=_(u"algorithm name (DEFAULT: current algorithm)"))
+            "-n", "--name", help=_("algorithm name (DEFAULT: current algorithm)"))
         algorithm.add_argument(
             "-N", "--namespace",
-            help=_(u"algorithm namespace (DEFAULT: current algorithm)"))
+            help=_("algorithm namespace (DEFAULT: current algorithm)"))
 
     def encryptionTrustUIGetCb(self, xmlui_raw):
         xmlui = xmlui_manager.create(self.host, xmlui_raw)
@@ -215,7 +215,7 @@
             callback=self.encryptionTrustUIGetCb,
             errback=partial(
                 self.errback,
-                msg=_(u"can't end encrypted session: {}"),
+                msg=_("can't end encrypted session: {}"),
                 exit_code=C.EXIT_BRIDGE_ERRBACK,
             ),
         )
@@ -225,13 +225,13 @@
             self.host.bridge.encryptionNamespaceGet(self.args.name,
                 callback=self.encryptionNamespaceGetCb,
                 errback=partial(self.errback,
-                                msg=_(u"Can't get encryption namespace: {}"),
+                                msg=_("Can't get encryption namespace: {}"),
                                 exit_code=C.EXIT_BRIDGE_ERRBACK,
                                 ))
         elif self.args.namespace is not None:
             self.encryptionNamespaceGetCb(self.args.namespace)
         else:
-            self.encryptionNamespaceGetCb(u"")
+            self.encryptionNamespaceGetCb("")
 
 
 class EncryptionTrust(base.CommandBase):
@@ -239,7 +239,7 @@
 
     def __init__(self, host):
         super(EncryptionTrust, self).__init__(
-            host, "trust", use_profile=False, help=_(u"trust manangement")
+            host, "trust", use_profile=False, help=_("trust manangement")
         )
 
 
@@ -249,5 +249,5 @@
 
     def __init__(self, host):
         super(Encryption, self).__init__(
-            host, "encryption", use_profile=False, help=_(u"encryption sessions handling")
+            host, "encryption", use_profile=False, help=_("encryption sessions handling")
         )