diff sat_frontends/jp/xmlui_manager.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 620bbcec884c
children fee60f17ebac
line wrap: on
line diff
--- a/sat_frontends/jp/xmlui_manager.py	Wed Jul 31 11:31:22 2019 +0200
+++ b/sat_frontends/jp/xmlui_manager.py	Tue Aug 13 19:08:41 2019 +0200
@@ -60,7 +60,7 @@
 
 
 class Widget(Base):
-    category = u"widget"
+    category = "widget"
     enabled = True
 
     @property
@@ -89,8 +89,8 @@
         if self.host.verbosity:
             to_disp = [
                 A.FG_MAGENTA,
-                u" " if elems else u"",
-                u"({})".format(value),
+                " " if elems else "",
+                "({})".format(value),
                 A.RESET,
             ]
             if elems is None:
@@ -166,11 +166,11 @@
 
     @property
     def inline(self):
-        return u"inline" in self.style
+        return "inline" in self.style
 
     @property
     def no_select(self):
-        return u"noselect" in self.style
+        return "noselect" in self.style
 
 
 class EmptyWidget(xmlui_base.EmptyWidget, Widget):
@@ -179,18 +179,18 @@
         Widget.__init__(self, xmlui_parent)
 
     def show(self):
-        self.host.disp(u'')
+        self.host.disp('')
 
 
 class TextWidget(xmlui_base.TextWidget, ValueWidget):
-    type = u"text"
+    type = "text"
 
     def show(self):
         self.host.disp(self.value)
 
 
 class LabelWidget(xmlui_base.LabelWidget, ValueWidget):
-    type = u"label"
+    type = "label"
 
     @property
     def for_name(self):
@@ -199,7 +199,7 @@
         except AttributeError:
             return None
 
-    def show(self, no_lf=False, ansi=u""):
+    def show(self, no_lf=False, ansi=""):
         """show label
 
         @param no_lf(bool): same as for [JP.disp]
@@ -209,10 +209,10 @@
 
 
 class JidWidget(xmlui_base.JidWidget, TextWidget):
-    type = u"jid"
+    type = "jid"
 
 class StringWidget(xmlui_base.StringWidget, InputWidget):
-    type = u"string"
+    type = "string"
 
     def show(self):
         if self.read_only or self.root.read_only:
@@ -221,9 +221,9 @@
             elems = []
             self.verboseName(elems)
             if self.value:
-                elems.append(_(u"(enter: {default})").format(default=self.value))
-            elems.extend([C.A_HEADER, u"> "])
-            value = raw_input(A.color(*elems).encode('utf-8'))
+                elems.append(_("(enter: {default})").format(default=self.value))
+            elems.extend([C.A_HEADER, "> "])
+            value = input(A.color(*elems).encode('utf-8'))
             if value:
                 #  TODO: empty value should be possible
                 #       an escape key should be used for default instead of enter with empty value
@@ -231,11 +231,11 @@
 
 
 class JidInputWidget(xmlui_base.JidInputWidget, StringWidget):
-    type = u"jid_input"
+    type = "jid_input"
 
 
 class TextBoxWidget(xmlui_base.TextWidget, StringWidget):
-    type = u"textbox"
+    type = "textbox"
     # TODO: use a more advanced input method
 
     def show(self):
@@ -244,25 +244,25 @@
             self.disp(self.value)
         else:
             if self.value:
-                self.disp(A.color(C.A_HEADER, u"↓ current value ↓\n", A.FG_CYAN, self.value,
+                self.disp(A.color(C.A_HEADER, "↓ current value ↓\n", A.FG_CYAN, self.value,
                                   ""))
 
             values = []
             while True:
                 try:
                     if not values:
-                        line = raw_input(A.color(C.A_HEADER, u"[Ctrl-D to finish]> "))
+                        line = input(A.color(C.A_HEADER, "[Ctrl-D to finish]> "))
                     else:
-                        line = raw_input()
+                        line = input()
                     values.append(line)
                 except EOFError:
                    break
 
-            self.value = u'\n'.join(values).rstrip()
+            self.value = '\n'.join(values).rstrip()
 
 
 class XHTMLBoxWidget(xmlui_base.XHTMLBoxWidget, StringWidget):
-    type = u"xhtmlbox"
+    type = "xhtmlbox"
 
     def show(self):
         # FIXME: we use bridge in a blocking way as permitted by python-dbus
@@ -274,7 +274,7 @@
 
 
 class ListWidget(xmlui_base.ListWidget, OptionsWidget):
-    type = u"list"
+    type = "list"
     # TODO: handle flags, notably multi
 
     def show(self):
@@ -291,7 +291,7 @@
         for idx, (value, label) in enumerate(self.options):
             elems = []
             if not self.root.read_only:
-                elems.extend([C.A_SUBHEADER, unicode(idx), A.RESET, u": "])
+                elems.extend([C.A_SUBHEADER, str(idx), A.RESET, ": "])
             elems.append(label)
             self.verboseName(elems, value)
             self.disp(A.color(*elems))
@@ -308,8 +308,8 @@
         choice = None
         limit_max = len(self.options) - 1
         while choice is None or choice < 0 or choice > limit_max:
-            choice = raw_input(
-                A.color(C.A_HEADER, _(u"your choice (0-{max}): ").format(max=limit_max))
+            choice = input(
+                A.color(C.A_HEADER, _("your choice (0-{max}): ").format(max=limit_max))
             )
             try:
                 choice = int(choice)
@@ -320,25 +320,25 @@
 
 
 class BoolWidget(xmlui_base.BoolWidget, InputWidget):
-    type = u"bool"
+    type = "bool"
 
     def show(self):
-        disp_true = A.color(A.FG_GREEN, u"TRUE")
-        disp_false = A.color(A.FG_RED, u"FALSE")
+        disp_true = A.color(A.FG_GREEN, "TRUE")
+        disp_false = A.color(A.FG_RED, "FALSE")
         if self.read_only or self.root.read_only:
             self.disp(disp_true if self.value else disp_false)
         else:
-            self.disp(A.color(C.A_HEADER, u"0: ",
+            self.disp(A.color(C.A_HEADER, "0: ",
                               disp_false, A.RESET,
-                              u" *" if not self.value else u""))
-            self.disp(A.color(C.A_HEADER, u"1: ",
+                              " *" if not self.value else ""))
+            self.disp(A.color(C.A_HEADER, "1: ",
                               disp_true, A.RESET,
-                              u" *" if self.value else u""))
+                              " *" if self.value else ""))
             choice = None
             while choice not in ("0", "1"):
-                elems = [C.A_HEADER, _(u"your choice (0,1): ")]
+                elems = [C.A_HEADER, _("your choice (0,1): ")]
                 self.verboseName(elems)
-                choice = raw_input(A.color(*elems))
+                choice = input(A.color(*elems))
             self.value = bool(int(choice))
             self.disp("")
 
@@ -350,7 +350,7 @@
 
 
 class Container(Base):
-    category = u"container"
+    category = "container"
 
     def __init__(self, xmlui_parent):
         super(Container, self).__init__(xmlui_parent)
@@ -371,22 +371,22 @@
 
 
 class VerticalContainer(xmlui_base.VerticalContainer, Container):
-    type = u"vertical"
+    type = "vertical"
 
 
 class PairsContainer(xmlui_base.PairsContainer, Container):
-    type = u"pairs"
+    type = "pairs"
 
 
 class LabelContainer(xmlui_base.PairsContainer, Container):
-    type = u"label"
+    type = "label"
 
     def show(self):
         for child in self.children:
             no_lf = False
             # we check linked widget type
             # to see if we want the label on the same line or not
-            if child.type == u"label":
+            if child.type == "label":
                 for_name = child.for_name
                 if for_name:
                     for_widget = self.root.widgets[for_name]
@@ -535,7 +535,7 @@
     def _launchActionCb(self, data):
         XMLUIPanel._actions -= 1
         assert XMLUIPanel._actions >= 0
-        if u"xmlui" in data:
+        if "xmlui" in data:
             xmlui_raw = data["xmlui"]
             xmlui = create(self.host, xmlui_raw)
             xmlui.show()
@@ -557,7 +557,7 @@
             callback=self._launchActionCb,
             errback=partial(
                 self.command.errback,
-                msg=_(u"can't launch XMLUI action: {}"),
+                msg=_("can't launch XMLUI action: {}"),
                 exit_code=C.EXIT_BRIDGE_ERRBACK,
             ),
         )