Dont make code that still uses the old "TorrentAddedEvent" fail, instead log a warning and make it work.
This commit is contained in:
parent
1c7676bfe5
commit
e52018bfcd
|
@ -53,7 +53,19 @@ class EventManager(component.Component):
|
||||||
if event.name in self.handlers:
|
if event.name in self.handlers:
|
||||||
for handler in self.handlers[event.name]:
|
for handler in self.handlers[event.name]:
|
||||||
#log.debug("Running handler %s for event %s with args: %s", event.name, handler, event.args)
|
#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):
|
def register_event_handler(self, event, handler):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -167,9 +167,22 @@ class DelugeRPCProtocol(Protocol):
|
||||||
#log.debug("Received RPCEvent: %s", event)
|
#log.debug("Received RPCEvent: %s", event)
|
||||||
# A RPCEvent was received from the daemon so run any handlers
|
# A RPCEvent was received from the daemon so run any handlers
|
||||||
# associated with it.
|
# 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:
|
if event in self.factory.event_handlers:
|
||||||
for handler in self.factory.event_handlers[event]:
|
for handler in self.factory.event_handlers[event]:
|
||||||
reactor.callLater(0, handler, *request[2])
|
reactor.callLater(0, call_handler, event, handler, request[2])
|
||||||
continue
|
continue
|
||||||
|
|
||||||
request_id = request[1]
|
request_id = request[1]
|
||||||
|
|
Loading…
Reference in New Issue