Module: deluge
Branch: improved-logging
Commit: e52018bfcd660251d94af2878b58ebacf6d82424

Author: Pedro Algarvio <[email protected]>
Date:   Fri Dec 10 04:59:05 2010 +0000

Dont make code that still uses the old "TorrentAddedEvent" fail, instead log a 
warning and make it work.

---

 deluge/core/eventmanager.py |   14 +++++++++++++-
 deluge/ui/client.py         |   37 +++++++++++++++++++++++++------------
 2 files changed, 38 insertions(+), 13 deletions(-)

diff --git a/deluge/core/eventmanager.py b/deluge/core/eventmanager.py
index b4aa175..0f61645 100644
--- a/deluge/core/eventmanager.py
+++ b/deluge/core/eventmanager.py
@@ -53,7 +53,19 @@ class EventManager(component.Component):
         if event.name in self.handlers:
             for handler in self.handlers[event.name]:
                 #log.debug("Running handler %s for event %s with args: %s", 
event.name, handler, event.args)
-                handler(*event.args)
+                try:
+                    handler(*event.args)
+                except TypeError:
+                    if event.name != "TorrentAddedEvent":
+                        raise
+                    else:
+                        log.warning("TorrentAddedEvent recently got an extra "
+                                    "argument, \"from_state\" and the handler "
+                                    "\"%s\" is not accepting that extra "
+                                    "argument. Correcting for now but this 
code "
+                                    "should be changed.", handler)
+                        handler(event.args[0])
+
 
     def register_event_handler(self, event, handler):
         """
diff --git a/deluge/ui/client.py b/deluge/ui/client.py
index 3fbae6e..f040244 100644
--- a/deluge/ui/client.py
+++ b/deluge/ui/client.py
@@ -140,7 +140,7 @@ class DelugeRPCProtocol(Protocol):
         while data:
             # Increase the byte counter
             self.factory.bytes_recv += len(data)
-            
+
             dobj = zlib.decompressobj()
             try:
                 request = rencode.loads(dobj.decompress(data))
@@ -167,9 +167,22 @@ class DelugeRPCProtocol(Protocol):
                 #log.debug("Received RPCEvent: %s", event)
                 # A RPCEvent was received from the daemon so run any handlers
                 # associated with it.
+                def call_handler(event, handler, args):
+                    try:
+                        handler(*args)
+                    except TypeError:
+                        if event != "TorrentAddedEvent":
+                            raise
+                        else:
+                            log.warning("TorrentAddedEvent recently got an 
extra "
+                                        "argument, \"from_state\" and the 
handler "
+                                        "\"%s\" is not accepting that extra "
+                                        "argument. Correcting for now but this 
code "
+                                        "should be changed.", handler)
+                            handler(args[0])
                 if event in self.factory.event_handlers:
                     for handler in self.factory.event_handlers[event]:
-                        reactor.callLater(0, handler, *request[2])
+                        reactor.callLater(0, call_handler, event, handler, 
request[2])
                 continue
 
             request_id = request[1]
@@ -213,7 +226,7 @@ class DelugeRPCClientFactory(ClientFactory):
     def __init__(self, daemon, event_handlers):
         self.daemon = daemon
         self.event_handlers = event_handlers
-        
+
         self.bytes_recv = 0
         self.bytes_sent = 0
 
@@ -329,7 +342,7 @@ class DaemonSSLProxy(DaemonProxy):
 
         :param request_id: the request_id of the Deferred to pop
         :type request_id: int
-        
+
         """
         return self.__deferred.pop(request_id)
 
@@ -343,7 +356,7 @@ class DaemonSSLProxy(DaemonProxy):
         :param handler: the function to be called when `:param:event`
             is emitted from the daemon
         :type handler: function
-        
+
         """
         if event not in self.__factory.event_handlers:
             # This is a new event to handle, so we need to tell the daemon
@@ -422,10 +435,10 @@ class DaemonSSLProxy(DaemonProxy):
 
     def get_bytes_recv(self):
         return self.__factory.bytes_recv
-    
+
     def get_bytes_sent(self):
         return self.__factory.bytes_sent
-        
+
 class DaemonClassicProxy(DaemonProxy):
     def __init__(self, event_handlers={}):
         import deluge.core.daemon
@@ -466,7 +479,7 @@ class DaemonClassicProxy(DaemonProxy):
         :param handler: the function to be called when `:param:event`
             is emitted from the daemon
         :type handler: function
-        
+
         """
         self.__daemon.core.eventmanager.register_event_handler(event, handler)
 
@@ -571,7 +584,7 @@ class Client(object):
         :rtype: bool
 
         :raises OSError: received from subprocess.call()
-        
+
         """
         try:
             if deluge.common.windows_check():
@@ -679,7 +692,7 @@ class Client(object):
     def get_bytes_recv(self):
         """
         Returns the number of bytes received from the daemon.
-        
+
         :returns: the number of bytes received
         :rtype: int
         """
@@ -688,11 +701,11 @@ class Client(object):
     def get_bytes_sent(self):
         """
         Returns the number of bytes sent to the daemon.
-        
+
         :returns: the number of bytes sent
         :rtype: int
         """
         return self._daemon_proxy.get_bytes_sent()
-        
+
 # This is the object clients will use
 client = Client()

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