diff --git a/aiohttp_xmlrpc/handler.py b/aiohttp_xmlrpc/handler.py index 734b824..5b22800 100644 --- a/aiohttp_xmlrpc/handler.py +++ b/aiohttp_xmlrpc/handler.py @@ -43,7 +43,11 @@ def __new__(cls, clsname, superclasses, attributedict): continue value = getattr(instance, key) - method_name = key.replace(instance.METHOD_PREFIX, "", 1) + + method_name = getattr(value, "__xmlrpc_name__", None) + if method_name is None: + method_name = key.replace(instance.METHOD_PREFIX, "", 1) + allowed_methods[method_name] = key argmapping[method_name] = inspect.getfullargspec(value) @@ -185,3 +189,10 @@ def _build_xml(cls, tree): encoding="utf-8", pretty_print=cls.DEBUG, ) + + +def rename(new_name): + def decorator(func): + func.__xmlrpc_name__ = new_name + return func + return decorator diff --git a/tests/test_handler.py b/tests/test_handler.py index 60f6916..bb5532f 100644 --- a/tests/test_handler.py +++ b/tests/test_handler.py @@ -8,6 +8,7 @@ from lxml import etree from lxml.builder import E +from aiohttp_xmlrpc.handler import rename pytest_plugins = ( "aiohttp.pytest_plugin", @@ -52,6 +53,10 @@ def rpc_dict_kwargs(self, d, **kw): def rpc_dict_kw_only_args(self, d, *, foo, **kw): return (d, foo, kw) + @rename("method_with.new_name") + def rpc_ranamed(self): + return "renamed_function" + class XMLRPCChild(XMLRPCMain): def rpc_child(self): @@ -214,3 +219,8 @@ async def test_13_kw_only_args(client): {"foo": "bar"}, foo=32, spam="egg" ) assert result == [{"foo": "bar"}, 32, {"spam": "egg"}] + + +async def test_14_method_renaming(client): + result = await client.method_with.new_name() + assert result == "renamed_function"