Revert "[Py2to3] Clean-up the use of keys() on dictionary objects."

This reverts commit 8b50f3cdbd.
This commit is contained in:
Calum Lind 2016-10-26 19:14:10 +01:00
parent c4282f29ab
commit 3f72905b3f
47 changed files with 97 additions and 95 deletions

View File

@ -298,7 +298,7 @@ class ComponentRegistry(object):
"""
# Start all the components if names is empty
if not names:
names = list(self.components)
names = self.components.keys()
elif isinstance(names, str):
names = [names]
@ -332,7 +332,7 @@ class ComponentRegistry(object):
"""
if not names:
names = list(self.components)
names = self.components.keys()
elif isinstance(names, str):
names = [names]
@ -370,7 +370,7 @@ class ComponentRegistry(object):
"""
if not names:
names = list(self.components)
names = self.components.keys()
elif isinstance(names, str):
names = [names]
@ -396,7 +396,7 @@ class ComponentRegistry(object):
"""
if not names:
names = list(self.components)
names = self.components.keys()
elif isinstance(names, str):
names = [names]
@ -421,7 +421,7 @@ class ComponentRegistry(object):
def on_stopped(result):
return DeferredList([comp._component_shutdown() for comp in self.components.values()])
return self.stop(list(self.components)).addCallback(on_stopped)
return self.stop(self.components.keys()).addCallback(on_stopped)
def update(self):
"""Update all Components that are in a Started state."""

View File

@ -88,7 +88,7 @@ class _ConfigManager(object):
"""Get a reference to the Config object for this filename"""
log.debug("Getting config '%s'", config_file)
# Create the config object if not already created
if config_file not in self.config_files:
if config_file not in self.config_files.keys():
self.config_files[config_file] = Config(config_file, defaults, self.config_directory)
return self.config_files[config_file]

View File

@ -506,7 +506,7 @@ class Core(component.Component):
status_dict, plugin_keys = args
# Ask the plugin manager to fill in the plugin keys
if len(plugin_keys) > 0:
for key in status_dict:
for key in status_dict.keys():
status_dict[key].update(self.pluginmanager.get_status(key, plugin_keys))
return status_dict
d.addCallback(add_plugin_fields)
@ -545,7 +545,7 @@ class Core(component.Component):
def set_config(self, config):
"""Set the config with values from dictionary"""
# Load all the values into the configuration
for key in config:
for key in config.keys():
if self.read_only_config_keys and key in self.read_only_config_keys:
continue
if isinstance(config[key], basestring):

View File

@ -169,7 +169,7 @@ class FilterManager(component.Component):
if not filter_dict:
return torrent_ids
torrent_keys, plugin_keys = self.torrents.separate_keys(list(filter_dict), torrent_ids)
torrent_keys, plugin_keys = self.torrents.separate_keys(filter_dict.keys(), torrent_ids)
# 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)
@ -186,7 +186,7 @@ class FilterManager(component.Component):
for use in sidebar.
"""
torrent_ids = self.torrents.get_torrent_list()
tree_keys = list(self.tree_fields)
tree_keys = list(self.tree_fields.keys())
if hide_cat:
for cat in hide_cat:
tree_keys.remove(cat)

View File

@ -46,7 +46,7 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase, component.Compon
self.stop()
def update_plugins(self):
for plugin in self.plugins:
for plugin in self.plugins.keys():
if hasattr(self.plugins[plugin], "update"):
try:
self.plugins[plugin].update()
@ -82,7 +82,7 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase, component.Compon
"""Return the value of status fields for the selected torrent_id."""
status = {}
if len(fields) == 0:
fields = list(self.status_fields)
fields = self.status_fields.keys()
for field in fields:
try:
status[field] = self.status_fields[field](torrent_id)

View File

@ -429,7 +429,7 @@ class RPCServer(component.Component):
:returns: the exported methods
:rtype: list
"""
return list(self.factory.methods)
return self.factory.methods.keys()
def get_session_id(self):
"""

View File

@ -940,7 +940,7 @@ class Torrent(object):
self.update_status(self.handle.status())
if all_keys:
keys = list(self.status_funcs)
keys = self.status_funcs.keys()
status_dict = {}
@ -1360,7 +1360,7 @@ class Torrent(object):
If the key is no longer valid, the dict will be deleted.
"""
for key in self.prev_status:
for key in self.prev_status.keys():
if not self.rpcserver.is_session_valid(key):
del self.prev_status[key]

View File

@ -266,7 +266,7 @@ class TorrentManager(component.Component):
list: A list of torrent_ids.
"""
torrent_ids = list(self.torrents)
torrent_ids = self.torrents.keys()
if component.get("RPCServer").get_session_auth_level() == AUTH_LEVEL_ADMIN:
return torrent_ids
@ -924,25 +924,25 @@ class TorrentManager(component.Component):
def on_set_max_connections_per_torrent(self, key, value):
"""Sets the per-torrent connection limit"""
log.debug("max_connections_per_torrent set to %s...", value)
for key in self.torrents:
for key in self.torrents.keys():
self.torrents[key].set_max_connections(value)
def on_set_max_upload_slots_per_torrent(self, key, value):
"""Sets the per-torrent upload slot limit"""
log.debug("max_upload_slots_per_torrent set to %s...", value)
for key in self.torrents:
for key in self.torrents.keys():
self.torrents[key].set_max_upload_slots(value)
def on_set_max_upload_speed_per_torrent(self, key, value):
"""Sets the per-torrent upload speed limit"""
log.debug("max_upload_speed_per_torrent set to %s...", value)
for key in self.torrents:
for key in self.torrents.keys():
self.torrents[key].set_max_upload_speed(value)
def on_set_max_download_speed_per_torrent(self, key, value):
"""Sets the per-torrent download speed limit"""
log.debug("max_download_speed_per_torrent set to %s...", value)
for key in self.torrents:
for key in self.torrents.keys():
self.torrents[key].set_max_download_speed(value)
# --- Alert handlers ---
@ -1301,7 +1301,7 @@ class TorrentManager(component.Component):
if self.torrents:
for torrent_id in torrent_ids:
if torrent_id in self.torrents:
status_keys = list(self.torrents[torrent_id].status_funcs)
status_keys = self.torrents[torrent_id].status_funcs.keys()
leftover_keys = list(set(keys) - set(status_keys))
torrent_keys = list(set(keys) - set(leftover_keys))
return torrent_keys, leftover_keys

View File

@ -74,7 +74,7 @@ class PluginManagerBase(object):
def disable_plugins(self):
# Disable all plugins that are enabled
for key in self.plugins:
for key in self.plugins.keys():
self.disable_plugin(key)
def __getitem__(self, key):
@ -86,7 +86,7 @@ class PluginManagerBase(object):
def get_enabled_plugins(self):
"""Returns a list of enabled plugins"""
return list(self.plugins)
return self.plugins.keys()
def scan_for_plugins(self):
"""Scans for available plugins"""
@ -243,14 +243,14 @@ class PluginManagerBase(object):
for line in self.pkg_env[name][0].get_metadata("PKG-INFO").splitlines():
if not line:
continue
if line[0] in ' \t' and (len(line.split(":", 1)) == 1 or line.split(":", 1)[0] not in info):
if line[0] in ' \t' and (len(line.split(":", 1)) == 1 or line.split(":", 1)[0] not in info.keys()):
# This is a continuation
cont_lines.append(line.strip())
else:
if cont_lines:
info[last_header] = "\n".join(cont_lines).strip()
cont_lines = []
if line.split(":", 1)[0] in info:
if line.split(":", 1)[0] in info.keys():
last_header = line.split(":", 1)[0]
info[last_header] = line.split(":", 1)[1].strip()
return info

View File

@ -131,9 +131,9 @@ class Core(CorePluginBase):
for w_id, w in self.watchdirs.iteritems():
if options["abspath"] == w["abspath"] and watchdir_id != w_id:
raise Exception("Path is already being watched.")
for key in options:
for key in options.keys():
if key not in OPTIONS_AVAILABLE:
if key not in [key2 + "_toggle" for key2 in OPTIONS_AVAILABLE]:
if key not in [key2 + "_toggle" for key2 in OPTIONS_AVAILABLE.iterkeys()]:
raise Exception("autoadd: Invalid options key:%s" % key)
# disable the watch loop if it was active
if watchdir_id in self.update_timers:
@ -360,7 +360,7 @@ class Core(CorePluginBase):
def set_config(self, config):
"""Sets the config dictionary."""
config = self._make_unicode(config)
for key in config:
for key in config.keys():
self.config[key] = config[key]
self.config.save()
component.get("EventManager").emit(AutoaddOptionsChangedEvent())
@ -386,7 +386,7 @@ class Core(CorePluginBase):
watchdirs[watchdir_id] = watchdir
log.debug("Current logged in user %s is not an ADMIN, send only "
"his watchdirs: %s", session_user, list(watchdirs))
"his watchdirs: %s", session_user, watchdirs.keys())
return watchdirs
def _make_unicode(self, options):
@ -434,7 +434,7 @@ class Core(CorePluginBase):
component.get("EventManager").emit(AutoaddOptionsChangedEvent())
def __migrate_config_1_to_2(self, config):
for watchdir_id in config["watchdirs"]:
for watchdir_id in config["watchdirs"].iterkeys():
config["watchdirs"][watchdir_id]["owner"] = "localclient"
return config

View File

@ -170,7 +170,7 @@ class Core(CorePluginBase):
"""
needs_blocklist_import = False
for key in config:
for key in config.keys():
if key == 'whitelisted':
saved = set(self.config[key])
update = set(config[key])

View File

@ -157,7 +157,7 @@ class Core(CorePluginBase):
@export
def set_config(self, config):
"sets the config dictionary"
for key in config:
for key in config.keys():
self.config[key] = config[key]
self.config.save()

View File

@ -107,8 +107,8 @@ class Core(CorePluginBase):
pass
def init_filter_dict(self):
filter_dict = dict([(label, 0) for label in self.labels])
filter_dict['All'] = len(self.torrents)
filter_dict = dict([(label, 0) for label in self.labels.keys()])
filter_dict['All'] = len(self.torrents.keys())
return filter_dict
# Plugin hooks #
@ -142,8 +142,8 @@ class Core(CorePluginBase):
*add any new keys in OPTIONS_DEFAULTS
*set all None values to default <-fix development config
"""
log.debug(list(self.labels))
for key in self.labels:
log.debug(self.labels.keys())
for key in self.labels.keys():
options = dict(OPTIONS_DEFAULTS)
options.update(self.labels[key])
self.labels[key] = options
@ -159,7 +159,7 @@ class Core(CorePluginBase):
@export
def get_labels(self):
return sorted(self.labels)
return sorted(self.labels.keys())
# Labels:
@export
@ -259,7 +259,7 @@ class Core(CorePluginBase):
}
"""
check_input(label_id in self.labels, _("Unknown Label"))
for key in options_dict:
for key in options_dict.keys():
if key not in OPTIONS_DEFAULTS:
raise Exception("label: Invalid options_dict key:%s" % key)

View File

@ -172,7 +172,7 @@ class OptionsDialog(object):
self.dialog.run()
def load_options(self, options):
log.debug(list(options))
log.debug(options.keys())
for spin_id in self.spin_ids + self.spin_int_ids:
self.glade.get_widget(spin_id).set_value(options[spin_id])

View File

@ -47,8 +47,8 @@ class CustomNotifications(object):
pass
def disable(self):
for kind in self.custom_notifications:
for eventtype in self.custom_notifications[kind].copy():
for kind in self.custom_notifications.iterkeys():
for eventtype in self.custom_notifications[kind].copy().iterkeys():
wrapper, handler = self.custom_notifications[kind][eventtype]
self._deregister_custom_provider(kind, eventtype)

View File

@ -80,7 +80,7 @@ class CoreNotifications(CustomNotifications):
def get_handled_events(self):
handled_events = []
for evt in sorted(known_events):
for evt in sorted(known_events.keys()):
if known_events[evt].__module__.startswith('deluge.event'):
if evt not in ('TorrentFinishedEvent',):
# Skip all un-handled built-in events
@ -204,7 +204,7 @@ class Core(CorePluginBase, CoreNotifications):
@export
def set_config(self, config):
"sets the config dictionary"
for key in config:
for key in config.keys():
self.config[key] = config[key]
self.config.save()

View File

@ -146,7 +146,7 @@ class Core(CorePluginBase):
@export()
def set_config(self, config):
"sets the config dictionary"
for key in config:
for key in config.keys():
self.config[key] = config[key]
self.config.save()
self.do_schedule(False)

View File

@ -215,7 +215,7 @@ class Core(CorePluginBase):
@export
def set_config(self, config):
"sets the config dictionary"
for key in config:
for key in config.keys():
self.config[key] = config[key]
self.config.save()

View File

@ -129,7 +129,7 @@ class GraphsTab(Tab):
return False
def update(self):
d1 = client.stats.get_stats(list(self.graph.stat_info), self.selected_interval)
d1 = client.stats.get_stats(self.graph.stat_info.keys(), self.selected_interval)
d1.addCallback(self.graph.set_stats)
def _update_complete(result):

View File

@ -97,7 +97,7 @@ class Core(CorePluginBase):
if not action:
action = 'restart'
for key in config:
for key in config.keys():
self.config[key] = config[key]
self.config.save()

View File

@ -132,7 +132,7 @@ class Core(CorePluginBase):
@export
def set_config(self, config):
\"\"\"Sets the config dictionary\"\"\"
for key in config:
for key in config.keys():
self.config[key] = config[key]
self.config.save()

View File

@ -175,7 +175,7 @@ class RPCRaiseDelugeErrorJSONTestCase(JSONBase):
self.assertTrue("testclass.test" in methods)
request = MagicMock()
request.getCookie = MagicMock(return_value=list(auth.config["sessions"])[0])
request.getCookie = MagicMock(return_value=auth.config["sessions"].keys()[0])
json_data = {"method": "testclass.test", "id": 0, "params": []}
request.json = json_lib.dumps(json_data)
request_id, result, error = json._handle_request(request)

View File

@ -33,7 +33,7 @@ class Core(object):
def get_torrent_status(self, torrent_id, keys, diff=False):
if not keys:
keys = list(self.torrents[torrent_id])
keys = self.torrents[torrent_id].keys()
if not diff:
ret = {}
@ -55,9 +55,9 @@ class Core(object):
def get_torrents_status(self, filter_dict, keys, diff=False):
if not filter_dict:
filter_dict["id"] = list(self.torrents)
filter_dict["id"] = self.torrents.keys()
if not keys:
keys = list(self.torrents["a"])
keys = self.torrents["a"].keys()
if not diff:
if "id" in filter_dict:
torrents = filter_dict["id"]

View File

@ -141,7 +141,7 @@ class Win32IcoFile(object):
# figure out where AND mask image starts
mode = a[0]
bpp = 8
for k in PIL.BmpImagePlugin.BIT2MODE:
for k in PIL.BmpImagePlugin.BIT2MODE.keys():
if mode == PIL.BmpImagePlugin.BIT2MODE[k][1]:
bpp = k
break

View File

@ -37,7 +37,7 @@ def find_subcommand(self, args=None, sys_argv=True):
for x in self._subparsers._actions:
if not isinstance(x, argparse._SubParsersAction):
continue
for sp_name in x._name_parser_map:
for sp_name in x._name_parser_map.keys():
if sp_name in args:
subcommand_found = args.index(sp_name)

View File

@ -394,7 +394,7 @@ class DaemonSSLProxy(DaemonProxy):
# We need to tell the daemon what events we're interested in receiving
if self.__factory.event_handlers:
self.call("daemon.set_event_interest",
list(self.__factory.event_handlers))
self.__factory.event_handlers.keys())
self.call("core.get_auth_levels_mappings").addCallback(
self.__on_auth_levels_mappings

View File

@ -134,7 +134,7 @@ class TorrentInfo(object):
item.update(paths[path])
item["download"] = True
file_tree = FileTree2(list(paths))
file_tree = FileTree2(paths.keys())
file_tree.walk(walk)
else:
def walk(path, item):
@ -313,7 +313,7 @@ class FileTree2(object):
:type callback: function
"""
def walk(directory, parent_path):
for path in directory["contents"]:
for path in directory["contents"].keys():
full_path = os.path.join(parent_path, path).replace("\\", "/")
if directory["contents"][path]["type"] == "dir":
directory["contents"][path] = callback(
@ -393,7 +393,7 @@ class FileTree(object):
:type callback: function
"""
def walk(directory, parent_path):
for path in directory:
for path in directory.keys():
full_path = os.path.join(parent_path, path)
if isinstance(directory[path], dict):
directory[path] = callback(full_path, directory[path]) or directory[path]

View File

@ -83,8 +83,9 @@ class Command(BaseCommand):
def _get_config(self, options):
def _on_get_config(config):
keys = sorted(config.keys())
s = ""
for key in sorted(config):
for key in keys:
if key not in options.values:
continue
color = "{!white,black,bold!}"
@ -119,7 +120,7 @@ class Command(BaseCommand):
self.console.write("{!error!}%s" % ex)
return
if key not in config:
if key not in config.keys():
self.console.write("{!error!}The key '%s' is invalid!" % key)
return
@ -137,4 +138,4 @@ class Command(BaseCommand):
return client.core.set_config({key: val}).addCallback(on_set_config)
def complete(self, text):
return [k for k in component.get("CoreConfig") if k.startswith(text)]
return [k for k in component.get("CoreConfig").keys() if k.startswith(text)]

View File

@ -75,7 +75,7 @@ class Command(BaseCommand):
return
request_options.append(opt)
if not request_options:
request_options = list(torrent_options)
request_options = [opt for opt in torrent_options.keys()]
request_options.append('name')
d = client.core.get_torrents_status({"id": torrent_ids}, request_options)

View File

@ -557,7 +557,7 @@ class AllTorrents(BaseMode, component.Component):
# Get first element so we can check if it has given field
# and if it's a string
first_element = state[list(state)[0]]
first_element = state[state.keys()[0]]
if field in first_element:
is_string = isinstance(first_element[field], basestring)

View File

@ -194,7 +194,7 @@ class Preferences(BaseMode):
if client.connected():
# Only do this if we're connected to a daemon
config_to_set = {}
for key in new_core_config:
for key in new_core_config.keys():
# The values do not match so this needs to be updated
if self.core_config[key] != new_core_config[key]:
config_to_set[key] = new_core_config[key]
@ -214,7 +214,7 @@ class Preferences(BaseMode):
# are ever reordered, so do it the slightly slower but safer way
if isinstance(pane, InterfacePane) or isinstance(pane, ColumnsPane):
pane.add_config_values(new_console_config)
for key in new_console_config:
for key in new_console_config.keys():
# The values do not match so this needs to be updated
if self.console_config[key] != new_console_config[key]:
self.console_config[key] = new_console_config[key]

View File

@ -271,7 +271,7 @@ class AccountDialog(BaseDialog):
self.authlevel_combo = gtk.combo_box_new_text()
active_idx = None
for idx, level in enumerate(levels_mapping):
for idx, level in enumerate(levels_mapping.keys()):
self.authlevel_combo.append_text(level)
if authlevel and authlevel == level:
active_idx = idx

View File

@ -303,7 +303,7 @@ class ListView(object):
def get_state_field_column(self, field):
"""Returns the column number for the state field"""
for column in self.columns:
for column in self.columns.keys():
if self.columns[column].status_field is None:
continue

View File

@ -413,7 +413,7 @@ class MenuBar(component.Component):
"menuitem_max_connections": client.core.set_torrent_max_connections,
"menuitem_upload_slots": client.core.set_torrent_max_upload_slots
}
if widget.name in funcs:
if widget.name in funcs.keys():
for torrent in component.get("TorrentView").get_selected_torrents():
funcs[widget.name](torrent, -1)

View File

@ -112,7 +112,7 @@ class OptionsTab(Tab):
# We only want to update values that have been applied in the core. This
# is so we don't overwrite the user changes that haven't been applied yet.
if self.prev_status is None:
self.prev_status = {}.fromkeys(list(status), None)
self.prev_status = {}.fromkeys(status.keys(), None)
if status != self.prev_status:
if status["max_download_speed"] != self.prev_status["max_download_speed"]:

View File

@ -58,7 +58,7 @@ class PathChoosersHandler(component.Component):
self.config_properties.update(config)
for chooser in self.path_choosers:
chooser.set_config(config)
keys = list(self.config_keys_to_funcs_mapping)
keys = self.config_keys_to_funcs_mapping.keys()
keys += self.paths_list_keys
client.core.get_config_values(keys).addCallback(_on_config_values)
@ -107,7 +107,7 @@ class PathChoosersHandler(component.Component):
chooser.set_values(values)
def get_config_keys(self):
keys = list(self.config_keys_to_funcs_mapping)
keys = self.config_keys_to_funcs_mapping.keys()
keys += self.paths_list_keys
return keys

View File

@ -296,7 +296,7 @@ class PeersTab(Tab):
self.peers[peer["ip"]] = row
# Now we need to remove any ips that were not in status["peers"] list
for ip in set(self.peers).difference(new_ips):
for ip in set(self.peers.keys()).difference(new_ips):
self.liststore.remove(self.peers[ip])
del self.peers[ip]

View File

@ -399,7 +399,7 @@ class Preferences(component.Component):
core_widgets[self.copy_torrent_files_path_chooser] = ("path_chooser", "torrentfiles_location")
# Update the widgets accordingly
for key in core_widgets:
for key in core_widgets.keys():
modifier = core_widgets[key][0]
if isinstance(key, str):
widget = self.builder.get_object(key)
@ -432,7 +432,7 @@ class Preferences(component.Component):
widget.set_text(value, cursor_end=False, default_text=True)
if self.is_connected:
for key in core_widgets:
for key in core_widgets.keys():
if isinstance(key, str):
widget = self.builder.get_object(key)
else:
@ -673,7 +673,7 @@ class Preferences(component.Component):
dialog.run()
# GtkUI
for key in new_gtkui_config:
for key in new_gtkui_config.keys():
# The values do not match so this needs to be updated
if self.gtkui_config[key] != new_gtkui_config[key]:
self.gtkui_config[key] = new_gtkui_config[key]
@ -682,7 +682,7 @@ class Preferences(component.Component):
if client.connected():
# Only do this if we're connected to a daemon
config_to_set = {}
for key in new_core_config:
for key in new_core_config.keys():
# The values do not match so this needs to be updated
if self.core_config[key] != new_core_config[key]:
config_to_set[key] = new_core_config[key]
@ -798,7 +798,7 @@ class Preferences(component.Component):
def update_dependent_widgets(name, value):
dependency = dependents[name]
for dep in dependency:
for dep in dependency.keys():
if dep in path_choosers:
depwidget = path_choosers[dep]
else:
@ -808,7 +808,7 @@ class Preferences(component.Component):
if dep in dependents:
update_dependent_widgets(dep, depwidget.get_active() and sensitive)
for key in dependents:
for key in dependents.keys():
if widget != self.builder.get_object(key):
continue
update_dependent_widgets(key, value)

View File

@ -288,7 +288,7 @@ class StatusBar(component.Component):
This is called when we receive a ConfigValueChangedEvent from
the core.
"""
if key in self.config_value_changed_dict:
if key in self.config_value_changed_dict.keys():
self.config_value_changed_dict[key](value)
def _on_max_connections_global(self, max_connections):

View File

@ -179,7 +179,7 @@ class SystemTray(component.Component):
def config_value_changed(self, key, value):
"""This is called when we received a config_value_changed signal from
the core."""
if key in self.config_value_changed_dict:
if key in self.config_value_changed_dict.keys():
self.config_value_changed_dict[key](value)
def _on_max_download_speed(self, max_download_speed):

View File

@ -408,7 +408,7 @@ class TorrentView(ListView, component.Component):
if columns is None:
# We need to iterate through all columns
columns = list(self.columns)
columns = self.columns.keys()
# Iterate through supplied list of columns to update
for column in columns:
@ -481,7 +481,7 @@ class TorrentView(ListView, component.Component):
# Get the columns to update from one of the torrents
if status:
torrent_id = list(status)[0]
torrent_id = status.keys()[0]
fields_to_update = []
for column in self.columns_to_update:
column_index = self.get_column_index(column)
@ -621,7 +621,7 @@ class TorrentView(ListView, component.Component):
return {}
def get_visible_torrents(self):
return list(self.status)
return self.status.keys()
# Callbacks #
def on_button_press_event(self, widget, event):

View File

@ -90,7 +90,7 @@ class SessionProxy(component.Component):
keys_to_remove = keys_diff_cached
else:
# Not the same keys so create a new diff
keys_to_remove = set(sd[torrent_id]) - keys
keys_to_remove = set(sd[torrent_id].iterkeys()) - keys
# Update the cached diff
keys_diff_cached = keys_to_remove
keys_len = len(sd[torrent_id])
@ -123,7 +123,7 @@ class SessionProxy(component.Component):
# Keep track of keys we need to request from the core
keys_to_get = []
if not keys:
keys = list(self.torrents[torrent_id][1])
keys = self.torrents[torrent_id][1].keys()
for key in keys:
if time() - self.cache_times[torrent_id].get(key, 0.0) > self.cache_time:
@ -190,7 +190,7 @@ class SessionProxy(component.Component):
# Create the status dict
if not torrent_ids:
torrent_ids = list(result)
torrent_ids = result.keys()
return self.create_status_dict(torrent_ids, keys)
@ -214,13 +214,13 @@ class SessionProxy(component.Component):
if not filter_dict:
# This means we want all the torrents status
# We get a list of any torrent_ids with expired status dicts
to_fetch = find_torrents_to_fetch(list(self.torrents))
to_fetch = find_torrents_to_fetch(self.torrents.keys())
if to_fetch:
d = client.core.get_torrents_status({"id": to_fetch}, keys, True)
return d.addCallback(on_status, list(self.torrents), keys)
return d.addCallback(on_status, self.torrents.keys(), keys)
# Don't need to fetch anything
return maybeDeferred(self.create_status_dict, list(self.torrents), keys)
return maybeDeferred(self.create_status_dict, self.torrents.keys(), keys)
if len(filter_dict) == 1 and "id" in filter_dict:
# At this point we should have a filter with just "id" in it

View File

@ -39,7 +39,7 @@ def start_ui():
# Get the registered UI entry points
ui_entrypoints = dict([(entrypoint.name, entrypoint.load())
for entrypoint in pkg_resources.iter_entry_points("deluge.ui")])
ui_titles = sorted(ui_entrypoints)
ui_titles = sorted(ui_entrypoints.keys())
def add_ui_options_group(_parser):
"""Function to enable reuse of UI Options group"""

View File

@ -90,7 +90,7 @@ class Auth(JSONComponent):
self.worker.stop()
def _clean_sessions(self):
session_ids = list(self.config["sessions"])
session_ids = self.config["sessions"].keys()
now = time.gmtime()
for session_id in session_ids:

View File

@ -893,7 +893,7 @@ class WebApi(JSONComponent):
:type config: dictionary
"""
web_config = component.get("DelugeWeb").config
for key in config:
for key in config.keys():
if key in ["sessions", "pwd_salt", "pwd_sha1"]:
log.warn("Ignored attempt to overwrite web config key '%s'", key)
continue
@ -914,7 +914,7 @@ class WebApi(JSONComponent):
"""
return {
"enabled_plugins": list(component.get("Web.PluginManager").plugins),
"enabled_plugins": component.get("Web.PluginManager").plugins.keys(),
"available_plugins": component.get("Web.PluginManager").available_plugins
}

View File

@ -89,7 +89,7 @@ def create_gettext_js(js_dir):
gettext_file = os.path.join(os.path.dirname(js_dir), 'gettext.js')
with open(gettext_file, 'w') as fp:
fp.write(gettext_tpl)
for key in sorted(strings):
for key in sorted(strings.keys()):
if DEBUG:
fp.write('\n// %s\n' % ', '.join(['%s:%s' % x for x in strings[key]]))
fp.write('''GetText.add('%(key)s','${escape(_("%(key)s"))}')\n''' % locals())

View File

@ -61,8 +61,9 @@ def generate():
"""
Return the generated output.
"""
keys = MESSAGES.keys()
# the keys are sorted in the .mo file
keys = sorted(MESSAGES)
keys.sort()
offsets = []
ids = strs = ''
for _id in keys: