Mercurial > libervia-backend
comparison sat_frontends/primitivus/contact_list.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 | d58dccd9e4b4 |
children | 9d0df638c8b4 |
comparison
equal
deleted
inserted
replaced
3027:ff5bcb12ae60 | 3028:ab2696e34d29 |
---|---|
45 self.contact_list = self.host.contact_lists[self.profile] | 45 self.contact_list = self.host.contact_lists[self.profile] |
46 | 46 |
47 # we now build the widget | 47 # we now build the widget |
48 self.status_bar = StatusBar(host) | 48 self.status_bar = StatusBar(host) |
49 self.frame = sat_widgets.FocusFrame(self._buildList(), None, self.status_bar) | 49 self.frame = sat_widgets.FocusFrame(self._buildList(), None, self.status_bar) |
50 PrimitivusWidget.__init__(self, self.frame, _(u"Contacts")) | 50 PrimitivusWidget.__init__(self, self.frame, _("Contacts")) |
51 if on_click: | 51 if on_click: |
52 urwid.connect_signal(self, "click", on_click, user_data) | 52 urwid.connect_signal(self, "click", on_click, user_data) |
53 if on_change: | 53 if on_change: |
54 urwid.connect_signal(self, "change", on_change, user_data) | 54 urwid.connect_signal(self, "change", on_change, user_data) |
55 self.host.addListener("notification", self.onNotification, [self.profile]) | 55 self.host.addListener("notification", self.onNotification, [self.profile]) |
132 return | 132 return |
133 except AttributeError: | 133 except AttributeError: |
134 pass | 134 pass |
135 idx += 1 | 135 idx += 1 |
136 | 136 |
137 log.debug(u"Not element found for {} in setFocus".format(text)) | 137 log.debug("Not element found for {} in setFocus".format(text)) |
138 | 138 |
139 # events | 139 # events |
140 | 140 |
141 def _groupClicked(self, group_wid): | 141 def _groupClicked(self, group_wid): |
142 group = group_wid.getValue() | 142 group = group_wid.getValue() |
157 self._emit("click", entity) | 157 self._emit("click", entity) |
158 | 158 |
159 def onNotification(self, entity, notif, profile): | 159 def onNotification(self, entity, notif, profile): |
160 notifs = list(self.host.getNotifs(C.ENTITY_ALL, profile=self.profile)) | 160 notifs = list(self.host.getNotifs(C.ENTITY_ALL, profile=self.profile)) |
161 if notifs: | 161 if notifs: |
162 self.title_dynamic = u"({})".format(len(notifs)) | 162 self.title_dynamic = "({})".format(len(notifs)) |
163 else: | 163 else: |
164 self.title_dynamic = None | 164 self.title_dynamic = None |
165 self.host.redraw() # FIXME: should not be necessary | 165 self.host.redraw() # FIXME: should not be necessary |
166 | 166 |
167 # Methods to build the widget | 167 # Methods to build the widget |
215 if with_show_attr: | 215 if with_show_attr: |
216 show = self.contact_list.getCache(entity, C.PRESENCE_SHOW) | 216 show = self.contact_list.getCache(entity, C.PRESENCE_SHOW) |
217 if show is None: | 217 if show is None: |
218 show = C.PRESENCE_UNAVAILABLE | 218 show = C.PRESENCE_UNAVAILABLE |
219 show_icon, entity_attr = C.PRESENCE.get(show, ("", "default")) | 219 show_icon, entity_attr = C.PRESENCE.get(show, ("", "default")) |
220 markup.insert(0, u"{} ".format(show_icon)) | 220 markup.insert(0, "{} ".format(show_icon)) |
221 else: | 221 else: |
222 entity_attr = "default" | 222 entity_attr = "default" |
223 | 223 |
224 notifs = list( | 224 notifs = list( |
225 self.host.getNotifs(entity, exact_jid=special, profile=self.profile) | 225 self.host.getNotifs(entity, exact_jid=special, profile=self.profile) |
227 mentions = list( | 227 mentions = list( |
228 self.host.getNotifs(entity.bare, C.NOTIFY_MENTION, profile=self.profile) | 228 self.host.getNotifs(entity.bare, C.NOTIFY_MENTION, profile=self.profile) |
229 ) | 229 ) |
230 if notifs or mentions: | 230 if notifs or mentions: |
231 attr = 'cl_mention' if mentions else 'cl_notifs' | 231 attr = 'cl_mention' if mentions else 'cl_notifs' |
232 header = [(attr, u"({})".format(len(notifs) + len(mentions))), u" "] | 232 header = [(attr, "({})".format(len(notifs) + len(mentions))), " "] |
233 else: | 233 else: |
234 header = u"" | 234 header = "" |
235 | 235 |
236 markup.append((entity_attr, entity_txt)) | 236 markup.append((entity_attr, entity_txt)) |
237 if markup_prepend: | 237 if markup_prepend: |
238 markup.insert(0, markup_prepend) | 238 markup.insert(0, markup_prepend) |
239 if markup_append: | 239 if markup_append: |
331 self._buildSpecials(content) | 331 self._buildSpecials(content) |
332 if self.contact_list._specials: | 332 if self.contact_list._specials: |
333 content.append(urwid.Divider("=")) | 333 content.append(urwid.Divider("=")) |
334 | 334 |
335 groups = list(self.contact_list._groups) | 335 groups = list(self.contact_list._groups) |
336 groups.sort(key=lambda x: x.lower() if x else x) | 336 groups.sort(key=lambda x: x.lower() if x else '') |
337 for group in groups: | 337 for group in groups: |
338 data = self.contact_list.getGroupData(group) | 338 data = self.contact_list.getGroupData(group) |
339 folded = data.get(C.GROUP_DATA_FOLDED, False) | 339 folded = data.get(C.GROUP_DATA_FOLDED, False) |
340 jids = list(data["jids"]) | 340 jids = list(data["jids"]) |
341 if group is not None and ( | 341 if group is not None and ( |