diff --git a/rpc/__pycache__/util.cpython-312.pyc b/rpc/__pycache__/util.cpython-312.pyc new file mode 100644 index 0000000..b3ba4aa Binary files /dev/null and b/rpc/__pycache__/util.cpython-312.pyc differ diff --git a/rpc/aioxmlrpc/__pycache__/client.cpython-312.pyc b/rpc/aioxmlrpc/__pycache__/client.cpython-312.pyc new file mode 100644 index 0000000..d832269 Binary files /dev/null and b/rpc/aioxmlrpc/__pycache__/client.cpython-312.pyc differ diff --git a/rpc/aioxmlrpc/client.py b/rpc/aioxmlrpc/client.py index e612cf9..ab73451 100644 --- a/rpc/aioxmlrpc/client.py +++ b/rpc/aioxmlrpc/client.py @@ -10,9 +10,21 @@ import sys import asyncio import logging import aiohttp +import inspect +import functools from xmlrpc import client as xmlrpc +def coroutine(fn): + if inspect.iscoroutinefunction(fn): + return fn + + @functools.wraps(fn) + async def _wrapper(*args, **kwargs): + return fn(*args, **kwargs) + + return _wrapper + __ALL__ = ['ServerProxy', 'Fault', 'ProtocolError'] @@ -34,7 +46,7 @@ class _Method: def __getattr__(self, name): return _Method(self.__send, "%s.%s" % (self.__name, name)) - @asyncio.coroutine + @coroutine def __call__(self, *args): ret = yield from self.__send(self.__name, args) return ret @@ -61,7 +73,7 @@ class AioTransport(xmlrpc.Transport): self.headers = headers - @asyncio.coroutine + @coroutine def request(self, host, handler, request_body, verbose=False): """ Send the XML-RPC request, return the response. @@ -136,7 +148,7 @@ class ServerProxy(xmlrpc.ServerProxy): super().__init__(uri, transport, encoding, verbose, allow_none, use_datetime, use_builtin_types) - @asyncio.coroutine + @coroutine def __request(self, methodname, params): # call a method on the remote server request = xmlrpc.dumps(params, methodname, encoding=self.__encoding, @@ -154,7 +166,7 @@ class ServerProxy(xmlrpc.ServerProxy): return response - @asyncio.coroutine + @coroutine def close(self): if self._close_session: yield from self._session.close() @@ -164,11 +176,11 @@ class ServerProxy(xmlrpc.ServerProxy): if PY35: - @asyncio.coroutine + @coroutine def __aenter__(self): return self - @asyncio.coroutine + @coroutine def __aexit__(self, exc_type, exc_val, exc_tb): if self._close_session: yield from self._session.close() diff --git a/rpc/rpc_pi_async_runner.py b/rpc/rpc_pi_async_runner.py index c1b0a3a..54b51c1 100644 --- a/rpc/rpc_pi_async_runner.py +++ b/rpc/rpc_pi_async_runner.py @@ -15,7 +15,8 @@ async def remote_estimate(n): # Create the proxy in a nice way so it gets closed when we are done. async with ServerProxy('http://localhost:9000') as proxy: pi_remote = await proxy.estimate_pi(n) - print(f"Result of remote estimation: pi={pi_remote:.010f}") + # print(f"Result of remote estimation: pi={pi_remote:.010f}") + print(pi_remote) return pi_remote