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

This commit is contained in:
Pedro Algarvio 2010-12-10 04:59:05 +00:00
parent 1c7676bfe5
commit e52018bfcd
2 changed files with 38 additions and 13 deletions

View File

@ -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):
"""

View File

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