only return deferreds for those methods that require it

This commit is contained in:
Damien Churchill 2009-08-20 00:31:31 +00:00
parent 7d0ccb8847
commit 1a635e8860
2 changed files with 17 additions and 41 deletions

View File

@ -254,11 +254,8 @@ class Auth(JSONComponent):
:param new_password: the password to change to :param new_password: the password to change to
:type new_password: string :type new_password: string
""" """
d = Deferred()
if not self.check_password(old_password): if not self.check_password(old_password):
d.callback(False) return False
return d
log.debug("Changing password") log.debug("Changing password")
salt = hashlib.sha1(str(random.getrandbits(40))).hexdigest() salt = hashlib.sha1(str(random.getrandbits(40))).hexdigest()
@ -267,8 +264,7 @@ class Auth(JSONComponent):
config = component.get("DelugeWeb").config config = component.get("DelugeWeb").config
config["pwd_salt"] = salt config["pwd_salt"] = salt
config["pwd_sha1"] = s.hexdigest() config["pwd_sha1"] = s.hexdigest()
d.callback(True) return True
return d
@export(AUTH_LEVEL_NONE) @export(AUTH_LEVEL_NONE)
def check_session(self, session_id=None): def check_session(self, session_id=None):
@ -278,9 +274,7 @@ class Auth(JSONComponent):
:returns: True if the session is valid, False if not. :returns: True if the session is valid, False if not.
:rtype: booleon :rtype: booleon
""" """
d = Deferred() return __request__.session_id is not None
d.callback(__request__.session_id is not None)
return d
@export @export
def delete_session(self): def delete_session(self):
@ -293,8 +287,7 @@ class Auth(JSONComponent):
d = Deferred() d = Deferred()
config = component.get("DelugeWeb").config config = component.get("DelugeWeb").config
del config["sessions"][__request__.session_id] del config["sessions"][__request__.session_id]
d.callback(True) return True
return d
@export(AUTH_LEVEL_NONE) @export(AUTH_LEVEL_NONE)
def login(self, password): def login(self, password):
@ -307,9 +300,7 @@ class Auth(JSONComponent):
:rtype: string or False :rtype: string or False
""" """
d = Deferred()
if self.check_password(password): if self.check_password(password):
d.callback(self._create_session(__request__)) return self._create_session(__request__)
else: else:
d.callback(False) return False
return d

View File

@ -360,19 +360,15 @@ class WebApi(JSONComponent):
:returns: True if the client is connected :returns: True if the client is connected
:rtype: booleon :rtype: booleon
""" """
d = Deferred() return client.connected()
d.callback(client.connected())
return d
@export @export
def disconnect(self): def disconnect(self):
""" """
Disconnect the web interface from the connected daemon. Disconnect the web interface from the connected daemon.
""" """
d = Deferred()
client.disconnect() client.disconnect()
d.callback(True) return True
return d
@export @export
def update_ui(self, keys, filter_dict): def update_ui(self, keys, filter_dict):
@ -514,13 +510,11 @@ class WebApi(JSONComponent):
:rtype: dictionary :rtype: dictionary
""" """
d = Deferred()
try: try:
torrent_info = uicommon.TorrentInfo(filename.strip()) torrent_info = uicommon.TorrentInfo(filename.strip())
d.callback(torrent_info.as_dict("name", "info_hash", "files_tree")) return torrent_info.as_dict("name", "info_hash", "files_tree")
except: except:
d.callback(False) return False
return d
@export @export
def add_torrents(self, torrents): def add_torrents(self, torrents):
@ -545,9 +539,7 @@ class WebApi(JSONComponent):
log.info("Adding torrent from file `%s` with options `%r`", log.info("Adding torrent from file `%s` with options `%r`",
filename, torrent["options"]) filename, torrent["options"])
client.core.add_torrent_file(filename, fdump, torrent["options"]) client.core.add_torrent_file(filename, fdump, torrent["options"])
d = Deferred() return True
d.callback(True)
return d
@export @export
def get_hosts(self): def get_hosts(self):
@ -555,9 +547,7 @@ class WebApi(JSONComponent):
Return the hosts in the hostlist. Return the hosts in the hostlist.
""" """
log.debug("get_hosts called") log.debug("get_hosts called")
d = Deferred() return [(tuple(host[HOSTS_ID:HOSTS_PORT+1]) + (_("Offline"),)) for host in self.host_list["hosts"]]
d.callback([(tuple(host[HOSTS_ID:HOSTS_PORT+1]) + (_("Offline"),)) for host in self.host_list["hosts"]])
return d
@export @export
def get_host_status(self, host_id): def get_host_status(self, host_id):
@ -656,26 +646,23 @@ class WebApi(JSONComponent):
:type password: string :type password: string
""" """
d = Deferred()
# Check to see if there is already an entry for this host and return # Check to see if there is already an entry for this host and return
# if thats the case # if thats the case
for entry in self.host_list["hosts"]: for entry in self.host_list["hosts"]:
if (entry[0], entry[1], entry[2]) == (host, port, username): if (entry[0], entry[1], entry[2]) == (host, port, username):
d.callback((False, "Host already in the list")) return (False, "Host already in the list")
try: try:
port = int(port) port = int(port)
except: except:
d.callback((False, "Port is invalid")) return (False, "Port is invalid")
return d
# Host isn't in the list, so lets add it # Host isn't in the list, so lets add it
connection_id = hashlib.sha1(str(time.time())).hexdigest() connection_id = hashlib.sha1(str(time.time())).hexdigest()
self.host_list["hosts"].append([connection_id, host, port, username, self.host_list["hosts"].append([connection_id, host, port, username,
password]) password])
self.host_list.save() self.host_list.save()
d.callback((True,)) return (True,)
return d
@export @export
def remove_host(self, connection_id): def remove_host(self, connection_id):
@ -685,15 +672,13 @@ class WebApi(JSONComponent):
:param host_id: the hash id of the host :param host_id: the hash id of the host
:type host_id: string :type host_id: string
""" """
d = Deferred()
host = self.get_host(connection_id) host = self.get_host(connection_id)
if host is None: if host is None:
d.callback(False) return False
self.host_list["hosts"].remove(host) self.host_list["hosts"].remove(host)
self.host_list.save() self.host_list.save()
d.callback(True) return True
return d
@export @export
def get_config(self): def get_config(self):