From 3fdefe20b786e4bbec6dfa64f976cde79970baa6 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Wed, 2 Jan 2013 18:17:51 +0100 Subject: [PATCH] xrange() -> list(range()) --- src/chat_control.py | 2 +- src/command_system/implementation/execute.py | 2 +- src/common/contacts.py | 4 +++- src/common/socks5.py | 2 +- src/config.py | 10 +++++----- src/dataforms_widget.py | 5 ++--- src/gtkgui_helpers.py | 4 ++-- src/message_window.py | 6 +++--- src/plugins/gui.py | 2 +- src/roster_window.py | 2 +- 10 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/chat_control.py b/src/chat_control.py index 61738933d..8484c9e62 100644 --- a/src/chat_control.py +++ b/src/chat_control.py @@ -916,7 +916,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): scroll = False if pos == size else True # are we scrolling? # we don't want size of the buffer to grow indefinately max_size = gajim.config.get('key_up_lines') - for i in xrange(size - max_size + 1): + for i in range(size - max_size + 1): if pos == 0: break history.pop(0) diff --git a/src/command_system/implementation/execute.py b/src/command_system/implementation/execute.py index 688347a1f..26fda9e81 100644 --- a/src/command_system/implementation/execute.py +++ b/src/command_system/implementation/execute.py @@ -68,7 +68,7 @@ class Execute(CommandContainer): @classmethod def poller(cls, processor, popen): - for x in xrange(cls.POLL_COUNT): + for x in list(range(cls.POLL_COUNT)): yield cls.brush(processor, popen) cls.overdue(processor, popen) yield False diff --git a/src/common/contacts.py b/src/common/contacts.py index 1d6f891b6..3d411bf24 100644 --- a/src/common/contacts.py +++ b/src/common/contacts.py @@ -28,6 +28,8 @@ ## along with Gajim. If not, see . ## +from functools import cmp_to_key + try: from common import caps_cache from common.account import Account @@ -848,7 +850,7 @@ class MetacontactManager(): Which of the family will be the big brother under wich all others will be ? """ - family.sort(cmp=self._compare_metacontacts) + family.sort(key=cmp_to_key(self._compare_metacontacts)) return family[-1] diff --git a/src/common/socks5.py b/src/common/socks5.py index 725ac73a1..c57be17a5 100644 --- a/src/common/socks5.py +++ b/src/common/socks5.py @@ -781,7 +781,7 @@ class Socks5: auth_mechanisms = [] try: num_auth = struct.unpack('!xB', buff[:2])[0] - for i in xrange(num_auth): + for i in list(range(num_auth)): mechanism, = struct.unpack('!B', buff[1 + i]) auth_mechanisms.append(mechanism) except Exception: diff --git a/src/config.py b/src/config.py index b5cbff3a8..597c74876 100644 --- a/src/config.py +++ b/src/config.py @@ -173,7 +173,7 @@ class PreferencesWindow: if dir_ != '.svn': l.append(dir_) l.append(_('Disabled')) - for i in xrange(len(l)): + for i in range(len(l)): model.append([l[i]]) if gajim.config.get('emoticons_theme') == l[i]: emoticons_combobox.set_active(i) @@ -243,7 +243,7 @@ class PreferencesWindow: l.append(dir) if l.count == 0: l.append(' ') - for i in xrange(len(l)): + for i in range(len(l)): preview = Gtk.Image() files = [] files.append(os.path.join(helpers.get_iconset_path(l[i]), '16x16', @@ -1279,7 +1279,7 @@ class PreferencesWindow: model.clear() l = gajim.config.get_per('proxies') l.insert(0, _('None')) - for i in xrange(len(l)): + for i in range(len(l)): model.append([l[i]]) if our_proxy == l[i]: proxy_combobox.set_active(i) @@ -1766,7 +1766,7 @@ class AccountsWindow: proxy_combobox.set_model(model) l = gajim.config.get_per('proxies') l.insert(0, _('None')) - for i in xrange(len(l)): + for i in range(len(l)): model.append([l[i]]) if our_proxy == l[i]: proxy_combobox.set_active(i) @@ -3757,7 +3757,7 @@ class AccountCreationWizardWindow: proxies_combobox.set_model(model) l = gajim.config.get_per('proxies') l.insert(0, _('None')) - for i in xrange(len(l)): + for i in range(len(l)): model.append([l[i]]) proxies_combobox.set_active(0) diff --git a/src/dataforms_widget.py b/src/dataforms_widget.py index 7e2b8198b..bd30db5d5 100644 --- a/src/dataforms_widget.py +++ b/src/dataforms_widget.py @@ -277,7 +277,7 @@ class DataFormWidget(Gtk.Alignment, object): selection = self.records_treeview.get_selection() model, rowrefs = selection.get_selected_rows() # rowref is a list of paths - for i in xrange(len(rowrefs)): + for i in list(range(len(rowrefs))): rowrefs[i] = Gtk.TreeRowReference(model, rowrefs[i]) # rowref is a list of row references; need to convert because we will # modify the model, paths would change @@ -566,8 +566,7 @@ class SingleForm(Gtk.Table, object): for uri in field.media.uris: if uri.type_.startswith('image/'): try: - img_data = base64.b64decode(uri.uri_data.encode( - 'utf-8')).decode('utf-8') + img_data = base64.decodestring(uri.uri_data) pixbuf_l = GdkPixbuf.PixbufLoader() pixbuf_l.write(img_data) pixbuf_l.close() diff --git a/src/gtkgui_helpers.py b/src/gtkgui_helpers.py index 7fdb46a78..a25fe3f14 100644 --- a/src/gtkgui_helpers.py +++ b/src/gtkgui_helpers.py @@ -317,7 +317,7 @@ class HashDigest: def __str__(self): prettydigest = '' - for i in xrange(0, len(self.digest), 2): + for i in list(range(0, len(self.digest), 2)): prettydigest += self.digest[i:i + 2] + ':' return prettydigest[:-1] @@ -1102,7 +1102,7 @@ def label_set_autowrap(widget): """ if isinstance (widget, Gtk.Container): children = widget.get_children() - for i in xrange (len (children)): + for i in list(range (len (children))): label_set_autowrap(children[i]) elif isinstance(widget, Gtk.Label): widget.set_line_wrap(True) diff --git a/src/message_window.py b/src/message_window.py index e2912fe56..13b4ed7d3 100644 --- a/src/message_window.py +++ b/src/message_window.py @@ -106,7 +106,7 @@ class MessageWindow(object): 'b', 'F4', 'w', 'Page_Up', 'Page_Down', 'Right', 'Left', 'd', 'c', 'm', 't', 'Escape'] + \ - [''+str(i) for i in xrange(10)] + [''+str(i) for i in list(range(10))] accel_group = Gtk.AccelGroup() for key in keys: keyval, mod = Gtk.accelerator_parse(key) @@ -856,7 +856,7 @@ class MessageWindow(object): to_right = False horiz = self.notebook.get_tab_pos() == Gtk.PositionType.TOP or \ self.notebook.get_tab_pos() == Gtk.PositionType.BOTTOM - for i in xrange(self.notebook.get_n_pages()): + for i in list(range(self.notebook.get_n_pages())): page = self.notebook.get_nth_page(i) tab = self.notebook.get_tab_label(page) tab_alloc = tab.get_allocation() @@ -882,7 +882,7 @@ class MessageWindow(object): Find the page num of the tab label """ page_num = -1 - for i in xrange(self.notebook.get_n_pages()): + for i in list(range(self.notebook.get_n_pages())): page = self.notebook.get_nth_page(i) tab = self.notebook.get_tab_label(page) if tab == tab_label: diff --git a/src/plugins/gui.py b/src/plugins/gui.py index ca4a63da0..142121839 100644 --- a/src/plugins/gui.py +++ b/src/plugins/gui.py @@ -264,7 +264,7 @@ class PluginsWindow(object): return model = self.installed_plugins_model - for row in xrange(len(model)): + for row in list(range(len(model))): if plugin == model[row][PLUGIN]: model.remove(model.get_iter((row, PLUGIN))) break diff --git a/src/roster_window.py b/src/roster_window.py index fd6c6f462..87e39b10b 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -3225,7 +3225,7 @@ class RosterWindow: 'attached_gpg_keys').split() keys = {} keyID = _('None') - for i in xrange(len(attached_keys)/2): + for i in list(range(len(attached_keys)/2)): keys[attached_keys[2*i]] = attached_keys[2*i+1] if attached_keys[2*i] == contact.jid: keyID = attached_keys[2*i+1]