diff sat_frontends/jp/cmd_debug.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_debug.py	Wed Jul 31 11:31:22 2019 +0200
+++ b/sat_frontends/jp/cmd_debug.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
@@ -31,11 +31,11 @@
     def evalArgs(self):
         if self.args.arg:
             try:
-                return eval(u"[{}]".format(u",".join(self.args.arg)))
+                return eval("[{}]".format(",".join(self.args.arg)))
             except SyntaxError as e:
                 self.disp(
-                    u"Can't evaluate arguments: {mess}\n{text}\n{offset}^".format(
-                        mess=e, text=e.text.decode("utf-8"), offset=u" " * (e.offset - 1)
+                    "Can't evaluate arguments: {mess}\n{text}\n{offset}^".format(
+                        mess=e, text=e.text, offset=" " * (e.offset - 1)
                     ),
                     error=True,
                 )
@@ -46,26 +46,26 @@
 
 class Method(base.CommandBase, BridgeCommon):
     def __init__(self, host):
-        base.CommandBase.__init__(self, host, "method", help=_(u"call a bridge method"))
+        base.CommandBase.__init__(self, host, "method", help=_("call a bridge method"))
         BridgeCommon.__init__(self)
         self.need_loop = True
 
     def add_parser_options(self):
         self.parser.add_argument(
-            "method", type=str, help=_(u"name of the method to execute")
+            "method", type=str, help=_("name of the method to execute")
         )
         self.parser.add_argument(
-            "arg", type=base.unicode_decoder, nargs="*", help=_(u"argument of the method")
+            "arg", nargs="*", help=_("argument of the method")
         )
 
     def method_cb(self, ret=None):
         if ret is not None:
-            self.disp(unicode(ret))
+            self.disp(str(ret))
         self.host.quit()
 
     def method_eb(self, failure):
         self.disp(
-            _(u"Error while executing {}: {}".format(self.args.method, failure)),
+            _("Error while executing {}: {}".format(self.args.method, failure)),
             error=True,
         )
         self.host.quit(C.EXIT_ERROR)
@@ -85,22 +85,22 @@
             try:
                 method(*args, callback=self.method_cb, errback=self.method_eb)
             except TypeError:
-                self.method_eb(_(u"bad arguments"))
+                self.method_eb(_("bad arguments"))
 
 
 class Signal(base.CommandBase, BridgeCommon):
     def __init__(self, host):
         base.CommandBase.__init__(
-            self, host, "signal", help=_(u"send a fake signal from backend")
+            self, host, "signal", help=_("send a fake signal from backend")
         )
         BridgeCommon.__init__(self)
 
     def add_parser_options(self):
         self.parser.add_argument(
-            "signal", type=str, help=_(u"name of the signal to send")
+            "signal", type=str, help=_("name of the signal to send")
         )
         self.parser.add_argument(
-            "arg", type=base.unicode_decoder, nargs="*", help=_(u"argument of the signal")
+            "arg", nargs="*", help=_("argument of the signal")
         )
 
     def start(self):
@@ -138,7 +138,7 @@
             "--direction",
             choices=("in", "out", "both"),
             default="both",
-            help=_(u"stream direction filter"),
+            help=_("stream direction filter"),
         )
 
     def printXML(self, direction, xml_data, profile):
@@ -155,7 +155,7 @@
             whiteping = False
 
         if verbosity:
-            profile_disp = u" ({})".format(profile) if verbosity > 1 else u""
+            profile_disp = " ({})".format(profile) if verbosity > 1 else ""
             if direction == "IN":
                 self.disp(
                     A.color(
@@ -180,7 +180,7 @@
                 #        but importing lxml directly here is not clean
                 #        should be wrapped in a custom Exception
                 self.disp(xml_data)
-                self.disp(u"")
+                self.disp("")
 
     def start(self):
         self.host.bridge.register_signal("xmlLog", self.printXML, "plugin")