From c399f7c9b3b7d159714dd8db78f89502b9b2ef31 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Sun, 1 Feb 2009 20:39:07 +0000 Subject: [PATCH] Move the list_methods rpc to the daemon object and rename it to 'get_method_list' --- deluge/core/daemon.py | 7 +++++++ deluge/core/rpcserver.py | 36 +++++++++++++++++++----------------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/deluge/core/daemon.py b/deluge/core/daemon.py index fec03c232..a3b33c670 100644 --- a/deluge/core/daemon.py +++ b/deluge/core/daemon.py @@ -118,3 +118,10 @@ class Daemon(object): :returns: str, the version number """ return deluge.common.get_version() + + @export() + def get_method_list(self): + """ + Returns a list of the exported methods. + """ + return self.rpccserver.get_method_list() diff --git a/deluge/core/rpcserver.py b/deluge/core/rpcserver.py index 617b94f82..e4b92bcc2 100644 --- a/deluge/core/rpcserver.py +++ b/deluge/core/rpcserver.py @@ -1,7 +1,7 @@ # # rpcserver.py # -# Copyright (C) 2008 Andrew Resch +# Copyright (C) 2008,2009 Andrew Resch # # Deluge is free software. # @@ -200,20 +200,6 @@ class DelugeRPCProtocol(Protocol): self.transport.loseConnection() finally: return - elif method == "daemon.list_methods": - # This is a method used to populate the json-rpc interface in the - # webui - try: - ret = self.factory.methods.keys() - except Exception, e: - # Send error packet here - log.exception(e) - else: - self.sendData((RPC_RESPONSE, request_id, (ret))) - if not ret: - self.transport.loseConnection() - finally: - return if method in self.factory.methods: try: @@ -306,18 +292,34 @@ class RPCServer(component.Component): if not name: name = obj.__class__.__name__.lower() - log.debug("dir: %s", dir(obj)) for d in dir(obj): if d[0] == "_": continue if getattr(getattr(obj, d), '_rpcserver_export', False): log.debug("Registering method: %s", name + "." + d) - #self.server.register_function(getattr(obj, d), name + "." + d) self.factory.methods[name + "." + d] = getattr(obj, d) def get_object_method(self, name): + """ + Returns a registered method. + + :param name: str, the name of the method, usually in the form of 'object.method' + + :returns: method + + :raises KeyError: if `:param:name` is not registered + + """ return self.factory.methods[name] + def get_method_list(self): + """ + Returns a list of the exported methods. + + :returns: list, the exported methods + """ + return self.factory.methods.keys() + def __generate_ssl_keys(self): """ This method generates a new SSL key/cert.