Comments (7)
Actually I've just noticed that a workaround exists for this problem!
I just have to call explicitly the getattr()
function...
# Get the list of available devices
# First attempt (not working)
# devices = await async_client.scheduler.devices.list()
# Second attempt (working)
devices = await getattr(async_client, "scheduler.devices.list")()
from aiohttp-xmlrpc.
It is not very difficult to implement, rather it is difficult to implement correctly.
For example, there is a class A
with the foo
method, should a call to the A.foo
instantiate class A
and with what parameters?
from aiohttp-xmlrpc.
I am not sure that I completely understood your question.
For my specific need, the full name of the method (with the point) needs to be passed to the <methodName>
field in the body of the HTTP request.
So, no needs to instantiate the "class A" method, only pass the following method in the HTTP request:
<?xml version='1.0' encoding='ASCII'?>
<methodCall><methodName>A.foo</methodName><params/></methodCall>
It is basically what the (synchronous) xmlrpc
library built-in python 3 does. As we can see here:
- https://github.com/python/cpython/blob/628667ac9a634c7a7fa7f681dd2f98ff5841c843/Lib/xmlrpc/client.py#L1482
- https://github.com/python/cpython/blob/628667ac9a634c7a7fa7f681dd2f98ff5841c843/Lib/xmlrpc/client.py#L1113
from aiohttp-xmlrpc.
Well, try to imagine a code example that would work both from the server-side and from the client-side, and write it here.
from aiohttp-xmlrpc.
Okay, I thing I get your point now. It will be easier to do that on the client-side than on the server-side.
I will see what I can do about that.
from aiohttp-xmlrpc.
Hi again Mosquito,
So I've seen with my hierarchy today and since we have a lot of work currently and that we are not using the server-side of aiohttp-xmlrpc, I cannot spend time "right now" on the server-side of this feature. Nevertheless, I could go back on it later when the peak of activities will have been passed.
In the mid-time, I can do a pull request with the correction I have done on the client side. The modifications I plan to add are in the following patch:
From f47ace384e953db25a8f95560cf32645bcbe68e9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Armand=20B=C3=A9n=C3=A9teau?= <[email protected]>
Date: Mon, 15 Nov 2021 15:25:46 +0000
Subject: [PATCH] Allow nested methods to be called on client side
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Armand Bénéteau <[email protected]>
---
aiohttp_xmlrpc/client.py | 29 +++++++++++++++++++++--------
1 file changed, 21 insertions(+), 8 deletions(-)
diff --git a/aiohttp_xmlrpc/client.py b/aiohttp_xmlrpc/client.py
index 2047d74..ed1440d 100644
--- a/aiohttp_xmlrpc/client.py
+++ b/aiohttp_xmlrpc/client.py
@@ -12,6 +12,20 @@ from .exceptions import xml2py_exception
log = logging.getLogger(__name__)
+class _Method:
+ # some magic to bind an XML-RPC method to an RPC server.
+ # supports "nested" methods (e.g. examples.getStateName)
+ def __init__(self, send, name):
+ self.__send = send
+ self.__name = name
+
+ def __getattr__(self, name):
+ return _Method(self.__send, "%s.%s" % (self.__name, name))
+
+ def __call__(self, *args, **kwargs):
+ return self.__send(self.__name, args, kwargs)
+
+
class ServerProxy(object):
__slots__ = "client", "url", "loop", "headers", "encoding", "huge_tree"
@@ -107,13 +121,12 @@ class ServerProxy(object):
return self._parse_response((await response.read()), method_name)
def __getattr__(self, method_name):
- return self[method_name]
-
- def __getitem__(self, method_name):
- def method(*args, **kwargs):
- return self.__remote_call(method_name, *args, **kwargs)
-
- return method
+ # Trick to keep the "close" method available
+ if method_name == "close":
+ return self.__close
+ else:
+ # Magic method dispatcher
+ return _Method(self.__remote_call, method_name)
def __aenter__(self):
return self.client.__aenter__()
@@ -121,5 +134,5 @@ class ServerProxy(object):
def __aexit__(self, exc_type, exc_val, exc_tb):
return self.client.__aexit__(exc_type, exc_val, exc_tb)
- def close(self):
+ def __close(self):
return self.client.close()
--
2.27.0
from aiohttp-xmlrpc.
Ok. Just open PR and let’s continue this dialogue there.
from aiohttp-xmlrpc.
Related Issues (15)
- PyPI version
- TypeError raised when response contains an empty base64 tag
- Multiple result is not parsed
- Add support for Python 3.6/3.7 and aiohttp 3+ HOT 1
- kwargs parsing seems incorrect HOT 3
- Remove @asyncio.coroutine + 3.4 Support HOT 4
- Problems closing aiohttp-xmlrpc aiohttps clients cleanly HOT 1
- FileNotFound when install 0.4.0 HOT 1
- 1.2.0 Wheel release
- Support for system.multicall HOT 3
- Support for introspection api
- Empty string values become the string literal "None" HOT 1
- Custom User Agent HOT 4
- Limited XXE attack ability
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aiohttp-xmlrpc.