1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 from common.zeroconf import zeroconf
22
27
31
33
34 if self._data is None:
35 self._data = {}
36 self.update_roster()
37 return self
38
40 """
41 Update the roster with new data and return dict with jid -> new status
42 pairs to do notifications and stuff
43 """
44 diffs = {}
45 old_data = self._data.copy()
46 self.update_roster()
47 for key in old_data.keys():
48 if key in self._data:
49 if old_data[key] != self._data[key]:
50 diffs[key] = self._data[key]['status']
51
52 return diffs
53
54 - def setItem(self, jid, name='', groups=''):
55
56 contact = self.zeroconf.get_contact(jid)
57 if not contact:
58 return
59
60 host, address, port = contact[4:7]
61 txt = contact[8]
62
63 self._data[jid]={}
64 self._data[jid]['ask'] = 'none'
65 self._data[jid]['subscription'] = 'both'
66 self._data[jid]['groups'] = []
67 self._data[jid]['resources'] = {}
68 self._data[jid]['address'] = address
69 self._data[jid]['host'] = host
70 self._data[jid]['port'] = port
71 txt_dict = self.zeroconf.txt_array_to_dict(txt)
72 status = txt_dict.get('status', '')
73 if not status:
74 status = 'avail'
75 nm = txt_dict.get('1st', '')
76 if 'last' in txt_dict:
77 if nm != '':
78 nm += ' '
79 nm += txt_dict['last']
80 if nm:
81 self._data[jid]['name'] = nm
82 else:
83 self._data[jid]['name'] = jid
84 if status == 'avail':
85 status = 'online'
86 self._data[jid]['txt_dict'] = txt_dict
87 if 'msg' not in self._data[jid]['txt_dict']:
88 self._data[jid]['txt_dict']['msg'] = ''
89 self._data[jid]['status'] = status
90 self._data[jid]['show'] = status
91
95
97
98 if jid in self._data:
99 del self._data[jid]
100
102
103 if jid in self._data:
104 return self._data[jid]
105
107
108 return self._data[jid]
109
111
112
113 return self._data.keys()
114
116
117 return self._data.keys()
118
120
121 return self._data
122
126
128 return self._data[jid]['groups']
129
131 if jid in self._data:
132 return self._data[jid]['name']
133
135 if jid in self._data:
136 return self._data[jid]['status']
137
139 if jid in self._data:
140 return self._data[jid]['txt_dict']['msg']
141
145
148
152
155
158
161
164