[Python-modules-commits] [aioxmlrpc] 01/04: Import aioxmlrpc_0.5.orig.tar.gz
Piotr Ożarowski
piotr at moszumanska.debian.org
Fri Sep 29 07:50:02 UTC 2017
This is an automated email from the git hooks/post-receive script.
piotr pushed a commit to branch master
in repository aioxmlrpc.
commit d47460323bd7edf8814557d06cb6a16bbe1576a5
Author: Piotr Ożarowski <piotr at debian.org>
Date: Fri Sep 29 09:41:29 2017 +0200
Import aioxmlrpc_0.5.orig.tar.gz
---
CHANGES.rst | 5 ++
PKG-INFO | 9 ++-
aioxmlrpc.egg-info/PKG-INFO | 9 ++-
aioxmlrpc.egg-info/requires.txt | 2 +-
aioxmlrpc/__init__.py | 2 +-
aioxmlrpc/client.py | 76 ++++++++++++++--------
aioxmlrpc/tests/test_client.py | 135 ++++++++++++++++++++++------------------
setup.py | 3 +-
8 files changed, 151 insertions(+), 90 deletions(-)
diff --git a/CHANGES.rst b/CHANGES.rst
index ff2da85..7a88f30 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -1,6 +1,11 @@
Changelog
=========
+0.5 released on 2017-09-10
+--------------------------
+
+ * Remove compatibility with aiohttp < 1.0 (Ovv)
+
0.4 released on 2017-03-30
--------------------------
diff --git a/PKG-INFO b/PKG-INFO
index d3cf3a2..b748a13 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,11 +1,12 @@
Metadata-Version: 1.1
Name: aioxmlrpc
-Version: 0.4
+Version: 0.5
Summary: XML-RPC client for asyncio
Home-page: https://github.com/mardiros/aioxmlrpc
Author: Guillaume Gauvrit
Author-email: guillaume at gauvr.it
License: UNKNOWN
+Description-Content-Type: UNKNOWN
Description: =========
aioxmlrpc
=========
@@ -65,6 +66,11 @@ Description: =========
Changelog
=========
+ 0.5 released on 2017-09-10
+ --------------------------
+
+ * Remove compatibility with aiohttp < 1.0 (Ovv)
+
0.4 released on 2017-03-30
--------------------------
@@ -98,6 +104,7 @@ Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
+Classifier: Programming Language :: Python :: 3.6
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
diff --git a/aioxmlrpc.egg-info/PKG-INFO b/aioxmlrpc.egg-info/PKG-INFO
index d3cf3a2..b748a13 100644
--- a/aioxmlrpc.egg-info/PKG-INFO
+++ b/aioxmlrpc.egg-info/PKG-INFO
@@ -1,11 +1,12 @@
Metadata-Version: 1.1
Name: aioxmlrpc
-Version: 0.4
+Version: 0.5
Summary: XML-RPC client for asyncio
Home-page: https://github.com/mardiros/aioxmlrpc
Author: Guillaume Gauvrit
Author-email: guillaume at gauvr.it
License: UNKNOWN
+Description-Content-Type: UNKNOWN
Description: =========
aioxmlrpc
=========
@@ -65,6 +66,11 @@ Description: =========
Changelog
=========
+ 0.5 released on 2017-09-10
+ --------------------------
+
+ * Remove compatibility with aiohttp < 1.0 (Ovv)
+
0.4 released on 2017-03-30
--------------------------
@@ -98,6 +104,7 @@ Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
+Classifier: Programming Language :: Python :: 3.6
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
diff --git a/aioxmlrpc.egg-info/requires.txt b/aioxmlrpc.egg-info/requires.txt
index e1cb557..133c942 100644
--- a/aioxmlrpc.egg-info/requires.txt
+++ b/aioxmlrpc.egg-info/requires.txt
@@ -1 +1 @@
-aiohttp >= 0.20
+aiohttp>=1.0.0
diff --git a/aioxmlrpc/__init__.py b/aioxmlrpc/__init__.py
index ae86ad2..aaa20be 100644
--- a/aioxmlrpc/__init__.py
+++ b/aioxmlrpc/__init__.py
@@ -2,4 +2,4 @@
XML-RPC Protocol for ``asyncio``
"""
-__version__ = '0.4'
+__version__ = '0.5'
diff --git a/aioxmlrpc/client.py b/aioxmlrpc/client.py
index 5ed292b..e612cf9 100644
--- a/aioxmlrpc/client.py
+++ b/aioxmlrpc/client.py
@@ -6,12 +6,13 @@ work with asyncio.
"""
+import sys
import asyncio
import logging
-from xmlrpc import client as xmlrpc
-
import aiohttp
+from xmlrpc import client as xmlrpc
+
__ALL__ = ['ServerProxy', 'Fault', 'ProtocolError']
@@ -20,6 +21,7 @@ Fault = xmlrpc.Fault
ProtocolError = xmlrpc.ProtocolError
log = logging.getLogger(__name__)
+PY35 = sys.version_info >= (3, 5)
class _Method:
@@ -43,32 +45,33 @@ class AioTransport(xmlrpc.Transport):
``xmlrpc.Transport`` subclass for asyncio support
"""
- user_agent = 'python/aioxmlrpc'
-
- def __init__(self, use_https, *, use_datetime=False,
- use_builtin_types=False, loop):
+ def __init__(self, session, use_https, *, use_datetime=False,
+ use_builtin_types=False, loop, headers=None, auth=None):
super().__init__(use_datetime, use_builtin_types)
self.use_https = use_https
self._loop = loop
- self._connector = aiohttp.TCPConnector(loop=self._loop)
+ self._session = session
+
+ self.auth = auth
+
+ if not headers:
+ headers = {'User-Agent': 'python/aioxmlrpc',
+ 'Accept': 'text/xml',
+ 'Content-Type': 'text/xml'}
+
+ self.headers = headers
@asyncio.coroutine
- def request(self, host, handler, request_body, verbose):
+ def request(self, host, handler, request_body, verbose=False):
"""
Send the XML-RPC request, return the response.
This method is a coroutine.
"""
- headers = {'User-Agent': self.user_agent,
- #Proxy-Connection': 'Keep-Alive',
- #'Content-Range': 'bytes oxy1.0/-1',
- 'Accept': 'text/xml',
- 'Content-Type': 'text/xml' }
url = self._build_url(host, handler)
response = None
try:
- response = yield from aiohttp.request(
- 'POST', url, headers=headers, data=request_body,
- connector=self._connector, loop=self._loop)
+ response = yield from self._session.request(
+ 'POST', url, headers=self.headers, data=request_body, auth=self.auth)
body = yield from response.text()
if response.status != 200:
raise ProtocolError(url, response.status,
@@ -106,22 +109,30 @@ class AioTransport(xmlrpc.Transport):
scheme = 'https' if self.use_https else 'http'
return '%s://%s%s' % (scheme, host, handler)
- def close(self):
- self._connector.close()
-
class ServerProxy(xmlrpc.ServerProxy):
"""
``xmlrpc.ServerProxy`` subclass for asyncio support
"""
- def __init__(self, uri, transport=None, encoding=None, verbose=False,
- allow_none=False, use_datetime=False,use_builtin_types=False,
- loop=None):
+ def __init__(self, uri, session=None, encoding=None, verbose=False,
+ allow_none=False, use_datetime=False, use_builtin_types=False,
+ loop=None, auth=None, headers=None):
self._loop = loop or asyncio.get_event_loop()
- if not transport:
- transport = AioTransport(uri.startswith('https://'),
- loop=self._loop)
+
+ if session:
+ self._session = session
+ self._close_session = False
+ else:
+ self._close_session = True
+ self._session = aiohttp.ClientSession(loop=self._loop)
+
+ transport = AioTransport(use_https=uri.startswith('https://'),
+ loop=self._loop,
+ session=self._session,
+ auth=auth,
+ headers=headers)
+
super().__init__(uri, transport, encoding, verbose, allow_none,
use_datetime, use_builtin_types)
@@ -143,8 +154,21 @@ class ServerProxy(xmlrpc.ServerProxy):
return response
+ @asyncio.coroutine
def close(self):
- self.__transport.close()
+ if self._close_session:
+ yield from self._session.close()
def __getattr__(self, name):
return _Method(self.__request, name)
+
+ if PY35:
+
+ @asyncio.coroutine
+ def __aenter__(self):
+ return self
+
+ @asyncio.coroutine
+ def __aexit__(self, exc_type, exc_val, exc_tb):
+ if self._close_session:
+ yield from self._session.close()
diff --git a/aioxmlrpc/tests/test_client.py b/aioxmlrpc/tests/test_client.py
index 98fef6b..5134482 100644
--- a/aioxmlrpc/tests/test_client.py
+++ b/aioxmlrpc/tests/test_client.py
@@ -1,8 +1,11 @@
+import sys
+import asyncio
+import aiohttp
+
from unittest import TestCase
from unittest import mock
-import asyncio
-
+from aioxmlrpc.client import ServerProxy, ProtocolError, Fault
RESPONSES = {
@@ -15,7 +18,7 @@ RESPONSES = {
</param>
</params>
</methodResponse>"""
-},
+ },
'http://localhost/test_xmlrpc_fault': {'status': 200,
'body': """<?xml version="1.0"?>
<methodResponse>
@@ -35,15 +38,16 @@ RESPONSES = {
</fault>
</methodResponse>
"""
-},
- 'http://localhost/test_http_500': {'status': 500,
- 'body': """
+ },
+ 'http://localhost/test_http_500': {'status': 500,
+ 'body': """
I am really broken
"""
-}
+ }
- }
+}
+PY35 = sys.version_info >= (3, 5)
@asyncio.coroutine
def dummy_response(method, url, **kwargs):
@@ -63,71 +67,88 @@ def dummy_response(method, url, **kwargs):
@asyncio.coroutine
def dummy_request(*args, **kwargs):
- return dummy_response(*args, **kwargs)
+ if isinstance(args[0], aiohttp.ClientSession):
+ return dummy_response(*args[1:], **kwargs)
+ else:
+ return dummy_response(*args, **kwargs)
-class ServerProxyTestCase(TestCase):
+class ServerProxyWithSessionTestCase(TestCase):
def setUp(self):
self.loop = asyncio.new_event_loop()
- asyncio.set_event_loop(None)
- self.aiohttp_request = mock.patch('aiohttp.request', new=dummy_request)
- self.aiohttp_request.start()
+ asyncio.set_event_loop(self.loop)
+ self.session = aiohttp.ClientSession(loop=self.loop)
+ self.session.request = dummy_request
def tearDown(self):
- self.aiohttp_request.stop()
+ self.loop.run_until_complete(self.session.close())
def test_xmlrpc_ok(self):
- from aioxmlrpc.client import ServerProxy
- client = ServerProxy('http://localhost/test_xmlrpc_ok', loop=self.loop)
+ client = ServerProxy('http://localhost/test_xmlrpc_ok',
+ loop=self.loop,
+ session=self.session)
response = self.loop.run_until_complete(
client.name.space.proxfyiedcall()
- )
+ )
self.assertEqual(response, 1)
self.assertIs(self.loop, client._loop)
def test_xmlrpc_fault(self):
- from aioxmlrpc.client import ServerProxy, Fault
client = ServerProxy('http://localhost/test_xmlrpc_fault',
- loop=self.loop)
- self.assertRaises(Fault,
- self.loop.run_until_complete,
- client.name.space.proxfyiedcall()
- )
+ loop=self.loop,
+ session=self.session)
+
+ with self.assertRaises(Fault):
+ self.loop.run_until_complete(client.name.space.proxfyiedcall())
def test_http_500(self):
- from aioxmlrpc.client import ServerProxy, ProtocolError
- client = ServerProxy('http://localhost/test_http_500', loop=self.loop)
- self.assertRaises(ProtocolError,
- self.loop.run_until_complete,
- client.name.space.proxfyiedcall()
- )
+ client = ServerProxy('http://localhost/test_http_500',
+ loop=self.loop,
+ session=self.session)
+
+ with self.assertRaises(ProtocolError):
+ self.loop.run_until_complete(client.name.space.proxfyiedcall())
def test_xmlrpc_ok_global_loop(self):
- loop = asyncio.new_event_loop()
- asyncio.set_event_loop(loop)
- from aioxmlrpc.client import ServerProxy
- client = ServerProxy('http://localhost/test_xmlrpc_ok')
+ client = ServerProxy('http://localhost/test_xmlrpc_ok',
+ session=self.session)
response = self.loop.run_until_complete(
client.name.space.proxfyiedcall()
- )
- self.assertIs(loop, client._loop)
+ )
+ self.assertIs(self.loop, client._loop)
self.assertEqual(response, 1)
- def test_close_transport(self):
- from aioxmlrpc.client import ServerProxy, AioTransport
- transp = AioTransport(use_https=False, loop=self.loop)
- transp._connector.close = mock.Mock()
- client = ServerProxy('http://localhost/test_xmlrpc_ok',
- loop=self.loop, transport=transp)
- response = self.loop.run_until_complete(
- client.name.space.proxfyiedcall()
- )
- client.close()
- self.assertEqual(response, 1)
- self.assertIs(self.loop, client._loop)
- self.assertTrue(transp._connector.close.called)
+class ServerProxyWithoutSessionTestCase(TestCase):
+
+ def setUp(self):
+ self.loop = asyncio.new_event_loop()
+ asyncio.set_event_loop(self.loop)
+
+ session_request = mock.patch('aiohttp.ClientSession.request', new=dummy_request)
+ session_request.start()
+ self.addCleanup(session_request.stop)
+
+ def test_close_session(self):
+ client = ServerProxy('http://localhost/test_xmlrpc_ok',
+ loop=self.loop)
+ response = self.loop.run_until_complete(
+ client.name.space.proxfyiedcall()
+ )
+ self.assertEqual(response, 1)
+ self.assertIs(self.loop, client._loop)
+ self.loop.run_until_complete(client.close())
+
+ # def test_contextmanager(self):
+ # self.loop.run_until_complete(self.xmlrpc_with_context_manager())
+ #
+ # async def xmlrpc_with_context_manager(self):
+ # async with ServerProxy('http://localhost/test_xmlrpc_ok',
+ # loop=self.loop) as client:
+ # response = await client.name.space.proxfyiedcall()
+ # self.assertEqual(response, 1)
+ # self.assertIs(self.loop, client._loop)
@asyncio.coroutine
@@ -136,20 +157,16 @@ def failing_request(*args, **kwargs):
class HTTPErrorTestCase(TestCase):
-
def setUp(self):
self.loop = asyncio.new_event_loop()
- asyncio.set_event_loop(None)
- self.aiohttp_request = mock.patch('aiohttp.request', new=failing_request)
- self.aiohttp_request.start()
+ self.session = aiohttp.ClientSession(loop=self.loop)
+ self.session.request = failing_request
def tearDown(self):
- self.aiohttp_request.stop()
+ self.loop.run_until_complete(self.session.close())
def test_http_error(self):
- from aioxmlrpc.client import ServerProxy, ProtocolError
- client = ServerProxy('http://nonexistent/nonexistent', loop=self.loop)
- self.assertRaises(ProtocolError,
- self.loop.run_until_complete,
- client.name.space.proxfyiedcall()
- )
+ client = ServerProxy('http://nonexistent/nonexistent', loop=self.loop,
+ session=self.session)
+ with self.assertRaises(ProtocolError):
+ self.loop.run_until_complete(client.name.space.proxfyiedcall())
diff --git a/setup.py b/setup.py
index 8c29b6b..34ab5cb 100644
--- a/setup.py
+++ b/setup.py
@@ -20,7 +20,7 @@ with open(os.path.join(here, NAME, '__init__.py')) as version:
re.S).match(version.read()).group(1)
-requires = ['aiohttp >= 0.20']
+requires = ['aiohttp >= 1.0.0']
if py_version < (3, 4):
requires.append('asyncio')
@@ -34,6 +34,7 @@ setup(name=NAME,
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
+ 'Programming Language :: Python :: 3.6',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License'
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/aioxmlrpc.git
More information about the Python-modules-commits
mailing list