[Py2to3] Clean-up the use of keys() on dictionary objects.
To make the code more Python 3 compatible, I've made a few changes to how we handle keys() or iterkeys() calls on dictionaries. All functionality should remain the same. * Remove the use of .keys() or .iterkeys() when iterating through a dictionary. * Remove the use of .keys() when checking if key exists in dictionary. * Replace dict.keys() with list(dict) to obtain a list of dictionary keys. In Python 3 dict.keys() returns a dict_keys object, not a list.
This commit is contained in:
parent
16da4d851e
commit
8b50f3cdbd
|
@ -298,7 +298,7 @@ class ComponentRegistry(object):
|
|||
"""
|
||||
# Start all the components if names is empty
|
||||
if not names:
|
||||
names = self.components.keys()
|
||||
names = list(self.components)
|
||||
elif isinstance(names, str):
|
||||
names = [names]
|
||||
|
||||
|
@ -332,7 +332,7 @@ class ComponentRegistry(object):
|
|||
|
||||
"""
|
||||
if not names:
|
||||
names = self.components.keys()
|
||||
names = list(self.components)
|
||||
elif isinstance(names, str):
|
||||
names = [names]
|
||||
|
||||
|
@ -370,7 +370,7 @@ class ComponentRegistry(object):
|
|||
|
||||
"""
|
||||
if not names:
|
||||
names = self.components.keys()
|
||||
names = list(self.components)
|
||||
elif isinstance(names, str):
|
||||
names = [names]
|
||||
|
||||
|
@ -396,7 +396,7 @@ class ComponentRegistry(object):
|
|||
|
||||
"""
|
||||
if not names:
|
||||
names = self.components.keys()
|
||||
names = list(self.components)
|
||||
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(self.components.keys()).addCallback(on_stopped)
|
||||
return self.stop(list(self.components)).addCallback(on_stopped)
|
||||
|
||||
def update(self):
|
||||
"""Update all Components that are in a Started state."""
|
||||
|
|
|
@ -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.keys():
|
||||
if config_file not in self.config_files:
|
||||
self.config_files[config_file] = Config(config_file, defaults, self.config_directory)
|
||||
|
||||
return self.config_files[config_file]
|
||||
|
|
|
@ -505,7 +505,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.keys():
|
||||
for key in status_dict:
|
||||
status_dict[key].update(self.pluginmanager.get_status(key, plugin_keys))
|
||||
return status_dict
|
||||
d.addCallback(add_plugin_fields)
|
||||
|
@ -544,7 +544,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.keys():
|
||||
for key in config:
|
||||
if self.read_only_config_keys and key in self.read_only_config_keys:
|
||||
continue
|
||||
if isinstance(config[key], basestring):
|
||||
|
|
|
@ -169,7 +169,7 @@ class FilterManager(component.Component):
|
|||
if not filter_dict:
|
||||
return torrent_ids
|
||||
|
||||
torrent_keys, plugin_keys = self.torrents.separate_keys(filter_dict.keys(), torrent_ids)
|
||||
torrent_keys, plugin_keys = self.torrents.separate_keys(list(filter_dict), 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.keys())
|
||||
tree_keys = list(self.tree_fields)
|
||||
if hide_cat:
|
||||
for cat in hide_cat:
|
||||
tree_keys.remove(cat)
|
||||
|
|
|
@ -46,7 +46,7 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase, component.Compon
|
|||
self.stop()
|
||||
|
||||
def update_plugins(self):
|
||||
for plugin in self.plugins.keys():
|
||||
for plugin in self.plugins:
|
||||
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 = self.status_fields.keys()
|
||||
fields = list(self.status_fields)
|
||||
for field in fields:
|
||||
try:
|
||||
status[field] = self.status_fields[field](torrent_id)
|
||||
|
|
|
@ -429,7 +429,7 @@ class RPCServer(component.Component):
|
|||
:returns: the exported methods
|
||||
:rtype: list
|
||||
"""
|
||||
return self.factory.methods.keys()
|
||||
return list(self.factory.methods)
|
||||
|
||||
def get_session_id(self):
|
||||
"""
|
||||
|
|
|
@ -940,7 +940,7 @@ class Torrent(object):
|
|||
self.update_status(self.handle.status())
|
||||
|
||||
if all_keys:
|
||||
keys = self.status_funcs.keys()
|
||||
keys = list(self.status_funcs)
|
||||
|
||||
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.keys():
|
||||
for key in self.prev_status:
|
||||
if not self.rpcserver.is_session_valid(key):
|
||||
del self.prev_status[key]
|
||||
|
||||
|
|
|
@ -266,7 +266,7 @@ class TorrentManager(component.Component):
|
|||
list: A list of torrent_ids.
|
||||
|
||||
"""
|
||||
torrent_ids = self.torrents.keys()
|
||||
torrent_ids = list(self.torrents)
|
||||
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.keys():
|
||||
for key in self.torrents:
|
||||
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.keys():
|
||||
for key in self.torrents:
|
||||
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.keys():
|
||||
for key in self.torrents:
|
||||
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.keys():
|
||||
for key in self.torrents:
|
||||
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 = self.torrents[torrent_id].status_funcs.keys()
|
||||
status_keys = list(self.torrents[torrent_id].status_funcs)
|
||||
leftover_keys = list(set(keys) - set(status_keys))
|
||||
torrent_keys = list(set(keys) - set(leftover_keys))
|
||||
return torrent_keys, leftover_keys
|
||||
|
|
|
@ -74,7 +74,7 @@ class PluginManagerBase(object):
|
|||
|
||||
def disable_plugins(self):
|
||||
# Disable all plugins that are enabled
|
||||
for key in self.plugins.keys():
|
||||
for key in self.plugins:
|
||||
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 self.plugins.keys()
|
||||
return list(self.plugins)
|
||||
|
||||
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.keys()):
|
||||
if line[0] in ' \t' and (len(line.split(":", 1)) == 1 or line.split(":", 1)[0] not in info):
|
||||
# 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.keys():
|
||||
if line.split(":", 1)[0] in info:
|
||||
last_header = line.split(":", 1)[0]
|
||||
info[last_header] = line.split(":", 1)[1].strip()
|
||||
return info
|
||||
|
|
|
@ -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.keys():
|
||||
for key in options:
|
||||
if key not in OPTIONS_AVAILABLE:
|
||||
if key not in [key2 + "_toggle" for key2 in OPTIONS_AVAILABLE.iterkeys()]:
|
||||
if key not in [key2 + "_toggle" for key2 in OPTIONS_AVAILABLE]:
|
||||
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.keys():
|
||||
for key in config:
|
||||
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, watchdirs.keys())
|
||||
"his watchdirs: %s", session_user, list(watchdirs))
|
||||
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"].iterkeys():
|
||||
for watchdir_id in config["watchdirs"]:
|
||||
config["watchdirs"][watchdir_id]["owner"] = "localclient"
|
||||
return config
|
||||
|
||||
|
|
|
@ -168,7 +168,7 @@ class Core(CorePluginBase):
|
|||
|
||||
"""
|
||||
needs_blocklist_import = False
|
||||
for key in config.keys():
|
||||
for key in config:
|
||||
if key == 'whitelisted':
|
||||
saved = set(self.config[key])
|
||||
update = set(config[key])
|
||||
|
|
|
@ -157,7 +157,7 @@ class Core(CorePluginBase):
|
|||
@export
|
||||
def set_config(self, config):
|
||||
"sets the config dictionary"
|
||||
for key in config.keys():
|
||||
for key in config:
|
||||
self.config[key] = config[key]
|
||||
self.config.save()
|
||||
|
||||
|
|
|
@ -107,8 +107,8 @@ class Core(CorePluginBase):
|
|||
pass
|
||||
|
||||
def init_filter_dict(self):
|
||||
filter_dict = dict([(label, 0) for label in self.labels.keys()])
|
||||
filter_dict['All'] = len(self.torrents.keys())
|
||||
filter_dict = dict([(label, 0) for label in self.labels])
|
||||
filter_dict['All'] = len(self.torrents)
|
||||
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(self.labels.keys())
|
||||
for key in self.labels.keys():
|
||||
log.debug(list(self.labels))
|
||||
for key in self.labels:
|
||||
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.keys())
|
||||
return sorted(self.labels)
|
||||
|
||||
# Labels:
|
||||
@export
|
||||
|
@ -259,7 +259,7 @@ class Core(CorePluginBase):
|
|||
}
|
||||
"""
|
||||
check_input(label_id in self.labels, _("Unknown Label"))
|
||||
for key in options_dict.keys():
|
||||
for key in options_dict:
|
||||
if key not in OPTIONS_DEFAULTS:
|
||||
raise Exception("label: Invalid options_dict key:%s" % key)
|
||||
|
||||
|
|
|
@ -172,7 +172,7 @@ class OptionsDialog(object):
|
|||
self.dialog.run()
|
||||
|
||||
def load_options(self, options):
|
||||
log.debug(options.keys())
|
||||
log.debug(list(options))
|
||||
|
||||
for spin_id in self.spin_ids + self.spin_int_ids:
|
||||
self.glade.get_widget(spin_id).set_value(options[spin_id])
|
||||
|
|
|
@ -47,8 +47,8 @@ class CustomNotifications(object):
|
|||
pass
|
||||
|
||||
def disable(self):
|
||||
for kind in self.custom_notifications.iterkeys():
|
||||
for eventtype in self.custom_notifications[kind].copy().iterkeys():
|
||||
for kind in self.custom_notifications:
|
||||
for eventtype in self.custom_notifications[kind].copy():
|
||||
wrapper, handler = self.custom_notifications[kind][eventtype]
|
||||
self._deregister_custom_provider(kind, eventtype)
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ class CoreNotifications(CustomNotifications):
|
|||
|
||||
def get_handled_events(self):
|
||||
handled_events = []
|
||||
for evt in sorted(known_events.keys()):
|
||||
for evt in sorted(known_events):
|
||||
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.keys():
|
||||
for key in config:
|
||||
self.config[key] = config[key]
|
||||
self.config.save()
|
||||
|
||||
|
|
|
@ -146,7 +146,7 @@ class Core(CorePluginBase):
|
|||
@export()
|
||||
def set_config(self, config):
|
||||
"sets the config dictionary"
|
||||
for key in config.keys():
|
||||
for key in config:
|
||||
self.config[key] = config[key]
|
||||
self.config.save()
|
||||
self.do_schedule(False)
|
||||
|
|
|
@ -213,7 +213,7 @@ class Core(CorePluginBase):
|
|||
@export
|
||||
def set_config(self, config):
|
||||
"sets the config dictionary"
|
||||
for key in config.keys():
|
||||
for key in config:
|
||||
self.config[key] = config[key]
|
||||
self.config.save()
|
||||
|
||||
|
|
|
@ -128,7 +128,7 @@ class GraphsTab(Tab):
|
|||
return False
|
||||
|
||||
def update(self):
|
||||
d1 = client.stats.get_stats(self.graph.stat_info.keys(), self.selected_interval)
|
||||
d1 = client.stats.get_stats(list(self.graph.stat_info), self.selected_interval)
|
||||
d1.addCallback(self.graph.set_stats)
|
||||
|
||||
def _update_complete(result):
|
||||
|
|
|
@ -98,7 +98,7 @@ class Core(CorePluginBase):
|
|||
if not action:
|
||||
action = 'restart'
|
||||
|
||||
for key in config.keys():
|
||||
for key in config:
|
||||
self.config[key] = config[key]
|
||||
self.config.save()
|
||||
|
||||
|
|
|
@ -132,7 +132,7 @@ class Core(CorePluginBase):
|
|||
@export
|
||||
def set_config(self, config):
|
||||
\"\"\"Sets the config dictionary\"\"\"
|
||||
for key in config.keys():
|
||||
for key in config:
|
||||
self.config[key] = config[key]
|
||||
self.config.save()
|
||||
|
||||
|
|
|
@ -175,7 +175,7 @@ class RPCRaiseDelugeErrorJSONTestCase(JSONBase):
|
|||
self.assertTrue("testclass.test" in methods)
|
||||
|
||||
request = MagicMock()
|
||||
request.getCookie = MagicMock(return_value=auth.config["sessions"].keys()[0])
|
||||
request.getCookie = MagicMock(return_value=list(auth.config["sessions"])[0])
|
||||
json_data = {"method": "testclass.test", "id": 0, "params": []}
|
||||
request.json = json_lib.dumps(json_data)
|
||||
request_id, result, error = json._handle_request(request)
|
||||
|
|
|
@ -33,7 +33,7 @@ class Core(object):
|
|||
|
||||
def get_torrent_status(self, torrent_id, keys, diff=False):
|
||||
if not keys:
|
||||
keys = self.torrents[torrent_id].keys()
|
||||
keys = list(self.torrents[torrent_id])
|
||||
|
||||
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"] = self.torrents.keys()
|
||||
filter_dict["id"] = list(self.torrents)
|
||||
if not keys:
|
||||
keys = self.torrents["a"].keys()
|
||||
keys = list(self.torrents["a"])
|
||||
if not diff:
|
||||
if "id" in filter_dict:
|
||||
torrents = filter_dict["id"]
|
||||
|
|
|
@ -139,7 +139,7 @@ class Win32IcoFile(object):
|
|||
# figure out where AND mask image starts
|
||||
mode = a[0]
|
||||
bpp = 8
|
||||
for k in PIL.BmpImagePlugin.BIT2MODE.keys():
|
||||
for k in PIL.BmpImagePlugin.BIT2MODE:
|
||||
if mode == PIL.BmpImagePlugin.BIT2MODE[k][1]:
|
||||
bpp = k
|
||||
break
|
||||
|
|
|
@ -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.keys():
|
||||
for sp_name in x._name_parser_map:
|
||||
if sp_name in args:
|
||||
subcommand_found = args.index(sp_name)
|
||||
|
||||
|
|
|
@ -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",
|
||||
self.__factory.event_handlers.keys())
|
||||
list(self.__factory.event_handlers))
|
||||
|
||||
self.call("core.get_auth_levels_mappings").addCallback(
|
||||
self.__on_auth_levels_mappings
|
||||
|
|
|
@ -134,7 +134,7 @@ class TorrentInfo(object):
|
|||
item.update(paths[path])
|
||||
item["download"] = True
|
||||
|
||||
file_tree = FileTree2(paths.keys())
|
||||
file_tree = FileTree2(list(paths))
|
||||
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"].keys():
|
||||
for path in directory["contents"]:
|
||||
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.keys():
|
||||
for path in directory:
|
||||
full_path = os.path.join(parent_path, path)
|
||||
if isinstance(directory[path], dict):
|
||||
directory[path] = callback(full_path, directory[path]) or directory[path]
|
||||
|
|
|
@ -83,9 +83,8 @@ class Command(BaseCommand):
|
|||
|
||||
def _get_config(self, options):
|
||||
def _on_get_config(config):
|
||||
keys = sorted(config.keys())
|
||||
s = ""
|
||||
for key in keys:
|
||||
for key in sorted(config):
|
||||
if key not in options.values:
|
||||
continue
|
||||
color = "{!white,black,bold!}"
|
||||
|
@ -120,7 +119,7 @@ class Command(BaseCommand):
|
|||
self.console.write("{!error!}%s" % ex)
|
||||
return
|
||||
|
||||
if key not in config.keys():
|
||||
if key not in config:
|
||||
self.console.write("{!error!}The key '%s' is invalid!" % key)
|
||||
return
|
||||
|
||||
|
@ -138,4 +137,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").keys() if k.startswith(text)]
|
||||
return [k for k in component.get("CoreConfig") if k.startswith(text)]
|
||||
|
|
|
@ -75,7 +75,7 @@ class Command(BaseCommand):
|
|||
return
|
||||
request_options.append(opt)
|
||||
if not request_options:
|
||||
request_options = [opt for opt in torrent_options.keys()]
|
||||
request_options = list(torrent_options)
|
||||
request_options.append('name')
|
||||
|
||||
d = client.core.get_torrents_status({"id": torrent_ids}, request_options)
|
||||
|
|
|
@ -555,7 +555,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[state.keys()[0]]
|
||||
first_element = state[list(state)[0]]
|
||||
if field in first_element:
|
||||
is_string = isinstance(first_element[field], basestring)
|
||||
|
||||
|
|
|
@ -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.keys():
|
||||
for key in new_core_config:
|
||||
# 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.keys():
|
||||
for key in new_console_config:
|
||||
# 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]
|
||||
|
|
|
@ -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.keys()):
|
||||
for idx, level in enumerate(levels_mapping):
|
||||
self.authlevel_combo.append_text(level)
|
||||
if authlevel and authlevel == level:
|
||||
active_idx = idx
|
||||
|
|
|
@ -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.keys():
|
||||
for column in self.columns:
|
||||
if self.columns[column].status_field is None:
|
||||
continue
|
||||
|
||||
|
|
|
@ -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.keys():
|
||||
if widget.name in funcs:
|
||||
for torrent in component.get("TorrentView").get_selected_torrents():
|
||||
funcs[widget.name](torrent, -1)
|
||||
|
||||
|
|
|
@ -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(status.keys(), None)
|
||||
self.prev_status = {}.fromkeys(list(status), None)
|
||||
|
||||
if status != self.prev_status:
|
||||
if status["max_download_speed"] != self.prev_status["max_download_speed"]:
|
||||
|
|
|
@ -58,7 +58,7 @@ class PathChoosersHandler(component.Component):
|
|||
self.config_properties.update(config)
|
||||
for chooser in self.path_choosers:
|
||||
chooser.set_config(config)
|
||||
keys = self.config_keys_to_funcs_mapping.keys()
|
||||
keys = list(self.config_keys_to_funcs_mapping)
|
||||
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 = self.config_keys_to_funcs_mapping.keys()
|
||||
keys = list(self.config_keys_to_funcs_mapping)
|
||||
keys += self.paths_list_keys
|
||||
return keys
|
||||
|
||||
|
|
|
@ -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.keys()).difference(new_ips):
|
||||
for ip in set(self.peers).difference(new_ips):
|
||||
self.liststore.remove(self.peers[ip])
|
||||
del self.peers[ip]
|
||||
|
||||
|
|
|
@ -400,7 +400,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.keys():
|
||||
for key in core_widgets:
|
||||
modifier = core_widgets[key][0]
|
||||
if isinstance(key, str):
|
||||
widget = self.builder.get_object(key)
|
||||
|
@ -433,7 +433,7 @@ class Preferences(component.Component):
|
|||
widget.set_text(value, cursor_end=False, default_text=True)
|
||||
|
||||
if self.is_connected:
|
||||
for key in core_widgets.keys():
|
||||
for key in core_widgets:
|
||||
if isinstance(key, str):
|
||||
widget = self.builder.get_object(key)
|
||||
else:
|
||||
|
@ -674,7 +674,7 @@ class Preferences(component.Component):
|
|||
dialog.run()
|
||||
|
||||
# GtkUI
|
||||
for key in new_gtkui_config.keys():
|
||||
for key in new_gtkui_config:
|
||||
# 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]
|
||||
|
@ -683,7 +683,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.keys():
|
||||
for key in new_core_config:
|
||||
# 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]
|
||||
|
@ -799,7 +799,7 @@ class Preferences(component.Component):
|
|||
|
||||
def update_dependent_widgets(name, value):
|
||||
dependency = dependents[name]
|
||||
for dep in dependency.keys():
|
||||
for dep in dependency:
|
||||
if dep in path_choosers:
|
||||
depwidget = path_choosers[dep]
|
||||
else:
|
||||
|
@ -809,7 +809,7 @@ class Preferences(component.Component):
|
|||
if dep in dependents:
|
||||
update_dependent_widgets(dep, depwidget.get_active() and sensitive)
|
||||
|
||||
for key in dependents.keys():
|
||||
for key in dependents:
|
||||
if widget != self.builder.get_object(key):
|
||||
continue
|
||||
update_dependent_widgets(key, value)
|
||||
|
|
|
@ -286,7 +286,7 @@ class StatusBar(component.Component):
|
|||
This is called when we receive a ConfigValueChangedEvent from
|
||||
the core.
|
||||
"""
|
||||
if key in self.config_value_changed_dict.keys():
|
||||
if key in self.config_value_changed_dict:
|
||||
self.config_value_changed_dict[key](value)
|
||||
|
||||
def _on_max_connections_global(self, max_connections):
|
||||
|
|
|
@ -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.keys():
|
||||
if key in self.config_value_changed_dict:
|
||||
self.config_value_changed_dict[key](value)
|
||||
|
||||
def _on_max_download_speed(self, max_download_speed):
|
||||
|
|
|
@ -408,7 +408,7 @@ class TorrentView(ListView, component.Component):
|
|||
|
||||
if columns is None:
|
||||
# We need to iterate through all columns
|
||||
columns = self.columns.keys()
|
||||
columns = list(self.columns)
|
||||
|
||||
# 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 = status.keys()[0]
|
||||
torrent_id = list(status)[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 self.status.keys()
|
||||
return list(self.status)
|
||||
|
||||
# Callbacks #
|
||||
def on_button_press_event(self, widget, event):
|
||||
|
|
|
@ -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].iterkeys()) - keys
|
||||
keys_to_remove = set(sd[torrent_id]) - 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 = self.torrents[torrent_id][1].keys()
|
||||
keys = list(self.torrents[torrent_id][1])
|
||||
|
||||
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 = result.keys()
|
||||
torrent_ids = list(result)
|
||||
|
||||
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(self.torrents.keys())
|
||||
to_fetch = find_torrents_to_fetch(list(self.torrents))
|
||||
if to_fetch:
|
||||
d = client.core.get_torrents_status({"id": to_fetch}, keys, True)
|
||||
return d.addCallback(on_status, self.torrents.keys(), keys)
|
||||
return d.addCallback(on_status, list(self.torrents), keys)
|
||||
|
||||
# Don't need to fetch anything
|
||||
return maybeDeferred(self.create_status_dict, self.torrents.keys(), keys)
|
||||
return maybeDeferred(self.create_status_dict, list(self.torrents), keys)
|
||||
|
||||
if len(filter_dict) == 1 and "id" in filter_dict:
|
||||
# At this point we should have a filter with just "id" in it
|
||||
|
|
|
@ -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.keys())
|
||||
ui_titles = sorted(ui_entrypoints)
|
||||
|
||||
def add_ui_options_group(_parser):
|
||||
"""Function to enable reuse of UI Options group"""
|
||||
|
|
|
@ -90,7 +90,7 @@ class Auth(JSONComponent):
|
|||
self.worker.stop()
|
||||
|
||||
def _clean_sessions(self):
|
||||
session_ids = self.config["sessions"].keys()
|
||||
session_ids = list(self.config["sessions"])
|
||||
|
||||
now = time.gmtime()
|
||||
for session_id in session_ids:
|
||||
|
|
|
@ -891,7 +891,7 @@ class WebApi(JSONComponent):
|
|||
:type config: dictionary
|
||||
"""
|
||||
web_config = component.get("DelugeWeb").config
|
||||
for key in config.keys():
|
||||
for key in config:
|
||||
if key in ["sessions", "pwd_salt", "pwd_sha1"]:
|
||||
log.warn("Ignored attempt to overwrite web config key '%s'", key)
|
||||
continue
|
||||
|
@ -912,7 +912,7 @@ class WebApi(JSONComponent):
|
|||
"""
|
||||
|
||||
return {
|
||||
"enabled_plugins": component.get("Web.PluginManager").plugins.keys(),
|
||||
"enabled_plugins": list(component.get("Web.PluginManager").plugins),
|
||||
"available_plugins": component.get("Web.PluginManager").available_plugins
|
||||
}
|
||||
|
||||
|
|
|
@ -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.keys()):
|
||||
for key in sorted(strings):
|
||||
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())
|
||||
|
|
Loading…
Reference in New Issue