diff sat_frontends/tools/xmlui.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 5ecce65631a2
children fee60f17ebac
line wrap: on
line diff
--- a/sat_frontends/tools/xmlui.py	Wed Jul 31 11:31:22 2019 +0200
+++ b/sat_frontends/tools/xmlui.py	Tue Aug 13 19:08:41 2019 +0200
@@ -51,7 +51,7 @@
     for child in node.childNodes:
         if child.nodeType == child.TEXT_NODE:
             data.append(child.wholeText)
-    return u"".join(data)
+    return "".join(data)
 
 
 class Widget(object):
@@ -295,7 +295,7 @@
         top = parsed_dom.documentElement
         self.session_id = top.getAttribute("session_id") or None
         self.submit_id = top.getAttribute("submit") or None
-        self.xmlui_title = title or top.getAttribute("title") or u""
+        self.xmlui_title = title or top.getAttribute("title") or ""
         self.hidden = {}
         if flags is None:
             flags = []
@@ -342,8 +342,8 @@
             raise ValueError("Can't submit is self.submit_id is not set")
         if "session_id" in data:
             raise ValueError(
-                u"session_id must no be used in data, it is automaticaly filled with "
-                u"self.session_id if present"
+                "session_id must no be used in data, it is automaticaly filled with "
+                "self.session_id if present"
             )
         if self.session_id is not None:
             data["session_id"] = self.session_id
@@ -376,7 +376,7 @@
         return self.__getitem__(name)
 
     def keys(self):
-        return self.widgets.keys()
+        return list(self.widgets.keys())
 
 
 class XMLUIPanel(XMLUIBase):
@@ -420,7 +420,7 @@
     @staticmethod
     def escape(name):
         """Return escaped name for forms"""
-        return u"%s%s" % (C.SAT_FORM_PREFIX, name)
+        return "%s%s" % (C.SAT_FORM_PREFIX, name)
 
     @property
     def main_cont(self):
@@ -556,7 +556,7 @@
                     value = getText(value_elt)
                 else:
                     value = (
-                        node.getAttribute("value") if node.hasAttribute("value") else u""
+                        node.getAttribute("value") if node.hasAttribute("value") else ""
                     )
                 if type_ == "empty":
                     ctrl = self.widget_factory.createEmptyWidget(_xmlui_parent)
@@ -569,8 +569,8 @@
                     data[CURRENT_LABEL] = ctrl
                 elif type_ == "hidden":
                     if name in self.hidden:
-                        raise exceptions.ConflictError(u"Conflict on hidden value with "
-                                                       u"name {name}".format(name=name))
+                        raise exceptions.ConflictError("Conflict on hidden value with "
+                                                       "name {name}".format(name=name))
                     self.hidden[name] = value
                     continue
                 elif type_ == "jid":
@@ -617,7 +617,7 @@
                     self.ctrl_list[name] = {"type": type_, "control": ctrl}
                 elif type_ == "list":
                     style = [] if node.getAttribute("multi") == "yes" else ["single"]
-                    for attr in (u"noselect", u"extensible", u"reducible", u"inline"):
+                    for attr in ("noselect", "extensible", "reducible", "inline"):
                         if node.getAttribute(attr) == "yes":
                             style.append(attr)
                     _options = [
@@ -778,7 +778,7 @@
             escaped = self.escape(field)
             ctrl = self.ctrl_list[field]
             if isinstance(ctrl["control"], ListWidget):
-                data[escaped] = u"\t".join(ctrl["control"]._xmluiGetSelectedValues())
+                data[escaped] = "\t".join(ctrl["control"]._xmluiGetSelectedValues())
             else:
                 data[escaped] = ctrl["control"]._xmluiGetValue()
         self._xmluiLaunchAction(callback_id, data)
@@ -810,7 +810,7 @@
                     target._xmluiAddValues(values, select=True)
             else:
                 if isinstance(source, ListWidget):
-                    value = u", ".join(source._xmluiGetSelectedValues())
+                    value = ", ".join(source._xmluiGetSelectedValues())
                 else:
                     value = source._xmluiGetValue()
                     if action == "move":
@@ -877,12 +877,12 @@
             ctrl = self.ctrl_list[ctrl_name]
             if isinstance(ctrl["control"], ListWidget):
                 selected_values.append(
-                    (escaped, u"\t".join(ctrl["control"]._xmluiGetSelectedValues()))
+                    (escaped, "\t".join(ctrl["control"]._xmluiGetSelectedValues()))
                 )
             else:
                 selected_values.append((escaped, ctrl["control"]._xmluiGetValue()))
         data = dict(selected_values)
-        for key, value in self.hidden.iteritems():
+        for key, value in self.hidden.items():
             data[self.escape(key)] = value
 
         if self.submit_id is not None:
@@ -913,7 +913,7 @@
         assert self.type == "param"
         for ctrl in self.param_changed:
             if isinstance(ctrl, ListWidget):
-                value = u"\t".join(ctrl._xmluiGetSelectedValues())
+                value = "\t".join(ctrl._xmluiGetSelectedValues())
             else:
                 value = ctrl._xmluiGetValue()
             param_name = ctrl._xmlui_name.split(C.SAT_PARAM_SEPARATOR)[1]
@@ -1012,10 +1012,10 @@
     # TODO: remove this method, as there are seme use cases where different XMLUI
     #       classes can be used in the same frontend, so a global value is not good
     assert type_ in (CLASS_PANEL, CLASS_DIALOG)
-    log.warning(u"registerClass for XMLUI is deprecated, please use partial with "
-                u"xmlui.create and class_map instead")
+    log.warning("registerClass for XMLUI is deprecated, please use partial with "
+                "xmlui.create and class_map instead")
     if type_ in _class_map:
-        log.debug(_(u"XMLUI class already registered for {type_}, ignoring").format(
+        log.debug(_("XMLUI class already registered for {type_}, ignoring").format(
             type_=type_))
         return