diff --git a/deluge/core/eventmanager.py b/deluge/core/eventmanager.py index b4aa1759a..0f616457f 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 3fbae6e6f..f040244b4 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()