Author: damoxc
Revision: 5687
Log:
only return deferreds for those methods that require it
Diff:
Modified: trunk/deluge/ui/web/auth.py
===================================================================
--- trunk/deluge/ui/web/auth.py 2009-08-20 00:27:34 UTC (rev 5686)
+++ trunk/deluge/ui/web/auth.py 2009-08-20 00:31:31 UTC (rev 5687)
@@ -254,11 +254,8 @@
: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 @@
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 @@
: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 @@
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 @@
: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
Modified: trunk/deluge/ui/web/json_api.py
===================================================================
--- trunk/deluge/ui/web/json_api.py 2009-08-20 00:27:34 UTC (rev 5686)
+++ trunk/deluge/ui/web/json_api.py 2009-08-20 00:31:31 UTC (rev 5687)
@@ -360,19 +360,15 @@
: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 @@
: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 @@
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 @@
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 @@
: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 @@
: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):
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"deluge-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/deluge-commit?hl=en
-~----------~----~----~----~------~----~------~--~---