From 7ad8a3cbb5d04797a3a121abb59943c17478286b Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Sun, 16 Oct 2016 18:48:48 -0700 Subject: [PATCH] [Py2to3] Replace iteritems and itervalues * Replace the use of iteritems() and itervalues() on dictionary objects with items() and values() respectively for Python 3 compatibility. --- deluge/config.py | 4 ++-- deluge/core/authmanager.py | 2 +- deluge/core/filtermanager.py | 4 ++-- deluge/core/torrent.py | 4 ++-- deluge/core/torrentmanager.py | 4 ++-- .../plugins/AutoAdd/deluge/plugins/autoadd/core.py | 14 +++++++------- .../AutoAdd/deluge/plugins/autoadd/gtkui.py | 6 +++--- .../plugins/Execute/deluge/plugins/execute/core.py | 2 +- deluge/plugins/Label/deluge/plugins/label/core.py | 8 ++++---- deluge/plugins/Stats/deluge/plugins/stats/core.py | 4 ++-- deluge/plugins/Stats/deluge/plugins/stats/graph.py | 2 +- .../Stats/deluge/plugins/stats/tests/test_stats.py | 2 +- deluge/ui/gtkui/addtorrentdialog.py | 2 +- deluge/ui/gtkui/files_tab.py | 2 +- deluge/ui/gtkui/filtertreeview.py | 2 +- deluge/ui/gtkui/listview.py | 2 +- deluge/ui/gtkui/mainwindow.py | 2 +- deluge/ui/gtkui/menubar.py | 4 ++-- deluge/ui/gtkui/preferences.py | 2 +- deluge/ui/gtkui/torrentdetails.py | 6 +++--- deluge/ui/sessionproxy.py | 2 +- 21 files changed, 40 insertions(+), 40 deletions(-) diff --git a/deluge/config.py b/deluge/config.py index 9fe700159..6133e2f5c 100644 --- a/deluge/config.py +++ b/deluge/config.py @@ -125,7 +125,7 @@ class Config(object): self._save_timer = None if defaults: - for key, value in defaults.iteritems(): + for key, value in defaults.items(): self.set_item(key, value) # Load the config from file in the config_dir @@ -363,7 +363,7 @@ what is currently in the config and it could not convert the value """ log.debug("Calling all set functions..") - for key, value in self.__set_functions.iteritems(): + for key, value in self.__set_functions.items(): for func in value: func(key, self.__config[key]) diff --git a/deluge/core/authmanager.py b/deluge/core/authmanager.py index ee94f003e..105a0905e 100644 --- a/deluge/core/authmanager.py +++ b/deluge/core/authmanager.py @@ -29,7 +29,7 @@ AUTH_LEVELS_MAPPING = { } AUTH_LEVELS_MAPPING_REVERSE = {} -for key, value in AUTH_LEVELS_MAPPING.iteritems(): +for key, value in AUTH_LEVELS_MAPPING.items(): AUTH_LEVELS_MAPPING_REVERSE[value] = key diff --git a/deluge/core/filtermanager.py b/deluge/core/filtermanager.py index cce367826..babf7d5ad 100644 --- a/deluge/core/filtermanager.py +++ b/deluge/core/filtermanager.py @@ -173,7 +173,7 @@ class FilterManager(component.Component): # Leftover filter arguments, default filter on status fields. for torrent_id in list(torrent_ids): status = self.core.create_torrent_status(torrent_id, torrent_keys, plugin_keys) - for field, values in filter_dict.iteritems(): + for field, values in filter_dict.items(): if field in status and status[field] in values: continue elif torrent_id in torrent_ids: @@ -212,7 +212,7 @@ class FilterManager(component.Component): # Return a dict of tuples: sorted_items = {} for field in tree_keys: - sorted_items[field] = sorted(items[field].iteritems()) + sorted_items[field] = sorted(items[field].items()) if "state" in tree_keys: sorted_items["state"].sort(self._sort_state_items) diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py index 277349337..c452e38cd 100644 --- a/deluge/core/torrent.py +++ b/deluge/core/torrent.py @@ -160,7 +160,7 @@ class TorrentOptions(dict): "super_seeding": "super_seeding", "priority": "priority", } - for opt_k, conf_k in options_conf_map.iteritems(): + for opt_k, conf_k in options_conf_map.items(): self[opt_k] = config[conf_k] self["file_priorities"] = [] self["mapped_files"] = {} @@ -1323,7 +1323,7 @@ class Torrent(object): torrent.waiting_on_folder_rename = [_dir for _dir in torrent.waiting_on_folder_rename if _dir] component.get("TorrentManager").save_resume_data((self.torrent_id,)) - d = DeferredList(wait_on_folder.values()) + d = DeferredList(list(wait_on_folder.values())) d.addBoth(on_folder_rename_complete, self, folder, new_folder) return d diff --git a/deluge/core/torrentmanager.py b/deluge/core/torrentmanager.py index ffe388aa5..dac17b48b 100644 --- a/deluge/core/torrentmanager.py +++ b/deluge/core/torrentmanager.py @@ -746,7 +746,7 @@ class TorrentManager(component.Component): """ if torrent_ids is None: - torrent_ids = (t[0] for t in self.torrents.iteritems() if t[1].handle.need_save_resume_data()) + torrent_ids = (t[0] for t in self.torrents.items() if t[1].handle.need_save_resume_data()) def on_torrent_resume_save(dummy_result, torrent_id): """Recieved torrent resume_data alert so remove from waiting list""" @@ -918,7 +918,7 @@ class TorrentManager(component.Component): def cleanup_torrents_prev_status(self): """Run cleanup_prev_status for each registered torrent""" - for torrent in self.torrents.iteritems(): + for torrent in self.torrents.items(): torrent[1].cleanup_prev_status() def on_set_max_connections_per_torrent(self, key, value): diff --git a/deluge/plugins/AutoAdd/deluge/plugins/autoadd/core.py b/deluge/plugins/AutoAdd/deluge/plugins/autoadd/core.py index 9487024f9..ba9398f6c 100644 --- a/deluge/plugins/AutoAdd/deluge/plugins/autoadd/core.py +++ b/deluge/plugins/AutoAdd/deluge/plugins/autoadd/core.py @@ -99,7 +99,7 @@ class Core(CorePluginBase): def enable_looping(self): # Enable all looping calls for enabled watchdirs here - for watchdir_id, watchdir in self.watchdirs.iteritems(): + for watchdir_id, watchdir in self.watchdirs.items(): if watchdir["enabled"]: self.enable_watchdir(watchdir_id) @@ -108,7 +108,7 @@ class Core(CorePluginBase): component.get("EventManager").deregister_event_handler( "PreTorrentRemovedEvent", self.__on_pre_torrent_removed ) - for loopingcall in self.update_timers.itervalues(): + for loopingcall in self.update_timers.values(): loopingcall.stop() self.config.save() @@ -128,7 +128,7 @@ class Core(CorePluginBase): check_input( os.path.isdir(options["abspath"]), _("Path does not exist.") ) - for w_id, w in self.watchdirs.iteritems(): + for w_id, w in self.watchdirs.items(): if options["abspath"] == w["abspath"] and watchdir_id != w_id: raise Exception("Path is already being watched.") for key in options: @@ -223,7 +223,7 @@ class Core(CorePluginBase): watchdir["stop_ratio_toggle"] = watchdir["stop_at_ratio_toggle"] # We default to True when reading _toggle values, so a config # without them is valid, and applies all its settings. - for option, value in watchdir.iteritems(): + for option, value in watchdir.items(): if OPTIONS_AVAILABLE.get(option): if watchdir.get(option + "_toggle", True) or option in ["owner", "seed_mode"]: opts[option] = value @@ -381,7 +381,7 @@ class Core(CorePluginBase): return self.watchdirs watchdirs = {} - for watchdir_id, watchdir in self.watchdirs.iteritems(): + for watchdir_id, watchdir in self.watchdirs.items(): if watchdir.get("owner", "localclient") == session_user: watchdirs[watchdir_id] = watchdir @@ -409,7 +409,7 @@ class Core(CorePluginBase): os.access(abswatchdir, os.R_OK | os.W_OK), "You must have read and write access to watch folder." ) - if abswatchdir in [wd["abspath"] for wd in self.watchdirs.itervalues()]: + if abswatchdir in [wd["abspath"] for wd in self.watchdirs.values()]: raise Exception("Path is already being watched.") options.setdefault("enabled", False) options["abspath"] = abswatchdir @@ -447,7 +447,7 @@ class Core(CorePluginBase): torrent_id) return torrent_fname = torrent.filename - for watchdir in self.watchdirs.itervalues(): + for watchdir in self.watchdirs.values(): if not watchdir.get("copy_torrent_toggle", False): # This watchlist does copy torrents continue diff --git a/deluge/plugins/AutoAdd/deluge/plugins/autoadd/gtkui.py b/deluge/plugins/AutoAdd/deluge/plugins/autoadd/gtkui.py index 9a569ed73..a4f6dc226 100644 --- a/deluge/plugins/AutoAdd/deluge/plugins/autoadd/gtkui.py +++ b/deluge/plugins/AutoAdd/deluge/plugins/autoadd/gtkui.py @@ -401,7 +401,7 @@ class GtkUI(GtkPluginBase): def create_model(self): store = gtk.ListStore(str, bool, str, str) - for watchdir_id, watchdir in self.watchdirs.iteritems(): + for watchdir_id, watchdir in self.watchdirs.items(): store.append([ watchdir_id, watchdir['enabled'], watchdir.get('owner', 'localclient'), watchdir['path'] @@ -474,7 +474,7 @@ class GtkUI(GtkPluginBase): def on_apply_prefs(self): log.debug("applying prefs for AutoAdd") - for watchdir_id, watchdir in self.watchdirs.iteritems(): + for watchdir_id, watchdir in self.watchdirs.items(): client.autoadd.set_options(watchdir_id, watchdir) def on_show_prefs(self): @@ -488,7 +488,7 @@ class GtkUI(GtkPluginBase): log.trace("Got whatchdirs from core: %s", watchdirs) self.watchdirs = watchdirs or {} self.store.clear() - for watchdir_id, watchdir in self.watchdirs.iteritems(): + for watchdir_id, watchdir in self.watchdirs.items(): self.store.append([ watchdir_id, watchdir['enabled'], watchdir.get('owner', 'localclient'), watchdir['path'] diff --git a/deluge/plugins/Execute/deluge/plugins/execute/core.py b/deluge/plugins/Execute/deluge/plugins/execute/core.py index 6fc257138..d91f91770 100644 --- a/deluge/plugins/Execute/deluge/plugins/execute/core.py +++ b/deluge/plugins/Execute/deluge/plugins/execute/core.py @@ -133,7 +133,7 @@ class Core(CorePluginBase): def disable(self): self.config.save() event_manager = component.get("EventManager") - for event, handler in self.registered_events.iteritems(): + for event, handler in self.registered_events.items(): event_manager.deregister_event_handler(event, handler) log.debug("Execute core plugin disabled!") diff --git a/deluge/plugins/Label/deluge/plugins/label/core.py b/deluge/plugins/Label/deluge/plugins/label/core.py index 5ca933375..bd01b815c 100644 --- a/deluge/plugins/Label/deluge/plugins/label/core.py +++ b/deluge/plugins/Label/deluge/plugins/label/core.py @@ -118,7 +118,7 @@ class Core(CorePluginBase): log.debug("post_torrent_add") torrent = self.torrents[torrent_id] - for label_id, options in self.labels.iteritems(): + for label_id, options in self.labels.items(): if options["auto_add"]: if self._has_auto_match(torrent, options): self.set_torrent(torrent_id, label_id) @@ -132,7 +132,7 @@ class Core(CorePluginBase): # Utils # def clean_config(self): """remove invalid data from config-file""" - for torrent_id, label_id in list(self.torrent_labels.iteritems()): + for torrent_id, label_id in list(self.torrent_labels.items()): if (label_id not in self.labels) or (torrent_id not in self.torrents): log.debug("label: rm %s:%s", torrent_id, label_id) del self.torrent_labels[torrent_id] @@ -266,14 +266,14 @@ class Core(CorePluginBase): self.labels[label_id].update(options_dict) # apply - for torrent_id, label in self.torrent_labels.iteritems(): + for torrent_id, label in self.torrent_labels.items(): if label_id == label and torrent_id in self.torrents: self._set_torrent_options(torrent_id, label_id) # auto add options = self.labels[label_id] if options["auto_add"]: - for torrent_id, torrent in self.torrents.iteritems(): + for torrent_id, torrent in self.torrents.items(): if self._has_auto_match(torrent, options): self.set_torrent(torrent_id, label_id) diff --git a/deluge/plugins/Stats/deluge/plugins/stats/core.py b/deluge/plugins/Stats/deluge/plugins/stats/core.py index 00ff0066a..67de6b4f6 100644 --- a/deluge/plugins/Stats/deluge/plugins/stats/core.py +++ b/deluge/plugins/Stats/deluge/plugins/stats/core.py @@ -136,7 +136,7 @@ class Core(CorePluginBase): # extract the ones we are interested in # adding them to the 1s array - for stat, stat_list in self.stats[1].iteritems(): + for stat, stat_list in self.stats[1].items(): if stat in stats: stat_list.insert(0, int(stats[stat])) else: @@ -150,7 +150,7 @@ class Core(CorePluginBase): self.last_update[interval] = update_time self.count[interval] = 0 current_stats = self.stats[interval] - for stat, stat_list in self.stats[base].iteritems(): + for stat, stat_list in self.stats[base].items(): try: avg = mean(stat_list[0:multiplier]) except ValueError: diff --git a/deluge/plugins/Stats/deluge/plugins/stats/graph.py b/deluge/plugins/Stats/deluge/plugins/stats/graph.py index 7b11a3085..121ffc9fb 100644 --- a/deluge/plugins/Stats/deluge/plugins/stats/graph.py +++ b/deluge/plugins/Stats/deluge/plugins/stats/graph.py @@ -242,7 +242,7 @@ class Graph(object): self.draw_y_text(y_tick_text[i], left, y) self.draw_line(gray, left, top, left, bottom) - for stat, info in stats.iteritems(): + for stat, info in stats.items(): if len(info['values']) > 0: self.draw_value_poly(info['values'], info['color'], max_value, bounds) self.draw_value_poly(info['values'], info['fill_color'], max_value, bounds, info['fill']) diff --git a/deluge/plugins/Stats/deluge/plugins/stats/tests/test_stats.py b/deluge/plugins/Stats/deluge/plugins/stats/tests/test_stats.py index a9ca8dc6a..96cbd049f 100644 --- a/deluge/plugins/Stats/deluge/plugins/stats/tests/test_stats.py +++ b/deluge/plugins/Stats/deluge/plugins/stats/tests/test_stats.py @@ -18,7 +18,7 @@ from deluge.ui.client import client def print_totals(totals): - for name, value in totals.iteritems(): + for name, value in totals.items(): print(name, fsize(value)) print("overhead:") diff --git a/deluge/ui/gtkui/addtorrentdialog.py b/deluge/ui/gtkui/addtorrentdialog.py index 5753c57c5..256f9bc1d 100644 --- a/deluge/ui/gtkui/addtorrentdialog.py +++ b/deluge/ui/gtkui/addtorrentdialog.py @@ -300,7 +300,7 @@ class AddTorrentDialog(component.Component): def add_files(self, parent_iter, split_files): ret = 0 - for key, value in split_files.iteritems(): + for key, value in split_files.items(): if key.endswith(os.path.sep): chunk_iter = self.files_treestore.append( parent_iter, [True, key, 0, -1, False, gtk.STOCK_DIRECTORY]) diff --git a/deluge/ui/gtkui/files_tab.py b/deluge/ui/gtkui/files_tab.py index d373ca954..007a8c429 100644 --- a/deluge/ui/gtkui/files_tab.py +++ b/deluge/ui/gtkui/files_tab.py @@ -362,7 +362,7 @@ class FilesTab(Tab): def add_files(self, parent_iter, split_files): chunk_size_total = 0 - for key, value in split_files.iteritems(): + for key, value in split_files.items(): if key.endswith("/"): chunk_iter = self.treestore.append(parent_iter, [key, 0, "", 0, 0, -1, gtk.STOCK_DIRECTORY]) diff --git a/deluge/ui/gtkui/filtertreeview.py b/deluge/ui/gtkui/filtertreeview.py index c788048ec..500a08b4d 100644 --- a/deluge/ui/gtkui/filtertreeview.py +++ b/deluge/ui/gtkui/filtertreeview.py @@ -159,7 +159,7 @@ class FilterTreeView(component.Component): # update rows visible_filters = [] - for cat, filters in filter_items.iteritems(): + for cat, filters in filter_items.items(): for value, count in filters: self.update_row(cat, value, count) visible_filters.append((cat, value)) diff --git a/deluge/ui/gtkui/listview.py b/deluge/ui/gtkui/listview.py index 004560973..3ff769074 100644 --- a/deluge/ui/gtkui/listview.py +++ b/deluge/ui/gtkui/listview.py @@ -118,7 +118,7 @@ class ListView(object): def set_col_attributes(self, renderer, add=True, **kw): if add is True: - for attr, value in kw.iteritems(): + for attr, value in kw.items(): self.add_attribute(renderer, attr, value) else: self.set_attributes(renderer, **kw) diff --git a/deluge/ui/gtkui/mainwindow.py b/deluge/ui/gtkui/mainwindow.py index cd2e1c137..75508707d 100644 --- a/deluge/ui/gtkui/mainwindow.py +++ b/deluge/ui/gtkui/mainwindow.py @@ -41,7 +41,7 @@ class _GtkBuilderSignalsHolder(object): def connect_signals(self, mapping_or_class): if isinstance(mapping_or_class, dict): - for name, handler in mapping_or_class.iteritems(): + for name, handler in mapping_or_class.items(): if hasattr(self, name): raise RuntimeError( "A handler for signal %r has already been registered: %s" % diff --git a/deluge/ui/gtkui/menubar.py b/deluge/ui/gtkui/menubar.py index c48eebc54..a3280e7ce 100644 --- a/deluge/ui/gtkui/menubar.py +++ b/deluge/ui/gtkui/menubar.py @@ -496,7 +496,7 @@ class MenuBar(component.Component): known_accounts_to_log = [] for account in known_accounts: account_to_log = {} - for key, value in account.copy().iteritems(): + for key, value in account.copy().items(): if key == 'password': value = '*' * len(value) account_to_log[key] = value @@ -539,7 +539,7 @@ class MenuBar(component.Component): return torrent_owner = component.get("TorrentView").get_torrent_status(selected[0])["owner"] - for username, item in self.change_owner_submenu_items.iteritems(): + for username, item in self.change_owner_submenu_items.items(): item.set_active(username == torrent_owner) def _on_change_owner_toggled(self, widget, username): diff --git a/deluge/ui/gtkui/preferences.py b/deluge/ui/gtkui/preferences.py index a09dafbdb..a51c98e96 100644 --- a/deluge/ui/gtkui/preferences.py +++ b/deluge/ui/gtkui/preferences.py @@ -1006,7 +1006,7 @@ class Preferences(component.Component): known_accounts_to_log = [] for account in known_accounts: account_to_log = {} - for key, value in account.copy().iteritems(): + for key, value in account.copy().items(): if key == 'password': value = '*' * len(value) account_to_log[key] = value diff --git a/deluge/ui/gtkui/torrentdetails.py b/deluge/ui/gtkui/torrentdetails.py index 0db1023cb..b71a7e872 100644 --- a/deluge/ui/gtkui/torrentdetails.py +++ b/deluge/ui/gtkui/torrentdetails.py @@ -129,7 +129,7 @@ class TorrentDetails(component.Component): # We need to rename the tab in the state for backwards compat self.state = [(tab_name.replace("Statistics", "Status"), visible) for tab_name, visible in state] - for tab in default_tabs.itervalues(): + for tab in default_tabs.values(): self.add_tab(tab(), generate_menu=False) # Generate the checklist menu @@ -140,7 +140,7 @@ class TorrentDetails(component.Component): # Determine insert position based on weight # weights is a list of visible tab names in weight order - weights = sorted([(tab.weight, name) for name, tab in self.tabs.iteritems() if tab.is_visible]) + weights = sorted([(tab.weight, name) for name, tab in self.tabs.items() if tab.is_visible]) log.debug("weights: %s", weights) log.debug("weight of tab: %s", weight) @@ -243,7 +243,7 @@ class TorrentDetails(component.Component): self.generate_menu() show = False - for name, tab in self.tabs.iteritems(): + for name, tab in self.tabs.items(): show = show or tab.is_visible self.visible(show) diff --git a/deluge/ui/sessionproxy.py b/deluge/ui/sessionproxy.py index d06fba72d..76f0d8c17 100644 --- a/deluge/ui/sessionproxy.py +++ b/deluge/ui/sessionproxy.py @@ -178,7 +178,7 @@ class SessionProxy(component.Component): def on_status(result, torrent_ids, keys): # Update the internal torrent status dict with the update values t = time() - for key, value in result.iteritems(): + for key, value in result.items(): try: self.torrents[key][0] = t self.torrents[key][1].update(value)