comparison sat/tools/common/template_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 442ab697f831
children 9d0df638c8b4
comparison
equal deleted inserted replaced
3027:ff5bcb12ae60 3028:ab2696e34d29
1 #!/usr/bin/env python2 1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
4 # SAT: a jabber client 4 # SAT: a jabber client
5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) 5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org)
6 6
37 37
38 ## Widgets ## 38 ## Widgets ##
39 39
40 40
41 class Widget(object): 41 class Widget(object):
42 category = u"widget" 42 category = "widget"
43 type = None 43 type = None
44 enabled = True 44 enabled = True
45 read_only = True 45 read_only = True
46 46
47 def __init__(self, xmlui_parent): 47 def __init__(self, xmlui_parent):
101 if no_select or value in self.selected: 101 if no_select or value in self.selected:
102 yield value, label 102 yield value, label
103 103
104 @property 104 @property
105 def inline(self): 105 def inline(self):
106 return u"inline" in self.style 106 return "inline" in self.style
107 107
108 @property 108 @property
109 def no_select(self): 109 def no_select(self):
110 return u"noselect" in self.style 110 return "noselect" in self.style
111 111
112 112
113 class EmptyWidget(xmlui.EmptyWidget, Widget): 113 class EmptyWidget(xmlui.EmptyWidget, Widget):
114 def __init__(self, _xmlui_parent): 114 def __init__(self, _xmlui_parent):
115 Widget.__init__(self) 115 Widget.__init__(self)
116 116
117 117
118 class TextWidget(xmlui.TextWidget, ValueWidget): 118 class TextWidget(xmlui.TextWidget, ValueWidget):
119 type = u"text" 119 type = "text"
120 120
121 121
122 class LabelWidget(xmlui.LabelWidget, ValueWidget): 122 class LabelWidget(xmlui.LabelWidget, ValueWidget):
123 type = u"label" 123 type = "label"
124 124
125 @property 125 @property
126 def for_name(self): 126 def for_name(self):
127 try: 127 try:
128 return self._xmlui_for_name 128 return self._xmlui_for_name
129 except AttributeError: 129 except AttributeError:
130 return None 130 return None
131 131
132 132
133 class StringWidget(xmlui.StringWidget, InputWidget): 133 class StringWidget(xmlui.StringWidget, InputWidget):
134 type = u"string" 134 type = "string"
135 135
136 136
137 class JidInputWidget(xmlui.JidInputWidget, StringWidget): 137 class JidInputWidget(xmlui.JidInputWidget, StringWidget):
138 type = u"jid" 138 type = "jid"
139 139
140 140
141 class TextBoxWidget(xmlui.TextWidget, InputWidget): 141 class TextBoxWidget(xmlui.TextWidget, InputWidget):
142 type = u"textbox" 142 type = "textbox"
143 143
144 144
145 class XHTMLBoxWidget(xmlui.XHTMLBoxWidget, InputWidget): 145 class XHTMLBoxWidget(xmlui.XHTMLBoxWidget, InputWidget):
146 type = u"xhtmlbox" 146 type = "xhtmlbox"
147 147
148 def __init__(self, xmlui_parent, value, read_only=False): 148 def __init__(self, xmlui_parent, value, read_only=False):
149 # XXX: XHTMLBoxWidget value must be cleaned (harmful XHTML must be removed) 149 # XXX: XHTMLBoxWidget value must be cleaned (harmful XHTML must be removed)
150 # This is normally done in the backend, the frontends should not need to 150 # This is normally done in the backend, the frontends should not need to
151 # worry about it. 151 # worry about it.
152 super(XHTMLBoxWidget, self).__init__( 152 super(XHTMLBoxWidget, self).__init__(
153 xmlui_parent=xmlui_parent, value=safe(value), read_only=read_only) 153 xmlui_parent=xmlui_parent, value=safe(value), read_only=read_only)
154 154
155 155
156 class ListWidget(xmlui.ListWidget, OptionsWidget): 156 class ListWidget(xmlui.ListWidget, OptionsWidget):
157 type = u"list" 157 type = "list"
158 158
159 159
160 ## Containers ## 160 ## Containers ##
161 161
162 162
163 class Container(object): 163 class Container(object):
164 category = u"container" 164 category = "container"
165 type = None 165 type = None
166 166
167 def __init__(self, xmlui_parent): 167 def __init__(self, xmlui_parent):
168 self.xmlui_parent = xmlui_parent 168 self.xmlui_parent = xmlui_parent
169 self.children = [] 169 self.children = []
177 def _xmluiRemove(self, widget): 177 def _xmluiRemove(self, widget):
178 self.children.remove(widget) 178 self.children.remove(widget)
179 179
180 180
181 class VerticalContainer(xmlui.VerticalContainer, Container): 181 class VerticalContainer(xmlui.VerticalContainer, Container):
182 type = u"vertical" 182 type = "vertical"
183 183
184 184
185 class PairsContainer(xmlui.PairsContainer, Container): 185 class PairsContainer(xmlui.PairsContainer, Container):
186 type = u"pairs" 186 type = "pairs"
187 187
188 188
189 class LabelContainer(xmlui.PairsContainer, Container): 189 class LabelContainer(xmlui.PairsContainer, Container):
190 type = u"label" 190 type = "label"
191 191
192 192
193 ## Factory ## 193 ## Factory ##
194 194
195 195