diff --git a/TODO b/TODO index 52628f091..2a25d946c 100644 --- a/TODO +++ b/TODO @@ -12,4 +12,3 @@ * Restart daemon function * Sync the details pane to current trunk * Docstrings! -* Change core to use dbus variants instead of byte-arrays diff --git a/deluge/core/core.py b/deluge/core/core.py index 109e96b71..9d6926d03 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -272,38 +272,30 @@ class Core(dbus.service.Object): @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", in_signature="sas", - out_signature="ay") + out_signature="a{sv}") def get_torrent_status(self, torrent_id, keys): # Convert the array of strings to a python list of strings - nkeys = [] - for key in keys: - nkeys.append(str(key)) - # Pickle the status dictionary from the torrent + keys = deluge.common.pythonize(keys) + # Build the status dictionary try: - status = self.torrents[torrent_id].get_status(nkeys) + status = self.torrents[torrent_id].get_status(keys) except KeyError: # The torrent_id is not found in the torrentmanager, so return None - status = None - status = pickle.dumps(status) - return status + return None # Get the leftover fields and ask the plugin manager to fill them - leftover_fields = list(set(nkeys) - set(status.keys())) + leftover_fields = list(set(keys) - set(status.keys())) if len(leftover_fields) > 0: status.update(self.plugins.get_status(torrent_id, leftover_fields)) - status = pickle.dumps(status) return status @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", in_signature="", - out_signature="ay") + out_signature="as") def get_session_state(self): """Returns a list of torrent_ids in the session.""" # Get the torrent list from the TorrentManager - torrent_list = self.torrents.get_torrent_list() - # Pickle the list and send it - session_state = pickle.dumps(torrent_list) - return session_state + return self.torrents.get_torrent_list() @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge") def save_state(self): @@ -313,33 +305,28 @@ class Core(dbus.service.Object): @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", in_signature="", - out_signature="ay") + out_signature="a{sv}") def get_config(self): """Get all the preferences as a dictionary""" - config = self.config.get_config() - config = pickle.dumps(config) - return config + return self.config.get_config() @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", in_signature="s", - out_signature="ay") + out_signature="v") def get_config_value(self, key): """Get the config value for key""" try: value = self.config[key] except KeyError: return None - - value = pickle.dumps(value) + return value @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", - in_signature="ay") + in_signature="a{sv}") def set_config(self, config): """Set the config with values from dictionary""" - # Convert the byte array into the dictionary - config = "".join(chr(b) for b in config) - config = pickle.loads(config) + config = deluge.common.pythonize(config) # Load all the values into the configuration for key in config.keys(): self.config[key] = config[key] diff --git a/deluge/ui/functions.py b/deluge/ui/functions.py index 1bd5d0a5f..d8c45f87f 100644 --- a/deluge/ui/functions.py +++ b/deluge/ui/functions.py @@ -42,6 +42,7 @@ import pygtk pygtk.require('2.0') import gtk, gtk.glade +import deluge.common from deluge.log import LOG as log def get_core(): @@ -130,46 +131,29 @@ def force_reannounce(torrent_ids): def get_torrent_status(core, torrent_id, keys): """Builds the status dictionary and returns it""" - status = core.get_torrent_status(torrent_id, keys) - # Join the array of bytes into a string for pickle to read - status = "".join(chr(b) for b in status) - # De-serialize the object - status = pickle.loads(status) - return status + return deluge.common.pythonize(core.get_torrent_status(torrent_id, keys)) def get_session_state(core=None): # Get the core if not supplied if core is None: core = get_core() - state = core.get_session_state() - # Join the array of bytes into a string for pickle to read - state = "".join(chr(b) for b in state) - # De-serialize the object - state = pickle.loads(state) - return state + return deluge.common.pythonize(core.get_session_state()) def get_config(core=None): if core is None: core = get_core() - config = core.get_config() - config = "".join(chr(b) for b in config) - config = pickle.loads(config) - return config + return deluge.common.pythonize(core.get_config()) def get_config_value(key, core=None): if core is None: core = get_core() - config = core.get_config_value(key) - config = "".join(chr(b) for b in config) - config = pickle.loads(config) - return config + return deluge.common.pythonize(core.get_config_value(key)) def set_config(config, core=None): if config == {}: return if core is None: core = get_core() - config = pickle.dumps(config) core.set_config(config) def get_listen_port(core=None):