From 24c945f139a2f5fa15d8386442afe4be0fde03b0 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Mon, 6 Jun 2011 13:55:51 -0700 Subject: [PATCH] Add a RPCServer.deregister method Deregister RPC exports when disabling a Core plugin --- deluge/core/rpcserver.py | 11 +++++++++++ deluge/plugins/pluginbase.py | 3 +++ 2 files changed, 14 insertions(+) diff --git a/deluge/core/rpcserver.py b/deluge/core/rpcserver.py index e2069360a..93315d4a7 100644 --- a/deluge/core/rpcserver.py +++ b/deluge/core/rpcserver.py @@ -424,6 +424,17 @@ class RPCServer(component.Component): log.debug("Registering method: %s", name + "." + d) self.factory.methods[name + "." + d] = getattr(obj, d) + def deregister_object(self, obj): + """ + Deregisters an objects exported rpc methods. + + :param obj: the object that was previously registered + + """ + for key, value in self.factory.methods.items(): + if value.im_self == obj: + del self.factory.methods[key] + def get_object_method(self, name): """ Returns a registered method. diff --git a/deluge/plugins/pluginbase.py b/deluge/plugins/pluginbase.py index a59aab754..cdabcf6bd 100644 --- a/deluge/plugins/pluginbase.py +++ b/deluge/plugins/pluginbase.py @@ -58,6 +58,9 @@ class CorePluginBase(PluginBase): component.get("RPCServer").register_object(self, plugin_name.lower()) log.debug("CorePlugin initialized..") + def __del__(self): + component.get("RPCServer").deregister_object(self) + class GtkPluginBase(PluginBase): def __init__(self, plugin_name): super(GtkPluginBase, self).__init__("GtkPlugin." + plugin_name)