comparison sat/test/helpers_plugins.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 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 # Copyright (C) 2013-2016 Adrien Cossa (souliane@mailoo.org) 6 # Copyright (C) 2013-2016 Adrien Cossa (souliane@mailoo.org)
27 from wokkel.disco import DiscoItem, DiscoItems 27 from wokkel.disco import DiscoItem, DiscoItems
28 28
29 # temporary until the changes are integrated to Wokkel 29 # temporary until the changes are integrated to Wokkel
30 from sat_tmp.wokkel.rsm import RSMResponse 30 from sat_tmp.wokkel.rsm import RSMResponse
31 31
32 from constants import Const as C 32 from .constants import Const as C
33 from sat.plugins import plugin_xep_0045 33 from sat.plugins import plugin_xep_0045
34 from collections import OrderedDict 34 from collections import OrderedDict
35 35
36 36
37 class FakeMUCClient(object): 37 class FakeMUCClient(object):
50 """ 50 """
51 profile = self.host.memory.getProfileName(profile_key) 51 profile = self.host.memory.getProfileName(profile_key)
52 roster = {} 52 roster = {}
53 53
54 # ask the other profiles to fill our roster 54 # ask the other profiles to fill our roster
55 for i in xrange(0, len(C.PROFILE)): 55 for i in range(0, len(C.PROFILE)):
56 other_profile = C.PROFILE[i] 56 other_profile = C.PROFILE[i]
57 if other_profile == profile: 57 if other_profile == profile:
58 continue 58 continue
59 try: 59 try:
60 other_room = self.plugin_parent.clients[other_profile].joined_rooms[ 60 other_room = self.plugin_parent.clients[other_profile].joined_rooms[
67 roster.setdefault(other_nick, other_room.roster[other_nick]) 67 roster.setdefault(other_nick, other_room.roster[other_nick])
68 except (AttributeError, KeyError): 68 except (AttributeError, KeyError):
69 pass 69 pass
70 70
71 # rename our nick if it already exists 71 # rename our nick if it already exists
72 while nick in roster.keys(): 72 while nick in list(roster.keys()):
73 if C.PROFILE_DICT[profile].userhost() == roster[nick].entity.userhost(): 73 if C.PROFILE_DICT[profile].userhost() == roster[nick].entity.userhost():
74 break # same user with different resource --> same nickname 74 break # same user with different resource --> same nickname
75 nick = nick + "_" 75 nick = nick + "_"
76 76
77 room = Room(room_jid, nick) 77 room = Room(room_jid, nick)
78 room.roster = roster 78 room.roster = roster
79 self.joined_rooms[room_jid] = room 79 self.joined_rooms[room_jid] = room
80 80
81 # fill the other rosters with the new entry 81 # fill the other rosters with the new entry
82 for i in xrange(0, len(C.PROFILE)): 82 for i in range(0, len(C.PROFILE)):
83 other_profile = C.PROFILE[i] 83 other_profile = C.PROFILE[i]
84 if other_profile == profile: 84 if other_profile == profile:
85 continue 85 continue
86 try: 86 try:
87 other_room = self.plugin_parent.clients[other_profile].joined_rooms[ 87 other_room = self.plugin_parent.clients[other_profile].joined_rooms[
102 @return: a dummy deferred 102 @return: a dummy deferred
103 """ 103 """
104 profile = self.host.memory.getProfileName(profile_key) 104 profile = self.host.memory.getProfileName(profile_key)
105 room = self.joined_rooms[roomJID] 105 room = self.joined_rooms[roomJID]
106 # remove ourself from the other rosters 106 # remove ourself from the other rosters
107 for i in xrange(0, len(C.PROFILE)): 107 for i in range(0, len(C.PROFILE)):
108 other_profile = C.PROFILE[i] 108 other_profile = C.PROFILE[i]
109 if other_profile == profile: 109 if other_profile == profile:
110 continue 110 continue
111 try: 111 try:
112 other_room = self.plugin_parent.clients[other_profile].joined_rooms[ 112 other_room = self.plugin_parent.clients[other_profile].joined_rooms[
250 return True 250 return True
251 index += 1 251 index += 1
252 return False 252 return False
253 253
254 for item in items: 254 for item in items:
255 item_obj = parseXml(item) if isinstance(item, unicode) else item 255 item_obj = parseXml(item) if isinstance(item, str) else item
256 if not replace(item_obj): 256 if not replace(item_obj):
257 node.append(item_obj) 257 node.append(item_obj)
258 return defer.succeed(None) 258 return defer.succeed(None)
259 259
260 def items( 260 def items(
294 def subscriptions(self, service, nodeIdentifier, sender=None): 294 def subscriptions(self, service, nodeIdentifier, sender=None):
295 return defer.succeed([]) 295 return defer.succeed([])
296 296
297 def service_getDiscoItems(self, service, nodeIdentifier, profile_key=C.PROF_KEY_NONE): 297 def service_getDiscoItems(self, service, nodeIdentifier, profile_key=C.PROF_KEY_NONE):
298 items = DiscoItems() 298 items = DiscoItems()
299 for item in self.__items.keys(): 299 for item in list(self.__items.keys()):
300 items.append(DiscoItem(service, item)) 300 items.append(DiscoItem(service, item))
301 return defer.succeed(items) 301 return defer.succeed(items)