summaryrefslogtreecommitdiffstats
path: root/deluge/ui
diff options
context:
space:
mode:
authorDamien Churchill <damoc@gmail.com>2009-08-20 00:31:31 +0000
committerDamien Churchill <damoc@gmail.com>2009-08-20 00:31:31 +0000
commit1a635e8860edb0f8988e38d4b5d4d3548dfb274b (patch)
treed0b9e2226464bef6ef75a259933b7c2a0a4818a6 /deluge/ui
parent7d0ccb8847acf8e755274eed3d290b78e35956de (diff)
downloaddeluge-1a635e8860edb0f8988e38d4b5d4d3548dfb274b.tar.gz
deluge-1a635e8860edb0f8988e38d4b5d4d3548dfb274b.tar.bz2
deluge-1a635e8860edb0f8988e38d4b5d4d3548dfb274b.zip
only return deferreds for those methods that require it
Diffstat (limited to 'deluge/ui')
-rw-r--r--deluge/ui/web/auth.py21
-rw-r--r--deluge/ui/web/json_api.py37
2 files changed, 17 insertions, 41 deletions
diff --git a/deluge/ui/web/auth.py b/deluge/ui/web/auth.py
index b0cede765..d700ecb66 100644
--- a/deluge/ui/web/auth.py
+++ b/deluge/ui/web/auth.py
@@ -254,11 +254,8 @@ class Auth(JSONComponent):
:param new_password: the password to change to
:type new_password: string
"""
- d = Deferred()
-
if not self.check_password(old_password):
- d.callback(False)
- return d
+ return False
log.debug("Changing password")
salt = hashlib.sha1(str(random.getrandbits(40))).hexdigest()
@@ -267,8 +264,7 @@ class Auth(JSONComponent):
config = component.get("DelugeWeb").config
config["pwd_salt"] = salt
config["pwd_sha1"] = s.hexdigest()
- d.callback(True)
- return d
+ return True
@export(AUTH_LEVEL_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.
:rtype: booleon
"""
- d = Deferred()
- d.callback(__request__.session_id is not None)
- return d
+ return __request__.session_id is not None
@export
def delete_session(self):
@@ -293,8 +287,7 @@ class Auth(JSONComponent):
d = Deferred()
config = component.get("DelugeWeb").config
del config["sessions"][__request__.session_id]
- d.callback(True)
- return d
+ return True
@export(AUTH_LEVEL_NONE)
def login(self, password):
@@ -307,9 +300,7 @@ class Auth(JSONComponent):
:rtype: string or False
"""
- d = Deferred()
if self.check_password(password):
- d.callback(self._create_session(__request__))
+ return self._create_session(__request__)
else:
- d.callback(False)
- return d
+ return False
diff --git a/deluge/ui/web/json_api.py b/deluge/ui/web/json_api.py
index 3bb2d277b..3a7653dd5 100644
--- a/deluge/ui/web/json_api.py
+++ b/deluge/ui/web/json_api.py
@@ -360,19 +360,15 @@ class WebApi(JSONComponent):
:returns: True if the client is connected
:rtype: booleon
"""
- d = Deferred()
- d.callback(client.connected())
- return d
+ return client.connected()
@export
def disconnect(self):
"""
Disconnect the web interface from the connected daemon.
"""
- d = Deferred()
client.disconnect()
- d.callback(True)
- return d
+ return True
@export
def update_ui(self, keys, filter_dict):
@@ -514,13 +510,11 @@ class WebApi(JSONComponent):
:rtype: dictionary
"""
- d = Deferred()
try:
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:
- d.callback(False)
- return d
+ return False
@export
def add_torrents(self, torrents):
@@ -545,9 +539,7 @@ class WebApi(JSONComponent):
log.info("Adding torrent from file `%s` with options `%r`",
filename, torrent["options"])
client.core.add_torrent_file(filename, fdump, torrent["options"])
- d = Deferred()
- d.callback(True)
- return d
+ return True
@export
def get_hosts(self):
@@ -555,9 +547,7 @@ class WebApi(JSONComponent):
Return the hosts in the hostlist.
"""
log.debug("get_hosts called")
- d = Deferred()
- d.callback([(tuple(host[HOSTS_ID:HOSTS_PORT+1]) + (_("Offline"),)) for host in self.host_list["hosts"]])
- return d
+ return [(tuple(host[HOSTS_ID:HOSTS_PORT+1]) + (_("Offline"),)) for host in self.host_list["hosts"]]
@export
def get_host_status(self, host_id):
@@ -656,26 +646,23 @@ class WebApi(JSONComponent):
:type password: string
"""
- d = Deferred()
# Check to see if there is already an entry for this host and return
# if thats the case
for entry in self.host_list["hosts"]:
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:
port = int(port)
except:
- d.callback((False, "Port is invalid"))
- return d
+ return (False, "Port is invalid")
# Host isn't in the list, so lets add it
connection_id = hashlib.sha1(str(time.time())).hexdigest()
self.host_list["hosts"].append([connection_id, host, port, username,
password])
self.host_list.save()
- d.callback((True,))
- return d
+ return (True,)
@export
def remove_host(self, connection_id):
@@ -685,15 +672,13 @@ class WebApi(JSONComponent):
:param host_id: the hash id of the host
:type host_id: string
"""
- d = Deferred()
host = self.get_host(connection_id)
if host is None:
- d.callback(False)
+ return False
self.host_list["hosts"].remove(host)
self.host_list.save()
- d.callback(True)
- return d
+ return True
@export
def get_config(self):