step 1.5: abandon due to differing async versions
This commit is contained in:
parent
9aec9332fc
commit
1044d6224a
Binary file not shown.
Binary file not shown.
|
|
@ -10,9 +10,21 @@ import sys
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
import inspect
|
||||||
|
import functools
|
||||||
|
|
||||||
from xmlrpc import client as xmlrpc
|
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']
|
__ALL__ = ['ServerProxy', 'Fault', 'ProtocolError']
|
||||||
|
|
||||||
|
|
@ -34,7 +46,7 @@ class _Method:
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
return _Method(self.__send, "%s.%s" % (self.__name, name))
|
return _Method(self.__send, "%s.%s" % (self.__name, name))
|
||||||
|
|
||||||
@asyncio.coroutine
|
@coroutine
|
||||||
def __call__(self, *args):
|
def __call__(self, *args):
|
||||||
ret = yield from self.__send(self.__name, args)
|
ret = yield from self.__send(self.__name, args)
|
||||||
return ret
|
return ret
|
||||||
|
|
@ -61,7 +73,7 @@ class AioTransport(xmlrpc.Transport):
|
||||||
|
|
||||||
self.headers = headers
|
self.headers = headers
|
||||||
|
|
||||||
@asyncio.coroutine
|
@coroutine
|
||||||
def request(self, host, handler, request_body, verbose=False):
|
def request(self, host, handler, request_body, verbose=False):
|
||||||
"""
|
"""
|
||||||
Send the XML-RPC request, return the response.
|
Send the XML-RPC request, return the response.
|
||||||
|
|
@ -136,7 +148,7 @@ class ServerProxy(xmlrpc.ServerProxy):
|
||||||
super().__init__(uri, transport, encoding, verbose, allow_none,
|
super().__init__(uri, transport, encoding, verbose, allow_none,
|
||||||
use_datetime, use_builtin_types)
|
use_datetime, use_builtin_types)
|
||||||
|
|
||||||
@asyncio.coroutine
|
@coroutine
|
||||||
def __request(self, methodname, params):
|
def __request(self, methodname, params):
|
||||||
# call a method on the remote server
|
# call a method on the remote server
|
||||||
request = xmlrpc.dumps(params, methodname, encoding=self.__encoding,
|
request = xmlrpc.dumps(params, methodname, encoding=self.__encoding,
|
||||||
|
|
@ -154,7 +166,7 @@ class ServerProxy(xmlrpc.ServerProxy):
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@asyncio.coroutine
|
@coroutine
|
||||||
def close(self):
|
def close(self):
|
||||||
if self._close_session:
|
if self._close_session:
|
||||||
yield from self._session.close()
|
yield from self._session.close()
|
||||||
|
|
@ -164,11 +176,11 @@ class ServerProxy(xmlrpc.ServerProxy):
|
||||||
|
|
||||||
if PY35:
|
if PY35:
|
||||||
|
|
||||||
@asyncio.coroutine
|
@coroutine
|
||||||
def __aenter__(self):
|
def __aenter__(self):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
@asyncio.coroutine
|
@coroutine
|
||||||
def __aexit__(self, exc_type, exc_val, exc_tb):
|
def __aexit__(self, exc_type, exc_val, exc_tb):
|
||||||
if self._close_session:
|
if self._close_session:
|
||||||
yield from self._session.close()
|
yield from self._session.close()
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,8 @@ async def remote_estimate(n):
|
||||||
# Create the proxy in a nice way so it gets closed when we are done.
|
# Create the proxy in a nice way so it gets closed when we are done.
|
||||||
async with ServerProxy('http://localhost:9000') as proxy:
|
async with ServerProxy('http://localhost:9000') as proxy:
|
||||||
pi_remote = await proxy.estimate_pi(n)
|
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
|
return pi_remote
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue