comparison sat_frontends/quick_frontend/quick_contact_management.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
39 """Clear all the contact list""" 39 """Clear all the contact list"""
40 self.__contactlist.clear() 40 self.__contactlist.clear()
41 41
42 def add(self, entity): 42 def add(self, entity):
43 """Add contact to the list, update resources""" 43 """Add contact to the list, update resources"""
44 if not self.__contactlist.has_key(entity.bare): 44 if entity.bare not in self.__contactlist:
45 self.__contactlist[entity.bare] = {"resources": []} 45 self.__contactlist[entity.bare] = {"resources": []}
46 if not entity.resource: 46 if not entity.resource:
47 return 47 return
48 if entity.resource in self.__contactlist[entity.bare]["resources"]: 48 if entity.resource in self.__contactlist[entity.bare]["resources"]:
49 self.__contactlist[entity.bare]["resources"].remove(entity.resource) 49 self.__contactlist[entity.bare]["resources"].remove(entity.resource)
51 51
52 def getContFromGroup(self, group): 52 def getContFromGroup(self, group):
53 """Return all contacts which are in given group""" 53 """Return all contacts which are in given group"""
54 result = [] 54 result = []
55 for contact in self.__contactlist: 55 for contact in self.__contactlist:
56 if self.__contactlist[contact].has_key("groups"): 56 if "groups" in self.__contactlist[contact]:
57 if group in self.__contactlist[contact]["groups"]: 57 if group in self.__contactlist[contact]["groups"]:
58 result.append(JID(contact)) 58 result.append(JID(contact))
59 return result 59 return result
60 60
61 def getAttr(self, entity, name): 61 def getAttr(self, entity, name):
62 """Return a specific attribute of contact, or all attributes 62 """Return a specific attribute of contact, or all attributes
63 @param entity: jid of the contact 63 @param entity: jid of the contact
64 @param name: name of the attribute 64 @param name: name of the attribute
65 @return: asked attribute""" 65 @return: asked attribute"""
66 if self.__contactlist.has_key(entity.bare): 66 if entity.bare in self.__contactlist:
67 if name == "status": # FIXME: for the moment, we only use the first status 67 if name == "status": # FIXME: for the moment, we only use the first status
68 if self.__contactlist[entity.bare]["statuses"]: 68 if self.__contactlist[entity.bare]["statuses"]:
69 return self.__contactlist[entity.bare]["statuses"].values()[0] 69 return list(self.__contactlist[entity.bare]["statuses"].values())[0]
70 if self.__contactlist[entity.bare].has_key(name): 70 if name in self.__contactlist[entity.bare]:
71 return self.__contactlist[entity.bare][name] 71 return self.__contactlist[entity.bare][name]
72 else: 72 else:
73 log.debug(_("Trying to get attribute for an unknown contact")) 73 log.debug(_("Trying to get attribute for an unknown contact"))
74 return None 74 return None
75 75
76 def isConnected(self, entity): 76 def isConnected(self, entity):
77 """Tell if the contact is online""" 77 """Tell if the contact is online"""
78 return self.__contactlist.has_key(entity.bare) 78 return entity.bare in self.__contactlist
79 79
80 def remove(self, entity): 80 def remove(self, entity):
81 """remove resource. If no more resource is online or is no resource is specified, contact is deleted""" 81 """remove resource. If no more resource is online or is no resource is specified, contact is deleted"""
82 try: 82 try:
83 if entity.resource: 83 if entity.resource:
93 """Update attribute of contact 93 """Update attribute of contact
94 @param entity: jid of the contact 94 @param entity: jid of the contact
95 @param key: name of the attribute 95 @param key: name of the attribute
96 @param value: value of the attribute 96 @param value: value of the attribute
97 """ 97 """
98 if self.__contactlist.has_key(entity.bare): 98 if entity.bare in self.__contactlist:
99 self.__contactlist[entity.bare][key] = value 99 self.__contactlist[entity.bare][key] = value
100 else: 100 else:
101 log.debug(_("Trying to update an unknown contact: %s") % entity.bare) 101 log.debug(_("Trying to update an unknown contact: %s") % entity.bare)
102 102
103 def get_full(self, entity): 103 def get_full(self, entity):