diff --git a/src/advanced.py b/src/advanced.py index 32059c66d..203653f4b 100644 --- a/src/advanced.py +++ b/src/advanced.py @@ -78,7 +78,7 @@ class AdvancedConfigurationWindow: self.plugin.windows['advanced_config'] = self def cb_value_column_data(self, col, cell, model, iter): - opttype = model[iter][2] + opttype = model[iter][2].decode('utf-8') if opttype == 'boolean': cell.set_property('editable', 0) else: @@ -87,14 +87,14 @@ class AdvancedConfigurationWindow: def on_advanced_treeview_row_activated(self, treeview, path, column): modelpath = self.modelfilter.convert_path_to_child_path(path) modelrow = self.model[modelpath] - option = modelrow[0] + option = modelrow[0].decode('utf-8') if modelrow[2] == 'boolean': newval = {'False': 'True', 'True': 'False'}[modelrow[1]] if len(modelpath) > 1: optnamerow = self.model[modelpath[0]] - optname = optnamerow[0] + optname = optnamerow[0].decode('utf-8') keyrow = self.model[modelpath[:2]] - key = keyrow[0] + key = keyrow[0].decode('utf-8') gajim.config.set_per(optname, key, option, newval) else: gajim.config.set(option, newval) @@ -105,12 +105,13 @@ class AdvancedConfigurationWindow: # convert modelfilter path to model path modelpath = self.modelfilter.convert_path_to_child_path(path) modelrow = self.model[modelpath] - option = modelrow[0] + option = modelrow[0].decode('utf-8') + text = text.decode('utf-8') if len(modelpath) > 1: optnamerow = self.model[modelpath[0]] - optname = optnamerow[0] + optname = optnamerow[0].decode('utf-8') keyrow = self.model[modelpath[:2]] - key = keyrow[0] + key = keyrow[0].decode('utf-8') gajim.config.set_per(optname, key, option, text) else: gajim.config.set(option, text) @@ -131,7 +132,7 @@ class AdvancedConfigurationWindow: else: iter = model.iter_children(parent_iter) while iter: - if model[iter][0] == name: + if model[iter][0].decode('utf-8') == name: break iter = model.iter_next(iter) return iter @@ -153,19 +154,19 @@ class AdvancedConfigurationWindow: model.append(iter, [name, val[OPT_VAL], type]) def visible_func(self, model, iter): - str = self.entry.get_text() + str = self.entry.get_text().decode('utf-8') if str is None or str == '': return True # show all - name = model[iter][0] + name = model[iter][0].decode('utf-8') # If a child of the iter matches, we return True if model.iter_has_child(iter): iterC = model.iter_children(iter) while iterC: - nameC = model[iterC][0] + nameC = model[iterC][0].decode('utf-8') if model.iter_has_child(iterC): iterCC = model.iter_children(iterC) while iterCC: - nameCC = model[iterCC][0] + nameCC = model[iterCC][0].decode('utf-8') if nameCC.find(str) != -1: return True iterCC = model.iter_next(iterCC) @@ -177,5 +178,5 @@ class AdvancedConfigurationWindow: return False def on_advanced_entry_changed(self, widget): - text = widget.get_text() + text = widget.get_text().decode('utf-8') self.modelfilter.refilter() diff --git a/src/chat.py b/src/chat.py index a2b0b221e..8dc55afc1 100644 --- a/src/chat.py +++ b/src/chat.py @@ -114,7 +114,7 @@ class Chat: unread += self.nb_unread[jid] start = "" if unread > 1: - start = '[' + str(unread) + '] ' + start = '[' + unicode(unread) + '] ' elif unread == 1: start = '* ' chat = self.names[jid] @@ -144,7 +144,7 @@ class Chat: """redraw the label of the tab""" start = '' if self.nb_unread[jid] > 1: - start = '[' + str(self.nb_unread[jid]) + '] ' + start = '[' + unicode(self.nb_unread[jid]) + '] ' elif self.nb_unread[jid] == 1: start = '* ' @@ -490,7 +490,7 @@ class Chat: gtkspell.Spell(message_textview) except gobject.GError, msg: #FIXME: add a ui for this use spell.set_language() - dialogs.ErrorDialog(str(msg), _('If that is not your language for which you want to highlight misspelled words, then please set your $LANG as appropriate. Eg. for French do export LANG=fr_FR or export LANG=fr_FR.UTF-8 in ~/.bash_profile or to make it global in /etc/profile.\n\nHighlighting misspelled words feature will not be used')).get_response() + dialogs.ErrorDialog(unicode(msg), _('If that is not your language for which you want to highlight misspelled words, then please set your $LANG as appropriate. Eg. for French do export LANG=fr_FR or export LANG=fr_FR.UTF-8 in ~/.bash_profile or to make it global in /etc/profile.\n\nHighlighting misspelled words feature will not be used')).get_response() gajim.config.set('use_speller', False) conversation_textview = self.xmls[jid].get_widget( @@ -831,7 +831,7 @@ class Chat: if return_val: # if sth was selected when we right-clicked # get the selected text start_sel, finish_sel = return_val[0], return_val[1] - self.selected_phrase = buffer.get_text(start_sel, finish_sel) + self.selected_phrase = buffer.get_text(start_sel, finish_sel).decode('utf-8') def print_time_timeout(self, jid): if not jid in self.xmls.keys(): @@ -934,7 +934,7 @@ class Chat: #we get the end of the tag while not end_iter.ends_tag(texttag): end_iter.forward_char() - word = begin_iter.get_text(end_iter) + word = begin_iter.get_text(end_iter).decode('utf-8') if event.button == 3: # right click self.make_link_menu(event, kind, word) else: @@ -1193,7 +1193,7 @@ class Chat: #whatever is already typed start_iter = conv_buf.get_start_iter() end_iter = conv_buf.get_end_iter() - self.orig_msg[jid] = conv_buf.get_text(start_iter, end_iter, 0) + self.orig_msg[jid] = conv_buf.get_text(start_iter, end_iter, 0).decode('utf-8') self.typing_new[jid] = False self.sent_history_pos[jid] = self.sent_history_pos[jid] - 1 diff --git a/src/common/connection.py b/src/common/connection.py index 9f7072bf9..133ddfd19 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -219,7 +219,8 @@ class Connection: self.dispatch('MYVCARD', vcard) #we re-send our presence with sha sshow = STATUS_LIST[self.connected] - prio = str(gajim.config.get_per('accounts', self.name, 'priority')) + prio = unicode(gajim.config.get_per('accounts', self.name, + 'priority')) p = common.xmpp.Presence(typ = None, priority = prio, show = sshow, status = self.status) p = self.add_sha(p) @@ -264,24 +265,25 @@ class Connection: msgtxt = decmsg encrypted = True if mtype == 'error': - self.dispatch('MSGERROR', (str(msg.getFrom()), + self.dispatch('MSGERROR', (unicode(msg.getFrom()), msg.getErrorCode(), msg.getError(), msgtxt, tim)) elif mtype == 'groupchat': if subject: - self.dispatch('GC_SUBJECT', (str(msg.getFrom()), subject)) + self.dispatch('GC_SUBJECT', (unicode(msg.getFrom()), subject)) else: if not msg.getTag('body'): #no return - self.dispatch('GC_MSG', (str(msg.getFrom()), msgtxt, tim)) - gajim.logger.write('gc', msgtxt, str(msg.getFrom()), tim = tim) + self.dispatch('GC_MSG', (unicode(msg.getFrom()), msgtxt, tim)) + gajim.logger.write('gc', msgtxt, unicode(msg.getFrom()), + tim = tim) elif mtype == 'normal': # it's single message log_msgtxt = msgtxt if subject: log_msgtxt = _('Subject: %s\n%s') % (subject, msgtxt) - gajim.logger.write('incoming', log_msgtxt, str(msg.getFrom()), + gajim.logger.write('incoming', log_msgtxt, unicode(msg.getFrom()), tim = tim) - self.dispatch('MSG', (str(msg.getFrom()), msgtxt, tim, encrypted, - mtype, subject, None)) + self.dispatch('MSG', (unicode(msg.getFrom()), msgtxt, tim, + encrypted, mtype, subject, None)) else: # it's type 'chat' if not msg.getTag('body') and chatstate is None: #no return @@ -289,15 +291,15 @@ class Connection: if subject: log_msgtxt = _('Subject: %s\n%s') % (subject, msgtxt) if msg.getTag('body'): - gajim.logger.write('incoming', log_msgtxt, str(msg.getFrom()), - tim = tim) - self.dispatch('MSG', (str(msg.getFrom()), msgtxt, tim, encrypted, - mtype, subject, chatstate)) + gajim.logger.write('incoming', log_msgtxt, + unicode(msg.getFrom()), tim = tim) + self.dispatch('MSG', (unicode(msg.getFrom()), msgtxt, tim, + encrypted, mtype, subject, chatstate)) # END messageCB def _presenceCB(self, con, prs): """Called when we receive a presence""" - who = str(prs.getFrom()) + who = unicode(prs.getFrom()) prio = prs.getPriority() if not prio: prio = 0 @@ -332,17 +334,16 @@ class Connection: self.to_be_sent.append(p) if who.find("@") <= 0: self.dispatch('NOTIFY', - (prs.getFrom().getStripped().encode('utf8'), 'offline', - 'offline', prs.getFrom().getResource().encode('utf8'), prio, - keyID, None, None, None, None, None, None)) + (prs.getFrom().getStripped(), 'offline', 'offline', + prs.getFrom().getResource(), prio, keyID, None, None, + None, None, None, None)) else: if not status: status = _('I would like to add you to my roster.') self.dispatch('SUBSCRIBE', (who, status)) elif ptype == 'subscribed': jid = prs.getFrom() - self.dispatch('SUBSCRIBED', (jid.getStripped().encode('utf8'), - jid.getResource().encode('utf8'))) + self.dispatch('SUBSCRIBED', (jid.getStripped(), jid.getResource())) # BE CAREFUL: no con.updateRosterItem() in a callback gajim.log.debug(_('we are now subscribed to %s') % who) elif ptype == 'unsubscribe': @@ -357,8 +358,8 @@ class Connection: self.dispatch('ERROR', (_('Unable to join room'), _('Server response:') + '\n' + errmsg)) elif errcode == '502': # Internal Timeout: - self.dispatch('NOTIFY', (prs.getFrom().getStripped().encode('utf8'), - 'error', errmsg, prs.getFrom().getResource().encode('utf8'), + self.dispatch('NOTIFY', (prs.getFrom().getStripped(), + 'error', errmsg, prs.getFrom().getResource(), prio, keyID, prs.getRole(), prs.getAffiliation(), prs.getJid(), prs.getReason(), prs.getActor(), prs.getStatusCode(), prs.getNewNick())) @@ -366,10 +367,10 @@ class Connection: self.dispatch('ERROR_ANSWER', ('', prs.getFrom().getStripped(), errmsg, errcode)) if not ptype or ptype == 'unavailable': - jid = prs.getFrom() - gajim.logger.write('status', status, str(jid).encode('utf8'), show) - account = prs.getFrom().getStripped().encode('utf8') - resource = prs.getFrom().getResource().encode('utf8') + jid = unicode(prs.getFrom()) + gajim.logger.write('status', status, jid, show) + account = prs.getFrom().getStripped() + resource = prs.getFrom().getResource() self.dispatch('NOTIFY', ( account, show, status, resource, prio, keyID, prs.getRole(), prs.getAffiliation(), prs.getJid(), prs.getReason(), @@ -393,11 +394,11 @@ class Connection: # END disconenctedCB def _bytestreamErrorCB(self, con, iq_obj): gajim.log.debug('_bytestreamErrorCB') - frm = str(iq_obj.getFrom()) - id = str(iq_obj.getAttr('id')) + frm = unicode(iq_obj.getFrom()) + id = unicode(iq_obj.getAttr('id')) query = iq_obj.getTag('query') streamhost = query.getTag('streamhost') - jid = iq_obj.getFrom().getStripped().encode('utf8') + jid = iq_obj.getFrom().getStripped() id = id[3:] if not self.files_props.has_key(id): return @@ -408,10 +409,10 @@ class Connection: def _bytestreamSetCB(self, con, iq_obj): gajim.log.debug('_bytestreamSetCB') - target = str(iq_obj.getAttr('to')) - id = str(iq_obj.getAttr('id')) + target = unicode(iq_obj.getAttr('to')) + id = unicode(iq_obj.getAttr('id')) query = iq_obj.getTag('query') - sid = str(query.getAttr('sid')) + sid = unicode(query.getAttr('sid')) file_props = gajim.socks5queue.get_file_props( self.name, sid) streamhosts=[] @@ -422,15 +423,10 @@ class Connection: 'target': target, 'id': id, 'sid': sid, - 'initiator': str(iq_obj.getFrom()) + 'initiator': unicode(iq_obj.getFrom()) } for attr in item.getAttrs(): - val = item.getAttr(attr) - if type(val) == unicode: - val = val.encode('utf-8') - if type(attr) == unicode: - attr = attr.encode('utf-8') - host_dict[attr] = val + host_dict[attr] = item.getAttr(attr) streamhosts.append(host_dict) if file_props is None: if self.files_props.has_key(sid): @@ -487,7 +483,7 @@ class Connection: typ = 'error') iq.setAttr('id', _id) err = iq.setTag('error') - err.setAttr('code', str(code)) + err.setAttr('code', unicode(code)) err.setData(msg) self.to_be_sent.append(iq) if code == 404: @@ -499,8 +495,8 @@ class Connection: def _bytestreamResultCB(self, con, iq_obj): gajim.log.debug('_bytestreamResultCB') - frm = str(iq_obj.getFrom()) - real_id = str(iq_obj.getAttr('id')) + frm = unicode(iq_obj.getFrom()) + real_id = unicode(iq_obj.getAttr('id')) query = iq_obj.getTag('query') streamhost = None try: @@ -521,9 +517,12 @@ class Connection: jid = item.getAttr('jid') conf = gajim.config conf.add_per('ft_proxies65_cache', jid) - conf.set_per('ft_proxies65_cache', jid, 'host', str(host)) - conf.set_per('ft_proxies65_cache', jid, 'port', int(port)) - conf.set_per('ft_proxies65_cache', jid, 'jid', str(jid)) + conf.set_per('ft_proxies65_cache', jid, + 'host', unicode(host)) + conf.set_per('ft_proxies65_cache', jid, + 'port', int(port)) + conf.set_per('ft_proxies65_cache', jid, + 'jid', unicode(jid)) raise common.xmpp.NodeProcessed try: streamhost = query.getTag('streamhost-used') @@ -545,7 +544,7 @@ class Connection: raise common.xmpp.NodeProcessed for host in file_props['proxyhosts']: if host['initiator'] == frm and \ - str(query.getAttr('sid')) == file_props['sid']: + unicode(query.getAttr('sid')) == file_props['sid']: gajim.socks5queue.activate_proxy(host['idx']) break raise common.xmpp.NodeProcessed @@ -581,8 +580,8 @@ class Connection: if file_props.has_key('fast'): fasts = file_props['fast'] if len(fasts) > 0: - self._connect_error(str(iq_obj.getFrom()), fasts[0]['id'], - file_props['sid'], code = 406) + self._connect_error(unicode(iq_obj.getFrom()), + fasts[0]['id'], file_props['sid'], code = 406) raise common.xmpp.NodeProcessed @@ -640,9 +639,9 @@ class Connection: def _discoGetCB(self, con, iq_obj): ''' get disco info ''' - frm = str(iq_obj.getFrom()) - to = str(iq_obj.getAttr('to')) - id = str(iq_obj.getAttr('id')) + frm = unicode(iq_obj.getFrom()) + to = unicode(iq_obj.getAttr('to')) + id = unicode(iq_obj.getAttr('id')) iq = common.xmpp.Iq(to = frm, typ = 'result', queryNS =\ common.xmpp.NS_DISCO, frm = to) iq.setAttr('id', id) @@ -673,8 +672,8 @@ class Connection: if file_props is None: # file properties for jid is none return - file_props['receiver'] = str(iq_obj.getFrom()) - jid = iq_obj.getFrom().getStripped().encode('utf8') + file_props['receiver'] = unicode(iq_obj.getFrom()) + jid = iq_obj.getFrom().getStripped() si = iq_obj.getTag('si') feature = si.setTag('feature') if feature.getNamespace() != common.xmpp.NS_FEATURE: @@ -738,12 +737,12 @@ class Connection: continue host_dict={ 'state': 0, - 'target': str(receiver), + 'target': unicode(receiver), 'id': file_props['sid'], 'sid': file_props['sid'], 'initiator': proxy, 'host': host, - 'port': str(_port), + 'port': unicode(_port), 'jid': jid } proxyhosts.append(host_dict) @@ -757,12 +756,12 @@ class Connection: sha_str, self.result_socks5_sid, file_props['sid']) if listener == None: file_props['error'] = -5 - self.dispatch('FILE_REQUEST_ERROR', (str(receiver), file_props)) - self._connect_error(str(receiver), file_props['sid'], + self.dispatch('FILE_REQUEST_ERROR', (unicode(receiver), file_props)) + self._connect_error(unicode(receiver), file_props['sid'], file_props['sid'], code = 406) return - iq = common.xmpp.Protocol(name = 'iq', to = str(receiver), + iq = common.xmpp.Protocol(name = 'iq', to = unicode(receiver), typ = 'set') file_props['request-id'] = 'id_' + file_props['sid'] iq.setID(file_props['request-id']) @@ -771,12 +770,12 @@ class Connection: query.setAttr('mode', 'tcp') query.setAttr('sid', file_props['sid']) streamhost = query.setTag('streamhost') - streamhost.setAttr('port', str(port)) + streamhost.setAttr('port', unicode(port)) streamhost.setAttr('host', ft_override_host_to_send) streamhost.setAttr('jid', sender) if fast and proxyhosts != []: - file_props['proxy_receiver'] = str(receiver) - file_props['proxy_sender'] = str(sender) + file_props['proxy_receiver'] = unicode(receiver) + file_props['proxy_sender'] = unicode(sender) file_props['proxyhosts'] = proxyhosts for proxyhost in proxyhosts: streamhost = common.xmpp.Node(tag = 'streamhost') @@ -792,7 +791,7 @@ class Connection: def _siSetCB(self, con, iq_obj): gajim.log.debug('_siSetCB') - jid = iq_obj.getFrom().getStripped().encode('utf8') + jid = iq_obj.getFrom().getStripped() si = iq_obj.getTag('si') profile = si.getAttr('profile') mime_type = si.getAttr('mime-type') @@ -802,13 +801,10 @@ class Connection: file_tag = si.getTag('file') file_props = {'type': 'r'} for attribute in file_tag.getAttrs(): - attribute = attribute.encode('utf-8') if attribute in ['name', 'size', 'hash', 'date']: val = file_tag.getAttr(attribute) if val is None: continue - if type(val) is unicode: - val = val.encode('utf-8') file_props[attribute] = val file_desc_tag = file_tag.getTag('desc') if file_desc_tag is not None: @@ -821,8 +817,8 @@ class Connection: resource = gajim.config.get_per('accounts', self.name, 'resource') file_props['receiver'] = name + '@' + hostname + '/' + resource file_props['sender'] = iq_obj.getFrom() - file_props['request-id'] = str(iq_obj.getAttr('id')) - file_props['sid'] = str(si.getAttr('id')) + file_props['request-id'] = unicode(iq_obj.getAttr('id')) + file_props['sid'] = unicode(si.getAttr('id')) gajim.socks5queue.add_file_props(self.name, file_props) self.dispatch('FILE_REQUEST', (jid, file_props)) raise common.xmpp.NodeProcessed @@ -841,15 +837,15 @@ class Connection: if file_props is None: # file properties for jid is none return - jid = iq_obj.getFrom().getStripped().encode('utf8') + jid = iq_obj.getFrom().getStripped() file_props['error'] = -3 self.dispatch('FILE_REQUEST_ERROR', (jid, file_props)) raise common.xmpp.NodeProcessed def send_file_rejection(self, file_props): ''' informs sender that we refuse to download the file ''' - iq = common.xmpp.Protocol(name = 'iq', to = str(file_props['sender']), - typ = 'error') + iq = common.xmpp.Protocol(name = 'iq', + to = unicode(file_props['sender']), typ = 'error') iq.setAttr('id', file_props['request-id']) err = common.xmpp.ErrorNode(code = '406', typ = 'auth', name = 'not-acceptable') iq.addChild(node=err) @@ -857,8 +853,8 @@ class Connection: def send_file_approval(self, file_props): ''' comfirm that we want to download the file ''' - iq = common.xmpp.Protocol(name = 'iq', to = str(file_props['sender']), - typ = 'result') + iq = common.xmpp.Protocol(name = 'iq', + to = unicode(file_props['sender']), typ = 'result') iq.setAttr('id', file_props['request-id']) si = iq.setTag('si') si.setNamespace(common.xmpp.NS_SI) @@ -908,17 +904,13 @@ class Connection: def _rosterSetCB(self, con, iq_obj): gajim.log.debug('rosterSetCB') for item in iq_obj.getTag('query').getChildren(): - jid = item.getAttr('jid').encode('utf8') + jid = item.getAttr('jid') name = item.getAttr('name') - if name: - name = name.encode('utf8') - sub = item.getAttr('subscription').encode('utf8') + sub = item.getAttr('subscription') ask = item.getAttr('ask') - if ask: - ask = ask.encode('utf8') groups = [] for group in item.getTags('group'): - groups.append(group.getData().encode('utf8')) + groups.append(group.getData()) self.dispatch('ROSTER_INFO', (jid, name, sub, ask, groups)) raise common.xmpp.NodeProcessed @@ -930,7 +922,7 @@ class Connection: continue attr = {} for key in q.getAttrs().keys(): - attr[key.encode('utf8')] = q.getAttr(key).encode('utf8') + attr[key] = q.getAttr(key) identities = [attr] for node in q.getChildren(): if node.getName() == 'ns': @@ -938,10 +930,10 @@ class Connection: else: infos = {} for key in node.getAttrs().keys(): - infos[key.encode('utf8')] = node.getAttr(key).encode('utf8') + infos[key] = node.getAttr(key) infos['category'] = node.getName() items.append(infos) - jid = str(iq_obj.getFrom()) + jid = unicode(iq_obj.getFrom()) self.dispatch('AGENT_INFO', (jid, identities, features, items)) def _DiscoverItemsCB(self, con, iq_obj): @@ -957,9 +949,9 @@ class Connection: for i in qp: attr = {} for key in i.getAttrs(): - attr[key.encode('utf8')] = i.getAttrs()[key].encode('utf8') + attr[key] = i.getAttrs()[key] items.append(attr) - jid = str(iq_obj.getFrom()) + jid = unicode(iq_obj.getFrom()) self.dispatch('AGENT_INFO_ITEMS', (jid, node, items)) def _DiscoverInfoErrorCB(self, con, iq_obj): @@ -985,11 +977,11 @@ class Connection: if i.getName() == 'identity': attr = {} for key in i.getAttrs().keys(): - attr[key.encode('utf8')] = i.getAttr(key).encode('utf8') + attr[key] = i.getAttr(key) identities.append(attr) elif i.getName() == 'feature': features.append(i.getAttr('var')) - jid = str(iq_obj.getFrom()) + jid = unicode(iq_obj.getFrom()) if not identities: self.to_be_sent.append(common.xmpp.Iq(typ = 'get', queryNS = \ common.xmpp.NS_AGENTS)) @@ -1086,11 +1078,11 @@ class Connection: dic[i]['options'][j]['values'].append(tag.getData()) j += 1 i += 1 - self.dispatch('GC_CONFIG', (str(iq_obj.getFrom()), dic)) + self.dispatch('GC_CONFIG', (unicode(iq_obj.getFrom()), dic)) def _MucErrorCB(self, con, iq_obj): gajim.log.debug('MucErrorCB') - jid = str(iq_obj.getFrom()) + jid = unicode(iq_obj.getFrom()) errmsg = iq_obj.getError() errcode = iq_obj.getErrorCode() self.dispatch('MSGERROR', (jid, errcode, errmsg)) @@ -1101,18 +1093,6 @@ class Connection: roster = self.connection.getRoster().getRaw() if not roster: roster = {} - else: - for i in roster.keys(): - props = roster[i] - if props.has_key('name') and props['name']: - props['name'] = props['name'].encode('utf8') - if props.has_key('groups') and props['groups']: - props['groups'] = map(lambda e:e.encode('utf8'), props['groups']) - if props.has_key('resources') and props['resources']: - props['resources'] = map(lambda e:e.encode('utf8'), - props['resources']) - del roster[i] - roster[i.encode('utf8')] = props name = gajim.config.get_per('accounts', self.name, 'name') hostname = gajim.config.get_per('accounts', self.name, 'hostname') @@ -1178,8 +1158,8 @@ class Connection: def _ErrorCB(self, con, iq_obj): errmsg = iq_obj.getError() errcode = iq_obj.getErrorCode() - jid_from = str(iq_obj.getFrom()) - id = str(iq_obj.getID()) + jid_from = unicode(iq_obj.getFrom()) + id = unicode(iq_obj.getID()) self.dispatch('ERROR_ANSWER', (id, jid_from, errmsg, errcode)) def _StanzaArrivedCB(self, con, obj): @@ -1214,9 +1194,9 @@ class Connection: self.dispatch('REGISTER_AGENT_INFO', (data[0], data[1].asDict())) elif realm == '': if event == common.xmpp.transports.DATA_RECEIVED: - self.dispatch('STANZA_ARRIVED', str(data)) + self.dispatch('STANZA_ARRIVED', unicode(data)) elif event == common.xmpp.transports.DATA_SENT: - self.dispatch('STANZA_SENT', str(data)) + self.dispatch('STANZA_SENT', unicode(data)) def connect(self): """Connect and authenticate to the Jabber server @@ -1389,7 +1369,7 @@ class Connection: # active the privacy rule self.privacy_rules_supported = True self.activate_privacy_rule('invisible') - prio = str(gajim.config.get_per('accounts', self.name, 'priority')) + prio = unicode(gajim.config.get_per('accounts', self.name, 'priority')) p = common.xmpp.Presence(typ = ptype, priority = prio, show = show) p = self.add_sha(p) if msg: @@ -1446,7 +1426,8 @@ class Connection: if show == 'invisible': self.send_invisible_presence(msg, signed, True) return - prio = str(gajim.config.get_per('accounts', self.name, 'priority')) + prio = unicode(gajim.config.get_per('accounts', self.name, + 'priority')) p = common.xmpp.Presence(typ = None, priority = prio, show = sshow) p = self.add_sha(p) if msg: @@ -1490,7 +1471,8 @@ class Connection: iq = self.build_privacy_rule('visible', 'allow') self.connection.send(iq) self.activate_privacy_rule('visible') - prio = str(gajim.config.get_per('accounts', self.name, 'priority')) + prio = unicode(gajim.config.get_per('accounts', self.name, + 'priority')) p = common.xmpp.Presence(typ = None, priority = prio, show = sshow) p = self.add_sha(p) if msg: @@ -1945,7 +1927,7 @@ class Connection: keep_alive_disconnect_after_foo_secs): self.connection.disconnect() # disconnect if no answer pritext = _('Gajim disconnected you from %s') % self.name - sectext = _('%s seconds have passed and server did not reply to our keep-alive. If you believe such disconnection should not have happened, you can disable sending keep-alive packets by modifying this account.') % str(keep_alive_disconnect_after_foo_secs) + sectext = _('%s seconds have passed and server did not reply to our keep-alive. If you believe such disconnection should not have happened, you can disable sending keep-alive packets by modifying this account.') % unicode(keep_alive_disconnect_after_foo_secs) self.dispatch('ERROR', (pritext, sectext)) return if self.connection: diff --git a/src/common/helpers.py b/src/common/helpers.py index 21212361a..361e4faff 100644 --- a/src/common/helpers.py +++ b/src/common/helpers.py @@ -62,7 +62,7 @@ def convert_bytes(string): else: #B means bytes suffix = _('%s B') - return suffix % str(bytes) + return suffix % unicode(bytes) def get_uf_show(show): '''returns a userfriendly string for dnd/xa/chat diff --git a/src/common/logger.py b/src/common/logger.py index b9b4490ea..7d0848f05 100644 --- a/src/common/logger.py +++ b/src/common/logger.py @@ -127,6 +127,14 @@ class Logger: files.append(ji + '/' + ji) jid = 'gc' show = nick + if type(tim) == unicode: + tim = tim.encode('utf-8') + if type(jid) == unicode: + jid = jid.encode('utf-8') + if type(show) == unicode: + show = show.encode('utf-8') + if msg and type(msg) == unicode: + msg = msg.encode('utf-8') for f in files: path_to_file = os.path.join(LOGPATH, f) if os.path.isdir(path_to_file): @@ -174,7 +182,7 @@ class Logger: while (no_of_lines < begin_line and fil.readline()): no_of_lines += 1 while no_of_lines < end_line: - line = fil.readline() + line = fil.readline().decode('utf-8') if line: line = helpers.from_one_line(line) lineSplited = line.split(':') diff --git a/src/common/optparser.py b/src/common/optparser.py index 22bdc6159..2dc3820fb 100644 --- a/src/common/optparser.py +++ b/src/common/optparser.py @@ -52,21 +52,31 @@ class OptionsParser: return for line in fd.readlines(): + line = line.decode('utf-8') self.read_line(line) fd.close() def write_line(self, fd, opt, parents, value): + if value == None: + return + value = value[1] + if type(value) == unicode: + value = value.encode('utf-8') + else: + value = str(value) + if type(opt) == unicode: + opt = opt.encode('utf-8') s = '' if parents: if len(parents) == 1: return for p in parents: + if type(p) == unicode: + p = p.encode('utf-8') s += p + '.' - if value == None: - return s += opt - fd.write(s + ' = ' + str(value[1]) + '\n') + fd.write(s + ' = ' + value + '\n') def write(self): (base_dir, filename) = os.path.split(self.__filename) diff --git a/src/config.py b/src/config.py index 1d5282d4d..71d6f3238 100644 --- a/src/config.py +++ b/src/config.py @@ -514,7 +514,7 @@ class PreferencesWindow: def on_iconset_combobox_changed(self, widget): model = widget.get_model() active = widget.get_active() - icon_string = model[active][1] + icon_string = model[active][1].decode('utf-8') gajim.config.set('iconset', icon_string) self.plugin.roster.reload_jabber_state_images() self.plugin.save_config() @@ -529,7 +529,7 @@ class PreferencesWindow: def on_theme_combobox_changed(self, widget): model = widget.get_model() active = widget.get_active() - theme = model[active][0] + theme = model[active][0].decode('utf-8') gajim.config.set('roster_theme', theme) @@ -684,19 +684,19 @@ class PreferencesWindow: self.plugin.save_config() def on_before_time_entry_focus_out_event(self, widget, event): - gajim.config.set('before_time', widget.get_text()) + gajim.config.set('before_time', widget.get_text().decode('utf-8')) self.plugin.save_config() def on_after_time_entry_focus_out_event(self, widget, event): - gajim.config.set('after_time', widget.get_text()) + gajim.config.set('after_time', widget.get_text().decode('utf-8')) self.plugin.save_config() def on_before_nickname_entry_focus_out_event(self, widget, event): - gajim.config.set('before_nickname', widget.get_text()) + gajim.config.set('before_nickname', widget.get_text().decode('utf-8')) self.plugin.save_config() def on_after_nickname_entry_focus_out_event(self, widget, event): - gajim.config.set('after_nickname', widget.get_text()) + gajim.config.set('after_nickname', widget.get_text().decode('utf-8')) self.plugin.save_config() def update_text_tags(self): @@ -800,7 +800,7 @@ class PreferencesWindow: self.xml.get_widget('browse_sounds_hbox')]) def on_soundplayer_entry_changed(self, widget): - gajim.config.set('soundplayer', widget.get_text()) + gajim.config.set('soundplayer', widget.get_text().decode('utf-8')) self.plugin.save_config() def on_prompt_online_status_message_checkbutton_toggled(self, widget): @@ -810,11 +810,11 @@ class PreferencesWindow: self.on_checkbutton_toggled(widget, 'ask_offline_status') def on_sounds_treemodel_row_changed(self, model, path, iter): - sound_event = model.get_value(iter, 0) + sound_event = model.get_value(iter, 0).decode('utf-8') gajim.config.set_per('soundevents', sound_event, 'enabled', bool(model[path][1])) gajim.config.set_per('soundevents', sound_event, 'path', - model[iter][2]) + model[iter][2].decode('utf-8')) self.plugin.save_config() def on_auto_away_checkbutton_toggled(self, widget): @@ -830,7 +830,7 @@ class PreferencesWindow: self.plugin.save_config() def on_auto_away_message_entry_changed(self, widget): - gajim.config.set('autoaway_message', widget.get_text()) + gajim.config.set('autoaway_message', widget.get_text().decode('utf-8')) def on_auto_xa_checkbutton_toggled(self, widget): self.on_checkbutton_toggled(widget, 'autoxa', @@ -845,17 +845,17 @@ class PreferencesWindow: self.plugin.save_config() def on_auto_xa_message_entry_changed(self, widget): - gajim.config.set('autoxa_message', widget.get_text()) + gajim.config.set('autoxa_message', widget.get_text().decode('utf-8')) def save_status_messages(self, model): for msg in gajim.config.get_per('statusmsg'): gajim.config.del_per('statusmsg', msg) iter = model.get_iter_first() while iter: - val = model.get_value(iter, 0) + val = model.get_value(iter, 0).decode('utf-8') gajim.config.add_per('statusmsg', val) gajim.config.set_per('statusmsg', val, 'message', - model[iter][1]) + model[iter][1].decode('utf-8')) iter = model.iter_next(iter) self.plugin.save_config() @@ -881,15 +881,15 @@ class PreferencesWindow: self.plugin.save_config() def on_custom_browser_entry_changed(self, widget): - gajim.config.set('custombrowser', widget.get_text()) + gajim.config.set('custombrowser', widget.get_text().decode('utf-8')) self.plugin.save_config() def on_custom_mail_client_entry_changed(self, widget): - gajim.config.set('custommailapp', widget.get_text()) + gajim.config.set('custommailapp', widget.get_text().decode('utf-8')) self.plugin.save_config() def on_custom_file_manager_entry_changed(self, widget): - gajim.config.set('custom_file_manager', widget.get_text()) + gajim.config.set('custom_file_manager', widget.get_text().decode('utf-8')) self.plugin.save_config() def on_log_in_contact_checkbutton_toggled(self, widget): @@ -987,7 +987,7 @@ class PreferencesWindow: (model, iter) = self.sound_tree.get_selection().get_selected() if not iter: return - file = model[iter][2] + file = model[iter][2].decode('utf-8') dialog = gtk.FileChooserDialog(_('Choose Sound'), None, gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, @@ -1171,7 +1171,7 @@ class AccountModificationWindow: 'custom_port') if not custom_port: custom_port = 5222 - self.xml.get_widget('custom_port_entry').set_text(str(custom_port)) + self.xml.get_widget('custom_port_entry').set_text(unicode(custom_port)) gpg_key_label = self.xml.get_widget('gpg_key_label') if gajim.config.get('usegpg'): @@ -1198,7 +1198,7 @@ class AccountModificationWindow: def on_save_button_clicked(self, widget): '''When save button is clicked: Save information in config file''' config = {} - name = self.xml.get_widget('name_entry').get_text() + name = self.xml.get_widget('name_entry').get_text().decode('utf-8') if gajim.connections.has_key(self.account): if name != self.account and \ gajim.connections[self.account].connected != 0: @@ -1213,7 +1213,7 @@ _('To change the account name, you must be disconnected.')).get_response() dialogs.ErrorDialog(_('Invalid account name'), _('Account name cannot contain spaces.')).get_response() return - jid = self.xml.get_widget('jid_entry').get_text() + jid = self.xml.get_widget('jid_entry').get_text().decode('utf-8') if jid == '' or jid.count('@') != 1: dialogs.ErrorDialog(_('Invalid Jabber ID'), _('A Jabber ID must be in the form "user@servername".')).get_response() @@ -1221,12 +1221,12 @@ _('To change the account name, you must be disconnected.')).get_response() new_account = self.xml.get_widget('new_account_checkbutton').get_active() config['savepass'] = self.xml.get_widget( 'save_password_checkbutton').get_active() - config['password'] = self.xml.get_widget('password_entry').get_text() + config['password'] = self.xml.get_widget('password_entry').get_text().decode('utf-8') if new_account and config['password'] == '': dialogs.ErrorDialog(_('Invalid password'), _('You must enter a password for the new account.')).get_response() return - config['resource'] = self.xml.get_widget('resource_entry').get_text() + config['resource'] = self.xml.get_widget('resource_entry').get_text().decode('utf-8') config['priority'] = self.xml.get_widget('priority_spinbutton').\ get_value_as_int() config['autoconnect'] = self.xml.get_widget('autoconnect_checkbutton').\ @@ -1247,7 +1247,7 @@ _('To change the account name, you must be disconnected.')).get_response() 'sync_with_global_status_checkbutton').get_active() active = self.proxy_combobox.get_active() - proxy = self.proxy_combobox.get_model()[active][0] + proxy = self.proxy_combobox.get_model()[active][0].decode('utf-8') if proxy == 'None': proxy = '' config['proxy'] = proxy @@ -1266,19 +1266,19 @@ _('To change the account name, you must be disconnected.')).get_response() return config['custom_port'] = custom_port config['custom_host'] = self.xml.get_widget( - 'custom_host_entry').get_text() + 'custom_host_entry').get_text().decode('utf-8') - config['keyname'] = self.xml.get_widget('gpg_name_label').get_text() + config['keyname'] = self.xml.get_widget('gpg_name_label').get_text().decode('utf-8') if config['keyname'] == '': #no key selected config['keyid'] = '' config['savegpgpass'] = False config['gpgpassword'] = '' else: - config['keyid'] = self.xml.get_widget('gpg_key_label').get_text() + config['keyid'] = self.xml.get_widget('gpg_key_label').get_text().decode('utf-8') config['savegpgpass'] = self.xml.get_widget( 'gpg_save_password_checkbutton').get_active() config['gpgpassword'] = self.xml.get_widget('gpg_password_entry').\ - get_text() + get_text().decode('utf-8') #if we are modifying an account if self.modify: #if we modify the name of the account @@ -1421,7 +1421,7 @@ _('To change the account name, you must be disconnected.')).get_response() dialogs.ErrorDialog(_('No such account available'), _('You must create your account before editing your personal information.')).get_response() return - jid = self.xml.get_widget('jid_entry').get_text() + jid = self.xml.get_widget('jid_entry').get_text().decode('utf-8') # show error dialog if account is newly created (not in gajim.connections) if not gajim.connections.has_key(self.account) or \ @@ -1567,17 +1567,17 @@ class ManageProxiesWindow: model = self.proxies_treeview.get_model() proxies = gajim.config.get_per('proxies') i = 1 - while ('proxy' + str(i)) in proxies: + while ('proxy' + unicode(i)) in proxies: i += 1 iter = model.append() - model.set(iter, 0, 'proxy' + str(i)) - gajim.config.add_per('proxies', 'proxy' + str(i)) + model.set(iter, 0, 'proxy' + unicode(i)) + gajim.config.add_per('proxies', 'proxy' + unicode(i)) def on_remove_proxy_button_clicked(self, widget): (model, iter) = self.proxies_treeview.get_selection().get_selected() if not iter: return - proxy = model.get_value(iter, 0) + proxy = model.get_value(iter, 0).decode('utf-8') model.remove(iter) gajim.config.del_per('proxies', proxy) self.xml.get_widget('remove_proxy_button').set_sensitive(False) @@ -1619,8 +1619,8 @@ class ManageProxiesWindow: self.xml.get_widget('proxy_table').set_sensitive(True) proxyhost_entry.set_text(gajim.config.get_per('proxies', proxy, 'host')) - proxyport_entry.set_text(str(gajim.config.get_per('proxies', proxy, - 'port'))) + proxyport_entry.set_text(unicode(gajim.config.get_per('proxies', + proxy, 'port'))) proxyuser_entry.set_text(gajim.config.get_per('proxies', proxy, 'user')) proxypass_entry.set_text(gajim.config.get_per('proxies', proxy, @@ -1637,8 +1637,8 @@ class ManageProxiesWindow: (model, iter) = self.proxies_treeview.get_selection().get_selected() if not iter: return - old_name = model.get_value(iter, 0) - new_name = widget.get_text() + old_name = model.get_value(iter, 0).decode('utf-8') + new_name = widget.get_text().decode('utf-8') if new_name == '': return if new_name == old_name: @@ -1656,23 +1656,23 @@ class ManageProxiesWindow: pass def on_proxyhost_entry_changed(self, widget): - value = widget.get_text() - proxy = self.proxyname_entry.get_text() + value = widget.get_text().decode('utf-8') + proxy = self.proxyname_entry.get_text().decode('utf-8') gajim.config.set_per('proxies', proxy, 'host', value) def on_proxyport_entry_changed(self, widget): - value = widget.get_text() - proxy = self.proxyname_entry.get_text() + value = widget.get_text().decode('utf-8') + proxy = self.proxyname_entry.get_text().decode('utf-8') gajim.config.set_per('proxies', proxy, 'port', value) def on_proxyuser_entry_changed(self, widget): - value = widget.get_text() - proxy = self.proxyname_entry.get_text() + value = widget.get_text().decode('utf-8') + proxy = self.proxyname_entry.get_text().decode('utf-8') gajim.config.set_per('proxies', proxy, 'user', value) def on_proxypass_entry_changed(self, widget): - value = widget.get_text() - proxy = self.proxyname_entry.get_text() + value = widget.get_text().decode('utf-8') + proxy = self.proxyname_entry.get_text().decode('utf-8') gajim.config.set_per('proxies', proxy, 'pass', value) @@ -1741,7 +1741,7 @@ class AccountsWindow: (model, iter) = sel.get_selected() if not iter: return - account = model.get_value(iter, 0) + account = model.get_value(iter, 0).decode('utf-8') if self.plugin.windows[account].has_key('remove_account'): self.plugin.windows[account]['remove_account'].window.present() else: @@ -1755,7 +1755,7 @@ class AccountsWindow: (model, iter) = sel.get_selected() if not iter: return - account = model.get_value(iter, 0) + account = model.get_value(iter, 0).decode('utf-8') if self.plugin.windows[account].has_key('account_modification'): self.plugin.windows[account]['account_modification'].window.present() else: @@ -1799,7 +1799,7 @@ class ServiceRegistrationWindow: '''When Ok button is clicked: send registration info to the core''' for name in self.entries.keys(): - self.infos[name] = self.entries[name].get_text() + self.infos[name] = self.entries[name].get_text().decode('utf-8') if self.infos.has_key('instructions'): del self.infos['instructions'] if self.infos.has_key('registered'): @@ -1874,11 +1874,12 @@ class ManageEmoticonsWindow: def on_emoticons_treemodel_row_changed(self, model, path, iter): emots = gajim.config.get_per('emoticons') - emot = model.get_value(iter, 0).upper() + emot = model.get_value(iter, 0).decode('utf-8').upper() if not emot in emots: gajim.config.add_per('emoticons', emot) self.plugin.init_regexp() # update regexp [emoticons included] - gajim.config.set_per('emoticons', emot, 'path', model[iter][1]) + gajim.config.set_per('emoticons', emot, 'path', + model[iter][1].decode('utf-8')) self.plugin.save_config() def image_is_ok(self, image): @@ -1925,17 +1926,17 @@ class ManageEmoticonsWindow: emots = gajim.config.get_per('emoticons') model = self.emot_tree.get_model() iter = model.get_iter_from_string(row) - old_text = model.get_value(iter, 0) + old_text = model.get_value(iter, 0).decode('utf-8') if old_text in emots: gajim.config.del_per('emoticons', old_text) - emot = new_text.upper() + emot = new_text.decode('utf-8').upper() if emot in emots: model.remove(iter) else: gajim.config.add_per('emoticons', emot) self.plugin.init_regexp() # update regexp [emoticons included] gajim.config.set_per('emoticons', emot, 'path', - model[iter][1]) + model[iter][1].decode('utf-8')) model.set_value(iter, 0, emot) self.plugin.save_config() @@ -1947,7 +1948,7 @@ class ManageEmoticonsWindow: (model, iter) = self.emot_tree.get_selection().get_selected() if not iter: return - file = model[iter][1] + file = model[iter][1].decode('utf-8') dialog = gtk.FileChooserDialog(_('Choose Image'), None, gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, @@ -2019,7 +2020,7 @@ class ManageEmoticonsWindow: (model, iter) = self.emot_tree.get_selection().get_selected() if not iter: return - gajim.config.del_per('emoticons', model.get_value(iter, 0)) + gajim.config.del_per('emoticons', model.get_value(iter, 0).decode('utf-8')) self.plugin.init_regexp() # update regexp [emoticons included] self.plugin.save_config() model.remove(iter) @@ -2135,11 +2136,11 @@ _('Without a connection, you can not browse available services')).get_response() def on_services_treeview_row_expanded(self, widget, iter, path): model = self.services_treeview.get_model() - jid = model[iter][1] + jid = model[iter][1].decode('utf-8') child = model.iter_children(iter) while child: - child_jid = model.get_value(child, 1) - child_node = model.get_value(child, 2) + child_jid = model.get_value(child, 1).decode('utf-8') + child_node = model.get_value(child, 2).decode('utf-8') # We never requested its infos if not self.agent_infos[child_jid + child_node].has_key('features'): self.browse(child_jid, child_node) @@ -2151,8 +2152,8 @@ _('Without a connection, you can not browse available services')).get_response() iter = model.get_iter_root() # We look if this agent is in the treeview while (iter): - if agent == model[iter][1] and node == model.get_value( - iter, 2): + if agent == model[iter][1].decode('utf-8') and\ + node == model.get_value(iter, 2).decode('utf-8'): break if model.iter_has_child(iter): iter = model.iter_children(iter) @@ -2176,8 +2177,8 @@ _('Without a connection, you can not browse available services')).get_response() iter = model.get_iter_root() # We look if this agent is in the treeview while (iter): - if agent == model[iter][1] and node == model.get_value( - iter, 2): + if agent == model[iter][1].decode('utf-8') and\ + node == model.get_value(iter, 2).decode('utf-8'): break if model.iter_has_child(iter): iter = model.iter_children(iter) @@ -2201,8 +2202,8 @@ _('Without a connection, you can not browse available services')).get_response() # We look if this item is already in the treeview iter_child = model.iter_children(iter) while iter_child: - if item['jid'] == model.get_value(iter_child, 1) and \ - node == model.get_value(iter_child, 2): + if item['jid'] == model.get_value(iter_child, 1).decode('utf-8') and\ + node == model.get_value(iter_child, 2).decode('utf-8'): break iter_child = model.iter_next(iter_child) if not iter_child: # If it is not we add it @@ -2223,7 +2224,7 @@ _('Without a connection, you can not browse available services')).get_response() def on_refresh_button_clicked(self, widget): '''When refresh button is clicked: refresh list: clear and rerequest it''' self.services_treeview.get_model().clear() - jid = self.address_comboboxentry.child.get_text() + jid = self.address_comboboxentry.child.get_text().decode('utf-8') self.browse(jid) def on_address_comboboxentry_changed(self, widget): @@ -2231,7 +2232,7 @@ _('Without a connection, you can not browse available services')).get_response() if self.address_comboboxentry.get_active() != -1: # user selected one of the entries so do auto-visit self.services_treeview.get_model().clear() - server_address = self.address_comboboxentry.child.get_text() + server_address = self.address_comboboxentry.child.get_text().decode('utf-8') self.browse(server_address) def on_services_treeview_row_activated(self, widget, path, col = 0): @@ -2248,7 +2249,7 @@ _('Without a connection, you can not browse available services')).get_response() model, iter = self.services_treeview.get_selection().get_selected() if not iter: return - service = model[iter][1] + service = model[iter][1].decode('utf-8') room = '' if service.find('@') != -1: services = service.split('@') @@ -2265,7 +2266,7 @@ _('Without a connection, you can not browse available services')).get_response() model, iter = self.services_treeview.get_selection().get_selected() if not iter : return - service = model[iter][1] + service = model[iter][1].decode('utf-8') gajim.connections[self.account].request_register_agent_info(service) self.window.destroy() @@ -2281,8 +2282,8 @@ _('Without a connection, you can not browse available services')).get_response() path = model.get_path(iter) if len(path) == 1: # we selected the jabber server return - jid = model[iter][1] - node = model[iter][2] + jid = model[iter][1].decode('utf-8') + node = model[iter][2].decode('utf-8') registered_transports = [] contacts = gajim.contacts[self.account] for j in contacts: @@ -2303,7 +2304,7 @@ _('Without a connection, you can not browse available services')).get_response() self.join_button.set_sensitive(True) def on_go_button_clicked(self, widget): - server_address = self.address_comboboxentry.child.get_text() + server_address = self.address_comboboxentry.child.get_text().decode('utf-8') if server_address in self.latest_addresses: self.latest_addresses.remove(server_address) self.latest_addresses.insert(0, server_address) @@ -2351,7 +2352,7 @@ class GroupchatConfigWindow: widget.get_active()]['values'][0] def on_entry_changed(self, widget, index): - self.config[index]['values'][0] = widget.get_text() + self.config[index]['values'][0] = widget.get_text().decode('utf-8') def on_textbuffer_changed(self, widget, index): begin, end = widget.get_bounds() @@ -2627,7 +2628,7 @@ class ManageBookmarksWindow: #Account data can't be changed return - if self.server_entry.get_text() == '' or self.room_entry.get_text() == '': + if self.server_entry.get_text().decode('utf-8') == '' or self.room_entry.get_text().decode('utf-8') == '': dialogs.ErrorDialog(_('This bookmark has invalid data'), _('Please be sure to fill out server and room fields or remove this bookmark.')).get_response() return False @@ -2650,7 +2651,7 @@ _('Please be sure to fill out server and room fields or remove this bookmark.')) for bm in account.iterchildren(): #Convert True/False/None to '1' or '0' - autojoin = str(int(bm[3])) + autojoin = unicode(int(bm[3])) #create the bookmark-dict bmdict = { 'name': bm[1], 'jid': bm[2], 'autojoin': autojoin, @@ -2693,7 +2694,7 @@ _('Please be sure to fill out server and room fields or remove this bookmark.')) #Fill in the data for childs self.title_entry.set_text(model[iter][1]) - room_jid = model[iter][2] + room_jid = model[iter][2].decode('utf-8') try: (room, server) = room_jid.split('@') except ValueError: @@ -2722,15 +2723,15 @@ _('Please be sure to fill out server and room fields or remove this bookmark.')) def on_server_entry_changed(self, widget): (model, iter) = self.selection.get_selected() if iter: - room_jid = self.room_entry.get_text() + '@' + \ - self.server_entry.get_text() + room_jid = self.room_entry.get_text().decode('utf-8') + '@' + \ + self.server_entry.get_text().decode('utf-8') model[iter][2] = room_jid def on_room_entry_changed(self, widget): (model, iter) = self.selection.get_selected() if iter: - room_jid = self.room_entry.get_text() + '@' + \ - self.server_entry.get_text() + room_jid = self.room_entry.get_text().decode('utf-8') + '@' + \ + self.server_entry.get_text().decode('utf-8') model[iter][2] = room_jid def on_pass_entry_changed(self, widget): @@ -2843,7 +2844,7 @@ class FirstTimeWizardWindow: self.back_button.set_sensitive(True) elif cur_page == 1: - user = self.nick_entry.get_text() + user = self.nick_entry.get_text().decode('utf-8') server = self.server_comboboxentry.get_active_text() if self.check_data(user, server): #TODO: write account to config file @@ -2854,7 +2855,7 @@ class FirstTimeWizardWindow: self.go_to_last_page() elif cur_page == 2: - user = self.register_nick_entry.get_text() + user = self.register_nick_entry.get_text().decode('utf-8') server = self.register_server_comboboxentry.get_active_text() if self.check_data(user, server): #TODO: Register account @@ -2930,7 +2931,7 @@ _('You need to enter a valid server address to add an account.')).get_response() return True def update_jid(self, name_widget, server_widget, jid_widget): - name = name_widget.get_text() + name = name_widget.get_text().decode('utf-8') server = server_widget.get_active_text() if len(name) == 0 or len(server) == 0: jid_widget.set_label('') diff --git a/src/dialogs.py b/src/dialogs.py index 9bc40bc89..50946a4e5 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -76,14 +76,14 @@ class EditGroupsDialog: self.user.name, self.user.groups) def on_add_button_clicked(self, widget): - group = self.xml.get_widget('group_entry').get_text() + group = self.xml.get_widget('group_entry').get_text().decode('utf-8') if not group: return # check if it already exists model = self.list.get_model() iter = model.get_iter_root() while iter: - if model.get_value(iter, 0) == group: + if model.get_value(iter, 0).decode('utf-8') == group: return iter = model.iter_next(iter) self.changes_made = True @@ -101,9 +101,9 @@ class EditGroupsDialog: return model[path][1] = not model[path][1] if model[path][1]: - self.user.groups.append(model[path][0]) + self.user.groups.append(model[path][0].decode('utf-8')) else: - self.user.groups.remove(model[path][0]) + self.user.groups.remove(model[path][0].decode('utf-8')) self.update_contact() def init_list(self): @@ -138,7 +138,7 @@ class PassphraseDialog: '''Wait for OK button to be pressed and return passphrase/password''' rep = self.window.run() if rep == gtk.RESPONSE_OK: - passphrase = self.passphrase_entry.get_text() + passphrase = self.passphrase_entry.get_text().decode('utf-8') else: passphrase = -1 save_passphrase_checkbutton = self.xml.\ @@ -185,7 +185,7 @@ class ChooseGPGKeyDialog: if rep == gtk.RESPONSE_OK: selection = self.keys_treeview.get_selection() (model, iter) = selection.get_selected() - keyID = [ model[iter][0], model[iter][1] ] + keyID = [ model[iter][0].decode('utf-8'), model[iter][1] ] else: keyID = None self.window.destroy() @@ -234,7 +234,7 @@ class ChangeStatusMessageDialog: rep = self.window.run() if rep == gtk.RESPONSE_OK: beg, end = self.message_buffer.get_bounds() - message = self.message_buffer.get_text(beg, end, 0).strip() + message = self.message_buffer.get_text(beg, end, 0).decode('utf-8').strip() msg = helpers.to_one_line(message) gajim.config.set('last_status_msg_' + self.show, msg) else: @@ -247,7 +247,7 @@ class ChangeStatusMessageDialog: active = widget.get_active() if active < 0: return None - name = model[active][0] + name = model[active][0].decode('utf-8') self.message_buffer.set_text(self.values[name]) def on_change_status_message_dialog_key_press_event(self, widget, event): @@ -332,8 +332,8 @@ _('Please fill in the data of the contact you want to add in account %s') %accou def on_subscribe_button_clicked(self, widget): '''When Subscribe button is clicked''' - jid = self.jid_entry.get_text() - nickname = self.nickname_entry.get_text() + jid = self.jid_entry.get_text().decode('utf-8') + nickname = self.nickname_entry.get_text().decode('utf-8') if not jid: return if jid.find('@') < 0: @@ -343,8 +343,8 @@ _('Contact names must be of the form "user@servername".')).get_response() message_buffer = self.xml.get_widget('message_textview').get_buffer() start_iter = message_buffer.get_start_iter() end_iter = message_buffer.get_end_iter() - message = message_buffer.get_text(start_iter, end_iter, 0) - group = self.group_comboboxentry.child.get_text() + message = message_buffer.get_text(start_iter, end_iter, 0).decode('utf-8') + group = self.group_comboboxentry.child.get_text().decode('utf-8') self.plugin.roster.req_sub(self, jid, message, self.account, group = group, pseudo = nickname) if self.xml.get_widget('auto_authorize_checkbutton').get_active(): @@ -354,10 +354,10 @@ _('Contact names must be of the form "user@servername".')).get_response() def fill_jid(self): model = self.protocol_combobox.get_model() index = self.protocol_combobox.get_active() - jid = self.uid_entry.get_text().strip() + jid = self.uid_entry.get_text().decode('utf-8').strip() if index > 0: # it's not jabber but a transport jid = jid.replace('@', '%') - agent = model[index][1] + agent = model[index][1].decode('utf-8') if agent: jid += '@' + agent self.jid_entry.set_text(jid) @@ -366,7 +366,7 @@ _('Contact names must be of the form "user@servername".')).get_response() self.fill_jid() def guess_agent(self): - uid = self.uid_entry.get_text() + uid = self.uid_entry.get_text().decode('utf-8') model = self.protocol_combobox.get_model() #If login contains only numbers, it's probably an ICQ number @@ -376,13 +376,13 @@ _('Contact names must be of the form "user@servername".')).get_response() return def set_nickname(self): - uid = self.uid_entry.get_text() - nickname = self.nickname_entry.get_text() + uid = self.uid_entry.get_text().decode('utf-8') + nickname = self.nickname_entry.get_text().decode('utf-8') if nickname == self.old_uid_value: self.nickname_entry.set_text(uid.split('@')[0]) def on_uid_entry_changed(self, widget): - uid = self.uid_entry.get_text() + uid = self.uid_entry.get_text().decode('utf-8') self.guess_agent() self.set_nickname() self.fill_jid() @@ -544,7 +544,7 @@ class InputDialog: self.dialog.show_all() def on_okbutton_clicked(self, widget): - response = self.input_entry.get_text() + response = self.input_entry.get_text().decode('utf-8') self.dialog.destroy() self.ok_handler(response) @@ -664,7 +664,7 @@ _('You can not join a group chat unless you are connected.')).get_response() def on_recently_combobox_changed(self, widget): model = widget.get_model() iter = widget.get_active_iter() - gid = model[iter][0] + gid = model[iter][0].decode('utf-8') self.xml.get_widget('room_entry').set_text(gid.split('@')[0]) self.xml.get_widget('server_entry').set_text(gid.split('@')[1]) @@ -674,10 +674,10 @@ _('You can not join a group chat unless you are connected.')).get_response() def on_join_button_clicked(self, widget): '''When Join button is clicked''' - nickname = self.xml.get_widget('nickname_entry').get_text() - room = self.xml.get_widget('room_entry').get_text() - server = self.xml.get_widget('server_entry').get_text() - password = self.xml.get_widget('password_entry').get_text() + nickname = self.xml.get_widget('nickname_entry').get_text().decode('utf-8') + room = self.xml.get_widget('room_entry').get_text().decode('utf-8') + server = self.xml.get_widget('server_entry').get_text().decode('utf-8') + password = self.xml.get_widget('password_entry').get_text().decode('utf-8') jid = '%s@%s' % (room, server) if jid in self.recently_groupchat: self.recently_groupchat.remove(jid) @@ -743,12 +743,12 @@ _('Without a connection, you can not change your password.')).get_response() while not end: rep = self.dialog.run() if rep == gtk.RESPONSE_OK: - password1 = self.password1_entry.get_text() + password1 = self.password1_entry.get_text().decode('utf-8') if not password1: ErrorDialog(_('Invalid password'), _('You must enter a password.')).get_response() continue - password2 = self.password2_entry.get_text() + password2 = self.password2_entry.get_text().decode('utf-8') if password1 != password2: ErrorDialog(_('Passwords do not match'), _('The passwords typed in both fields must be identical.')).get_response() @@ -818,7 +818,7 @@ class PopupNotificationWindow: if file_props is not None: if file_props['type'] == 'r': # get the name of the sender, as it is in the roster - sender = str(file_props['sender']).split('/')[0] + sender = unicode(file_props['sender']).split('/')[0] name = gajim.get_first_contact_instance_from_jid( account, sender).name txt = _('From %s') % name @@ -1017,7 +1017,7 @@ class SingleMessageWindow: def update_char_counter(self, widget): characters_no = self.message_tv_buffer.get_char_count() - self.count_chars_label.set_text(str(characters_no)) + self.count_chars_label.set_text(unicode(characters_no)) def send_single_message(self): if gajim.connections[self.account].connected <= 1: @@ -1026,10 +1026,10 @@ class SingleMessageWindow: _('Please make sure you are connected with "%s".' % self.account) ).get_response() return - to_whom_jid = self.to_entry.get_text() - subject = self.subject_entry.get_text() + to_whom_jid = self.to_entry.get_text().decode('utf-8') + subject = self.subject_entry.get_text().decode('utf-8') begin, end = self.message_tv_buffer.get_bounds() - message = self.message_tv_buffer.get_text(begin, end) + message = self.message_tv_buffer.get_text(begin, end).decode('utf-8') if to_whom_jid.find('/announce/') != -1: gajim.connections[self.account].send_motd(to_whom_jid, subject, @@ -1148,7 +1148,7 @@ class XMLConsoleWindow: ).get_response() return begin_iter, end_iter = self.input_tv_buffer.get_bounds() - stanza = self.input_tv_buffer.get_text(begin_iter, end_iter) + stanza = self.input_tv_buffer.get_text(begin_iter, end_iter).decode('utf-8') if stanza: gajim.connections[self.account].send_stanza(stanza) self.input_tv_buffer.set_text('') # we sent ok, clear the textview diff --git a/src/filetransfers_window.py b/src/filetransfers_window.py index 05cc94029..44812b394 100644 --- a/src/filetransfers_window.py +++ b/src/filetransfers_window.py @@ -117,7 +117,7 @@ class FileTransfersWindow: # 'account' is the sender for file_props in self.files_props['s'].values(): if file_props['tt_account'] == account: - receiver_jid = str(file_props['receiver']).split('/')[0] + receiver_jid = unicode(file_props['receiver']).split('/')[0] if jid == receiver_jid: if not self.is_transfer_stoped(file_props): active_transfers[0].append(file_props) @@ -125,7 +125,7 @@ class FileTransfersWindow: # 'account' is the recipient for file_props in self.files_props['r'].values(): if file_props['tt_account'] == account: - sender_jid = str(file_props['sender']).split('/')[0] + sender_jid = unicode(file_props['sender']).split('/')[0] if jid == sender_jid: if not self.is_transfer_stoped(file_props): active_transfers[1].append(file_props) @@ -145,7 +145,7 @@ class FileTransfersWindow: sectext += '\n\t' + _('Size: %s') % \ helpers.convert_bytes(file_props['size']) if file_props['type'] == 'r': - jid = str(file_props['sender']).split('/')[0] + jid = unicode(file_props['sender']).split('/')[0] sender_name = gajim.get_first_contact_instance_from_jid( file_props['tt_account'], jid).name sender = gtkgui_helpers.escape_for_pango_markup(sender_name) @@ -155,7 +155,7 @@ class FileTransfersWindow: sectext += '\n\t' +_('Sender: %s') % sender sectext += '\n\t' +_('Recipient: ') if file_props['type'] == 's': - jid = str(file_props['receiver']).split('/')[0] + jid = unicode(file_props['receiver']).split('/')[0] receiver_name = gajim.get_first_contact_instance_from_jid( file_props['tt_account'], jid).name recipient = gtkgui_helpers.escape_for_pango_markup(receiver_name) @@ -342,7 +342,7 @@ _('Connection with peer cannot be established.')) iter = self.get_iter_by_sid(typ, sid) if iter is None: return - sid = self.model[iter][4] + sid = self.model[iter][4].decode('utf-8') file_props = self.files_props[sid[0]][sid[1:]] if status == 'stop': file_props['stopped'] = True @@ -363,7 +363,7 @@ _('Connection with peer cannot be established.')) if iter is None: iter = self.get_iter_by_sid(typ, sid) if iter is not None: - text = str(percent) + '%\n' + text = unicode(percent) + '%\n' if transfered_size == 0: text += '0' else: @@ -389,7 +389,7 @@ _('Connection with peer cannot be established.')) session id''' iter = self.model.get_iter_root() while iter: - if typ + sid == self.model[iter][4]: + if typ + sid == self.model[iter][4].decode('utf-8'): return iter iter = self.model.iter_next(iter) @@ -410,7 +410,7 @@ _('Connection with peer cannot be established.')) if os.path.exists(file_path) and os.path.isfile(file_path): stat = os.stat(file_path) os.stat(file_path) - file_props['size'] = str(stat[6]) + file_props['size'] = unicode(stat[6]) file_props['sid'] = self.get_sid() file_props['completed'] = False file_props['started'] = False @@ -467,7 +467,7 @@ _('Connection with peer cannot be established.')) except: self.tooltip.hide_tooltip() return - sid = self.model[iter][4] + sid = self.model[iter][4].decode('utf-8') file_props = self.files_props[sid[0]][sid[1:]] if file_props is not None: if self.tooltip.timeout == 0 or self.tooltip.id != props[0]: @@ -539,7 +539,7 @@ _('Connection with peer cannot be established.')) self.set_all_insensitive() return current_iter = self.model.get_iter(path) - sid = self.model[current_iter][4] + sid = self.model[current_iter][4].decode('utf-8') file_props = self.files_props[sid[0]][sid[1:]] self.remove_button.set_sensitive(is_row_selected) self.remove_menuitem.set_sensitive(is_row_selected) @@ -597,7 +597,7 @@ _('Connection with peer cannot be established.')) if selected is None or selected[1] is None: return s_iter = selected[1] - sid = self.model[s_iter][4] + sid = self.model[s_iter][4].decode('utf-8') file_props = self.files_props[sid[0]][sid[1:]] if not file_props.has_key('tt_account'): # file transfer is not set yet @@ -639,7 +639,7 @@ _('Connection with peer cannot be established.')) if selected is None or selected[1] is None: return s_iter = selected[1] - sid = self.model[s_iter][4] + sid = self.model[s_iter][4].decode('utf-8') file_props = self.files_props[sid[0]][sid[1:]] if self.is_transfer_paused(file_props): file_props['paused'] = False @@ -656,7 +656,7 @@ _('Connection with peer cannot be established.')) if selected is None or selected[1] is None: return s_iter = selected[1] - sid = self.model[s_iter][4] + sid = self.model[s_iter][4].decode('utf-8') file_props = self.files_props[sid[0]][sid[1:]] if not file_props.has_key('tt_account'): return @@ -677,7 +677,7 @@ _('Connection with peer cannot be established.')) # check if the current pointer is at the same path # as it was before setting the timeout iter = self.model.get_iter(props[0]) - sid = self.model[iter][4] + sid = self.model[iter][4].decode('utf-8') file_props = self.files_props[sid[0]][sid[1:]] rect = self.tree.get_cell_area(props[0],props[1]) position = widget.window.get_origin() @@ -777,7 +777,7 @@ _('Connection with peer cannot be established.')) i = len(self.model) - 1 while i >= 0: iter = self.model.get_iter((i)) - sid = self.model[iter][4] + sid = self.model[iter][4].decode('utf-8') file_props = self.files_props[sid[0]][sid[1:]] if file_props.has_key('completed') and file_props['completed']: self.model.remove(iter) @@ -792,7 +792,7 @@ _('Connection with peer cannot be established.')) if selected is None or selected[1] is None: return s_iter = selected[1] - sid = self.model[s_iter][4] + sid = self.model[s_iter][4].decode('utf-8') file_props = self.files_props[sid[0]][sid[1:]] if not file_props.has_key('file-name'): return diff --git a/src/gajim.py b/src/gajim.py index 2b5d6ab5d..153039a3f 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -160,7 +160,7 @@ class Interface: def handle_event_error_answer(self, account, array): id, jid_from, errmsg, errcode = array - if str(errcode) in ['403', '406'] and id: + if unicode(errcode) in ['403', '406'] and id: # show the error dialog ft = self.windows['file_transfers'] sid = id @@ -174,7 +174,7 @@ class Interface: conn = gajim.connections[account] conn.disconnect_transfer(file_props) return - elif str(errcode) == '404': + elif unicode(errcode) == '404': conn = gajim.connections[account] sid = id if len(id) > 3 and id[2] == '_': @@ -768,7 +768,7 @@ class Interface: if file_props.has_key('stalled') and file_props['stalled'] or \ file_props.has_key('paused') and file_props['paused']: return - jid = str(file_props['sender']) + jid = unicode(file_props['sender']) if gajim.config.get('notify_on_file_complete'): if (gajim.connections[account].connected in (2, 3) and gajim.config.get('autopopup')) or \ diff --git a/src/gajim_themes_window.py b/src/gajim_themes_window.py index 78fc12cd5..032da39a4 100644 --- a/src/gajim_themes_window.py +++ b/src/gajim_themes_window.py @@ -79,7 +79,7 @@ class GajimThemesWindow: def on_theme_cell_edited(self, cell, row, new_name): model = self.themes_tree.get_model() iter = model.get_iter_from_string(row) - old_name = model.get_value(iter, 0) + old_name = model.get_value(iter, 0).decode('utf-8') if old_name == new_name: return if new_name in gajim.config.get_per('themes'): @@ -115,24 +115,24 @@ class GajimThemesWindow: return self.xml.get_widget('remove_button').set_sensitive(True) self.xml.get_widget('fonts_colors_table').set_sensitive(True) - self.current_theme = model.get_value(iter, 0) + self.current_theme = model.get_value(iter, 0).decode('utf-8') self.set_widgets(self.current_theme) def on_add_button_clicked(self, widget): model = self.themes_tree.get_model() iter = model.append() i = 0 - while _('theme name') + str(i) in gajim.config.get_per('themes'): + while _('theme name') + unicode(i) in gajim.config.get_per('themes'): i += 1 - model.set_value(iter, 0, _('theme name') + str(i)) - gajim.config.add_per('themes', _('theme_name') + str(i)) + model.set_value(iter, 0, _('theme name') + unicode(i)) + gajim.config.add_per('themes', _('theme_name') + unicode(i)) self.plugin.windows['preferences'].update_preferences_window() def on_remove_button_clicked(self, widget): (model, iter) = self.themes_tree.get_selection().get_selected() if not iter: return - name = model.get_value(iter, 0) + name = model.get_value(iter, 0).decode('utf-8') gajim.config.del_per('themes', name) model.remove(iter) self.plugin.windows['preferences'].update_preferences_window() diff --git a/src/groupchat_window.py b/src/groupchat_window.py index 6928f40d0..248c6956d 100644 --- a/src/groupchat_window.py +++ b/src/groupchat_window.py @@ -221,7 +221,7 @@ class GroupchatWindow(chat.Chat): if not iter: return None while not fin: - role_name = model.get_value(iter, 1) + role_name = model.get_value(iter, 1).decode('utf-8') if role == role_name: return iter iter = model.iter_next(iter) @@ -241,7 +241,7 @@ class GroupchatWindow(chat.Chat): if not user_iter: fin2 = True while not fin2: - if nick == model.get_value(user_iter, 1): + if nick == model.get_value(user_iter, 1).decode('utf-8'): return user_iter user_iter = model.iter_next(user_iter) if not user_iter: @@ -317,7 +317,7 @@ class GroupchatWindow(chat.Chat): if not user_iter: continue while user_iter: - nick = model.get_value(user_iter, 1) + nick = model.get_value(user_iter, 1).decode('utf-8') show = gajim.gc_contacts[self.account][room_jid][nick].show state_images = roster.get_appropriate_state_images(room_jid) image = state_images[show] #FIXME: always Jabber why? @@ -412,7 +412,7 @@ class GroupchatWindow(chat.Chat): _('Please specify the new subject:'), subject) response = instance.get_response() if response == gtk.RESPONSE_OK: - subject = instance.input_entry.get_text() + subject = instance.input_entry.get_text().decode('utf-8') gajim.connections[self.account].send_gc_subject(room_jid, subject) def on_change_nick_menuitem_activate(self, widget): @@ -422,7 +422,7 @@ class GroupchatWindow(chat.Chat): _('Please specify the new nickname you want to use:'), nick) response = instance.get_response() if response == gtk.RESPONSE_OK: - nick = instance.input_entry.get_text() + nick = instance.input_entry.get_text().decode('utf-8') gajim.connections[self.account].change_gc_nick(room_jid, nick) def on_configure_room_menuitem_activate(self, widget): @@ -464,7 +464,7 @@ class GroupchatWindow(chat.Chat): 'conversation_textview') message_buffer = widget.get_buffer() start_iter, end_iter = message_buffer.get_bounds() - message = message_buffer.get_text(start_iter, end_iter, False) + message = message_buffer.get_text(start_iter, end_iter, False).decode('utf-8') if event.keyval == gtk.keysyms.ISO_Left_Tab: # SHIFT + TAB if (event.state & gtk.gdk.CONTROL_MASK): # CTRL + SHIFT + TAB @@ -475,7 +475,7 @@ class GroupchatWindow(chat.Chat): else: cursor_position = message_buffer.get_insert() end_iter = message_buffer.get_iter_at_mark(cursor_position) - text = message_buffer.get_text(start_iter, end_iter, False) + text = message_buffer.get_text(start_iter, end_iter, False).decode('utf-8') if not text or text.endswith(' '): if not self.last_key_tabs[room_jid]: # if we are nick cycling, last char will always be space return False @@ -577,7 +577,7 @@ class GroupchatWindow(chat.Chat): message_buffer = message_textview.get_buffer() start_iter = message_buffer.get_start_iter() end_iter = message_buffer.get_end_iter() - message = message_buffer.get_text(start_iter, end_iter, 0) + message = message_buffer.get_text(start_iter, end_iter, 0).decode('utf-8') # send the message self.send_gc_message(message) @@ -702,11 +702,7 @@ class GroupchatWindow(chat.Chat): else: kind = 'status' - # nick can be unicode or utf-8 nick = self.nicks[room_jid] - if type(nick) == str: - nick = unicode(nick, 'utf-8') - if kind == 'incoming' and \ text.lower().find(nick.lower()) != -1: other_tags_for_name.append('bold') @@ -722,7 +718,7 @@ class GroupchatWindow(chat.Chat): _('You may specify a reason below:')) response = instance.get_response() if response == gtk.RESPONSE_OK: - reason = instance.input_entry.get_text() + reason = instance.input_entry.get_text().decode('utf-8') else: return # stop kicking procedure gajim.connections[self.account].gc_set_role(room_jid, nick, 'none', @@ -753,7 +749,7 @@ class GroupchatWindow(chat.Chat): _('You may specify a reason below:')) response = instance.get_response() if response == gtk.RESPONSE_OK: - reason = instance.input_entry.get_text() + reason = instance.input_entry.get_text().decode('utf-8') else: return # stop banning procedure gajim.connections[self.account].gc_set_affiliation(room_jid, jid, @@ -824,7 +820,7 @@ class GroupchatWindow(chat.Chat): '''opens a chat window and msg is not None sends private message to a contact in a room''' if nick is None: - nick = model[iter][1] + nick = model[iter][1].decode('utf-8') room_jid = self.get_active_jid() fjid = gajim.construct_fjid(room_jid, nick) # 'fake' jid if not self.plugin.windows[self.account]['chats'].has_key(fjid): @@ -873,7 +869,7 @@ class GroupchatWindow(chat.Chat): def mk_menu(self, room_jid, event, iter): '''Make contact's popup menu''' model = self.list_treeview[room_jid].get_model() - nick = model[iter][1] + nick = model[iter][1].decode('utf-8') c = gajim.gc_contacts[self.account][room_jid][nick] jid = c.jid target_affiliation = c.affiliation @@ -1003,7 +999,7 @@ class GroupchatWindow(chat.Chat): self.xmls[room_jid] = gtk.glade.XML(GTKGUI_GLADE, 'gc_vbox', APP) self.childs[room_jid] = self.xmls[room_jid].get_widget('gc_vbox') chat.Chat.new_tab(self, room_jid) - self.nicks[room_jid] = nick.decode('utf-8') + self.nicks[room_jid] = nick self.subjects[room_jid] = '' self.room_creation[room_jid] = time.time() self.nick_hits[room_jid] = [] @@ -1085,7 +1081,7 @@ class GroupchatWindow(chat.Chat): self.tooltip.hide_tooltip() return room_jid = self.get_active_jid() - nick = model[iter][1] + nick = model[iter][1].decode('utf-8') if nick != 'moderator' and nick != 'participant': account = self.account @@ -1163,7 +1159,7 @@ class GroupchatWindow(chat.Chat): model = widget.get_model() iter = model.get_iter(path) if len(path) == 2: - nick = model[iter][1] + nick = model[iter][1].decode('utf-8') fjid = gajim.construct_fjid(room_jid, nick) if not self.plugin.windows[self.account]['chats'].has_key(fjid): show = gajim.gc_contacts[self.account][room_jid][nick].show @@ -1184,7 +1180,7 @@ class GroupchatWindow(chat.Chat): model = widget.get_model() iter = model.get_iter(path) - nick = model[iter][1] + nick = model[iter][1].decode('utf-8') if not nick in gajim.gc_contacts[self.account][room_jid]: #it's a group if x < 20: # first cell in 1st column (the arrow SINGLE clicked) if (widget.row_expanded(path)): @@ -1207,7 +1203,7 @@ class GroupchatWindow(chat.Chat): widget.expand_row(path, False) else: # We want to send a private message room_jid = self.get_active_jid() - nick = model[iter][1] + nick = model[iter][1].decode('utf-8') fjid = gajim.construct_fjid(room_jid, nick) if not self.plugin.windows[self.account]['chats'].has_key(fjid): show = gajim.gc_contacts[self.account][room_jid][nick].show diff --git a/src/gtkgui_helpers.py b/src/gtkgui_helpers.py index f3b177b72..35e820b71 100644 --- a/src/gtkgui_helpers.py +++ b/src/gtkgui_helpers.py @@ -86,8 +86,7 @@ def reduce_chars_newlines(text, max_chars = 0, max_lines = 0, If any of the params is not present(None or 0) the action on it is not performed ''' - # make sure that we have only unicode text - text = text.decode('utf-8') + text = text def _cut_if_long(str): if len(str) > max_chars: diff --git a/src/roster_window.py b/src/roster_window.py index 4d5a2de59..f75c2a5b0 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -57,7 +57,7 @@ class RosterWindow: return account = model.get_iter_root() while account: - account_name = model.get_value(account, 3) + account_name = model.get_value(account, 3).decode('utf-8') if name == account_name: break account = model.iter_next(account) @@ -68,7 +68,7 @@ class RosterWindow: root = self.get_account_iter(account) group = model.iter_children(root) while group: - group_name = model.get_value(group, 3) + group_name = model.get_value(group, 3).decode('utf-8') if name == group_name: break group = model.iter_next(group) @@ -83,7 +83,7 @@ class RosterWindow: while group: user = model.iter_children(group) while user: - if jid == model.get_value(user, 3): + if jid == model.get_value(user, 3).decode('utf-8'): found.append(user) user = model.iter_next(user) group = model.iter_next(group) @@ -157,8 +157,7 @@ class RosterWindow: typestr, user.jid, account, False, None]) # FIXME None --> avatar if gajim.groups[account][g]['expand']: - self.tree.expand_row(model.get_path(iterG), - False) + self.tree.expand_row(model.get_path(iterG), False) self.draw_contact(jid, account) def really_remove_contact(self, user, account): @@ -180,7 +179,7 @@ class RosterWindow: model = self.tree.get_model() for i in self.get_contact_iter(user.jid, account): parent_i = model.iter_parent(i) - group = model.get_value(parent_i, 3) + group = model.get_value(parent_i, 3).decode('utf-8') model.remove(i) if model.iter_n_children(parent_i) == 0: model.remove(parent_i) @@ -235,7 +234,7 @@ class RosterWindow: contact = gajim.get_highest_prio_contact_from_contacts(contact_instances) name = contact.name if len(contact_instances) > 1: - name += ' (' + str(len(contact_instances)) + ')' + name += ' (' + unicode(len(contact_instances)) + ')' state_images = self.get_appropriate_state_images(jid) if gajim.awaiting_messages[account].has_key(jid): @@ -676,8 +675,8 @@ class RosterWindow: self.tooltip.hide_tooltip() return if model[iter][2] == 'contact': - account = model[iter][4] - jid = model[iter][3] + account = model[iter][4].decode('utf-8') + jid = model[iter][3].decode('utf-8') img = model[iter][0] if self.tooltip.timeout == 0 or self.tooltip.id != props[0]: self.tooltip.id = row @@ -721,8 +720,8 @@ class RosterWindow: model = self.tree.get_model() row_type = model[iter][2] - jid = model[iter][3] - account = model[iter][4] + jid = model[iter][3].decode('utf-8') + account = model[iter][4].decode('utf-8') if row_type == 'contact': # it's jid #Remove resource indicator (Name (2)) @@ -789,9 +788,9 @@ class RosterWindow: def mk_menu_user(self, event, iter): '''Make contact's popup menu''' model = self.tree.get_model() - jid = model[iter][3] + jid = model[iter][3].decode('utf-8') path = model.get_path(iter) - account = model[iter][4] + account = model[iter][4].decode('utf-8') contact = gajim.contacts[account][jid][0] xml = gtk.glade.XML(GTKGUI_GLADE, 'roster_contact_context_menu', @@ -891,9 +890,9 @@ class RosterWindow: def mk_menu_agent(self, event, iter): '''Make agent's popup menu''' model = self.tree.get_model() - jid = model[iter][3] + jid = model[iter][3].decode('utf-8') path = model.get_path(iter) - account = model[iter][4] + account = model[iter][4].decode('utf-8') user = gajim.contacts[account][jid][0] menu = gtk.Menu() @@ -955,7 +954,7 @@ class RosterWindow: def mk_menu_account(self, event, iter): '''Make account's popup menu''' model = self.tree.get_model() - account = model[iter][3] + account = model[iter][3].decode('utf-8') #FIXME: make most menuitems of this menu insensitive if account is offline @@ -1083,8 +1082,8 @@ _('If "%s" accepts this request you will know his status.') %jid) model, iter = treeselection.get_selected() if not iter: return - jid = model[iter][3] - account = model[iter][4] + jid = model[iter][3].decode('utf-8') + account = model[iter][4].decode('utf-8') type = model[iter][2] user = gajim.contacts[account][jid][0] if type == 'contact': @@ -1146,8 +1145,8 @@ _('If "%s" accepts this request you will know his status.') %jid) iter = model.get_iter(path) type = model[iter][2] if type in ('agent', 'contact'): - account = model[iter][4] - jid = model[iter][3] + account = model[iter][4].decode('utf-8') + jid = model[iter][3].decode('utf-8') if self.plugin.windows[account]['chats'].has_key(jid): self.plugin.windows[account]['chats'][jid].set_active_tab(jid) elif gajim.contacts[account].has_key(jid): @@ -1296,7 +1295,7 @@ _('If "%s" accepts this request you will know his status.') %jid) ).get_response() self.update_status_comboxbox() return - status = model[active][2] + status = model[active][2].decode('utf-8') message = self.get_status_message(status) if message == -1: self.update_status_comboxbox() @@ -1615,9 +1614,9 @@ _('If "%s" accepts this request you will know his status.') %jid) '''When an iter is double clicked: open the chat window''' model = self.tree.get_model() iter = model.get_iter(path) - account = model[iter][4] + account = model[iter][4].decode('utf-8') type = model[iter][2] - jid = model[iter][3] + jid = model[iter][3].decode('utf-8') if type in ('group', 'account'): if self.tree.row_expanded(path): self.tree.collapse_row(path) @@ -1638,11 +1637,11 @@ _('If "%s" accepts this request you will know his status.') %jid) if gajim.config.get('mergeaccounts') or len(gajim.connections) == 1: accounts = gajim.connections.keys() else: - accounts = [model[iter][4]] + accounts = [model[iter][4].decode('utf-8')] type = model[iter][2] if type == 'group': model.set_value(iter, 0, self.jabber_state_images['opened']) - jid = model[iter][3] + jid = model[iter][3].decode('utf-8') for account in accounts: if gajim.groups[account].has_key(jid): # This account has this group gajim.groups[account][jid]['expand'] = True @@ -1665,11 +1664,11 @@ _('If "%s" accepts this request you will know his status.') %jid) if gajim.config.get('mergeaccounts') or len(gajim.connections) == 1: accounts = gajim.connections.keys() else: - accounts = [model[iter][4]] + accounts = [model[iter][4].decode('utf-8')] type = model[iter][2] if type == 'group': model.set_value(iter, 0, self.jabber_state_images['closed']) - jid = model[iter][3] + jid = model[iter][3].decode('utf-8') for account in accounts: if gajim.groups[account].has_key(jid): # This account has this group gajim.groups[account][jid]['expand'] = False @@ -1695,8 +1694,8 @@ _('If "%s" accepts this request you will know his status.') %jid) self.editing_path = None model = self.tree.get_model() iter = model.get_iter(path) - account = model[iter][4] - jid = model[iter][3] + account = model[iter][4].decode('utf-8') + jid = model[iter][3].decode('utf-8') type = model[iter][2] # restore the number of resources string at the end of contact name if type == 'contact' and len(gajim.contacts[account][jid]) > 1: @@ -1720,8 +1719,8 @@ _('If "%s" accepts this request you will know his status.') %jid) self.editing_path = None return self.editing_path = None - account = model[iter][4] - jid = model[iter][3] + account = model[iter][4].decode('utf-8') + jid = model[iter][3].decode('utf-8') type = model[iter][2] if type == 'contact': old_text = gajim.contacts[account][jid][0].name @@ -1731,7 +1730,7 @@ _('If "%s" accepts this request you will know his status.') %jid) gajim.connections[account].update_contact(jid, new_text, u.groups) self.draw_contact(jid, account) elif type == 'group': - old_name = model[iter][1] + old_name = model[iter][1].decode('utf-8') # Groups maynot change name from or to 'not in the roster' if _('not in the roster') in (new_text, old_name): return @@ -1838,8 +1837,8 @@ _('If "%s" accepts this request you will know his status.') %jid) gajim.config.get_per('themes', theme, 'groupbgcolor')) renderer.set_property('xalign', 0.5) else: - jid = model[iter][3] - account = model[iter][4] + jid = model[iter][3].decode('utf-8') + account = model[iter][4].decode('utf-8') if jid in gajim.newly_added[account]: renderer.set_property('cell-background', '#adc3c6') elif jid in gajim.to_be_removed[account]: @@ -1871,8 +1870,8 @@ _('If "%s" accepts this request you will know his status.') %jid) gajim.config.get_per('themes', theme, 'groupfont')) renderer.set_property('xpad', 4) else: - jid = model[iter][3] - account = model[iter][4] + jid = model[iter][3].decode('utf-8') + account = model[iter][4].decode('utf-8') renderer.set_property('foreground', gajim.config.get_per('themes', theme, 'contacttextcolor')) if jid in gajim.newly_added[account]: @@ -1896,8 +1895,8 @@ _('If "%s" accepts this request you will know his status.') %jid) renderer.set_property('cell-background', gajim.config.get_per('themes', theme, 'groupbgcolor')) else: - jid = model[iter][3] - account = model[iter][4] + jid = model[iter][3].decode('utf-8') + account = model[iter][4].decode('utf-8') if jid in gajim.newly_added[account]: renderer.set_property('cell-background', '#adc3c6') elif jid in gajim.to_be_removed[account]: @@ -1923,6 +1922,9 @@ _('If "%s" accepts this request you will know his status.') %jid) name2 = model.get_value(iter2, 1) if not name1 or not name2: return 0 + else: + name1 = name1.decode('utf-8') + name2 = name2.decode('utf-8') type1 = model.get_value(iter1, 2) type2 = model.get_value(iter2, 2) if type1 == 'group': @@ -1938,8 +1940,9 @@ _('If "%s" accepts this request you will know his status.') %jid) gajim.config.get('sort_by_show'): account = model.get_value(iter1, 4) if account and model.get_value(iter2, 4) == account: - jid1 = model.get_value(iter1, 3) - jid2 = model.get_value(iter2, 3) + account = account.decode('utf-8') + jid1 = model.get_value(iter1, 3).decode('utf-8') + jid2 = model.get_value(iter2, 3).decode('utf-8') luser1 = gajim.contacts[account][jid1] luser2 = gajim.contacts[account][jid2] cshow = {'online':0, 'chat': 1, 'away': 2, 'xa': 3, 'dnd': 4, @@ -2004,15 +2007,16 @@ _('If "%s" accepts this request you will know his status.') %jid) #droped in another account return iter_group_source = model.iter_parent(iter_source) - grp_source = model.get_value(iter_group_source, 3) + grp_source = model.get_value(iter_group_source, 3).decode('utf-8') if grp_source == _('Transports') or grp_source == _('not in the roster'): return - account = model.get_value(iter_dest, 4) + account = model.get_value(iter_dest, 4).decode('utf-8') type_dest = model.get_value(iter_dest, 2) if type_dest == 'group': - grp_dest = model.get_value(iter_dest, 3) + grp_dest = model.get_value(iter_dest, 3).decode('utf-8') else: - grp_dest = model.get_value(model.iter_parent(iter_dest), 3) + grp_dest = model.get_value(model.iter_parent(iter_dest), 3).\ + decode('utf-8') if grp_source == grp_dest: return # We upgrade only the first user because user2.groups is a pointer to @@ -2042,7 +2046,7 @@ _('If "%s" accepts this request you will know his status.') %jid) if change_title_allowed: start = '' if self.nb_unread > 1: - start = '[' + str(self.nb_unread) + '] ' + start = '[' + unicode(self.nb_unread) + '] ' elif self.nb_unread == 1: start = '* ' self.window.set_title(start + 'Gajim') diff --git a/src/tabbed_chat_window.py b/src/tabbed_chat_window.py index cfd54cc62..08d3c38b1 100644 --- a/src/tabbed_chat_window.py +++ b/src/tabbed_chat_window.py @@ -329,7 +329,7 @@ timestamp, contact): message_buffer = message_textview.get_buffer() start_iter = message_buffer.get_start_iter() end_iter = message_buffer.get_end_iter() - message = message_buffer.get_text(start_iter, end_iter, 0) + message = message_buffer.get_text(start_iter, end_iter, 0).decode('utf-8') # send the message self.send_message(message) @@ -478,7 +478,7 @@ timestamp, contact): conversation_textview = widget message_buffer = conversation_textview.get_buffer() start_iter, end_iter = message_buffer.get_bounds() - message = message_buffer.get_text(start_iter, end_iter, False) + message = message_buffer.get_text(start_iter, end_iter, False).decode('utf-8') if event.keyval == gtk.keysyms.ISO_Left_Tab: # SHIFT + TAB if event.state & gtk.gdk.CONTROL_MASK: # CTRL + SHIFT + TAB diff --git a/src/tooltips.py b/src/tooltips.py index 92c81e725..f03b3f786 100644 --- a/src/tooltips.py +++ b/src/tooltips.py @@ -134,7 +134,7 @@ class StatusTable: self.table.attach(self.text_lable, 1, 4, 1, 2) def get_status_info(self, resource, priority, show, status): - str_status = resource + ' (' + str(priority) + ')' + str_status = resource + ' (' + unicode(priority) + ')' if status: status = status.strip() if status != '': @@ -359,7 +359,7 @@ class RosterTooltip(BaseTooltip, StatusTable): if contact.resource: info += '\n' + _('Resource: ') + \ '' + gtkgui_helpers.escape_for_pango_markup( - contact.resource) + ' (' + str(contact.priority) + ')' + contact.resource) + ' (' + unicode(contact.priority) + ')' if contact.show: info += '\n' + _('Status: ') + \ '' + helpers.get_uf_show(contact.show) @@ -402,7 +402,7 @@ class FileTransfersTooltip(BaseTooltip): text += _('Upload') if file_props['type'] == 'r': text += '\n' + _('Sender: ') + '' - sender = str(file_props['sender']).split('/')[0] + sender = unicode(file_props['sender']).split('/')[0] name = gajim.get_first_contact_instance_from_jid( file_props['tt_account'], sender).name else: diff --git a/src/vcard.py b/src/vcard.py index 276e2769b..c833907a4 100644 --- a/src/vcard.py +++ b/src/vcard.py @@ -84,7 +84,7 @@ class VcardWindow: return #update contact.name if it's not '' name_entry = self.xml.get_widget('nickname_entry') - new_name = name_entry.get_text() + new_name = name_entry.get_text().decode('utf-8') if new_name != self.contact.name and new_name != '': self.contact.name = new_name for i in self.plugin.roster.get_contact_iter(self.contact.jid, self.account): @@ -268,10 +268,10 @@ class VcardWindow: 'no_log_for').split(' '): log = 0 self.xml.get_widget('log_checkbutton').set_active(log) - resources = '%s (%s)' % (self.contact.resource, str( + resources = '%s (%s)' % (self.contact.resource, unicode( self.contact.priority)) uf_resources = self.contact.resource + _(' resource with priority ')\ - + str(self.contact.priority) + + unicode(self.contact.priority) if not self.contact.status: self.contact.status = '' @@ -287,9 +287,10 @@ class VcardWindow: if gajim.contacts[self.account].has_key(self.contact.jid): for c in gajim.contacts[self.account][self.contact.jid]: if c.resource != self.contact.resource: - resources += '\n%s (%s)' % (c.resource, str(c.priority)) + resources += '\n%s (%s)' % (c.resource, + unicode(c.priority)) uf_resources += '\n' + c.resource + _(' resource with priority ')\ - + str(c.priority) + + unicode(c.priority) if not c.status: c.status = '' stats += '\n' + c.show + ': ' + c.status @@ -352,7 +353,7 @@ class VcardWindow: 'ADR_WORK_REGION', 'ADR_WORK_PCODE', 'ADR_WORK_CTRY'] vcard = {} for e in entries: - txt = self.xml.get_widget(e + '_entry').get_text() + txt = self.xml.get_widget(e + '_entry').get_text().decode('utf-8') if txt != '': vcard = self.add_to_vcard(vcard, e, txt) @@ -362,7 +363,7 @@ class VcardWindow: end_iter = buff.get_end_iter() txt = buff.get_text(start_iter, end_iter, 0) if txt != '': - vcard['DESC'] = txt + vcard['DESC'] = txt.decode('utf-8') # Avatar if self.avatar_encoded: