Module: deluge
Branch: chunked-sessionproxy-and-gtkui-speedups
Commit: 117d50b72820807f53914d4db1071244492d5485

Author: Damien Churchill <[email protected]>
Date:   Sat May  7 11:51:47 2011 +0100

fix a bug when the host_id doesn't exist

---

 deluge/ui/web/json_api.py |   40 ++++++++++++++++++++--------------------
 1 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/deluge/ui/web/json_api.py b/deluge/ui/web/json_api.py
index 8365784..2cf90b7 100644
--- a/deluge/ui/web/json_api.py
+++ b/deluge/ui/web/json_api.py
@@ -740,46 +740,46 @@ class WebApi(JSONComponent):
         :param host_id: the hash id of the host
         :type host_id: string
        """
-        main_deferred = Deferred()
 
-        (host_id, host, port, user, password) = self.get_host(host_id)
+        def response(status, info=None):
+            return host_id, host, port, status, info
 
-        def callback(status, info=None):
-            main_deferred.callback((host_id, host, port, status, info))
+        try:
+            host_id, host, port, user, password = self.get_host(host_id)
+        except TypeError, e:
+            return response(_("Offline"))
 
         def on_connect(connected, c, host_id):
             def on_info(info, c):
                 c.disconnect()
-                callback(_("Online"), info)
+                return response(_("Online"), info)
 
             def on_info_fail(reason, c):
                 c.disconnect()
-                callback(_("Offline"))
+                return response(_("Offline"))
 
             if not connected:
-                callback(_("Offline"))
-                return
+                return response(_("Offline"))
 
-            d = c.daemon.info()
-            d.addCallback(on_info, c)
-            d.addErrback(on_info_fail, c)
+            return c.daemon.info(
+                ).addCallback(on_info, c
+                ).addErrback(on_info_fail, c)
 
         def on_connect_failed(reason, host_id):
-            callback(_("Offline"))
+            return response(_("Offline"))
 
-        if client.connected() and (host, port, "localclient" if not \
-                                   user and host in ("127.0.0.1", "localhost") 
else \
+        if client.connected() and (host, port, "localclient" if not
+                                   user and host in ("127.0.0.1", "localhost") 
else
                                    user)  == client.connection_info():
             def on_info(info):
-                callback(_("Connected"), info)
+                return response(_("Connected"), info)
 
-            client.daemon.info().addCallback(on_info)
+            return client.daemon.info().addCallback(on_info)
         else:
             c = Client()
-            d = c.connect(host, port, user, password)
-            d.addCallback(on_connect, c, host_id)
-            d.addErrback(on_connect_failed, host_id)
-        return main_deferred
+            return c.connect(host, port, user, password
+                ).addCallback(on_connect, c, host_id
+                ).addErrback(on_connect_failed, host_id)
 
     @export
     def start_daemon(self, port):

-- 
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.

Reply via email to