aioxmlrpc-0.1/0000755000175000001440000000000012335736134014522 5ustar guillaumeusers00000000000000aioxmlrpc-0.1/LICENSE0000644000175000001440000000276012335650421015526 0ustar guillaumeusers00000000000000Copyright (c) 2014, Guillaume Gauvrit and Contibutors All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. aioxmlrpc-0.1/aioxmlrpc/0000755000175000001440000000000012335736134016520 5ustar guillaumeusers00000000000000aioxmlrpc-0.1/aioxmlrpc/client.py0000644000175000001440000000770112335710347020353 0ustar guillaumeusers00000000000000""" XML-RPC Client with asyncio. This module adapt the ``xmlrpc.client`` module of the standard library to work with asyncio. """ import asyncio import logging from xmlrpc import client as xmlrpc import aiohttp __ALL__ = ['ServerProxy', 'Fault', 'ProtocolError'] # you don't have to import xmlrpc.client from your code Fault = xmlrpc.Fault ProtocolError = xmlrpc.ProtocolError 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)) @asyncio.coroutine def __call__(self, *args): ret = yield from self.__send(self.__name, args) return ret 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): super().__init__(use_datetime, use_builtin_types) self.use_https = use_https @asyncio.coroutine def request(self, host, handler, request_body, verbose): """ 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) body = yield from response.read_and_close() if response.status != 200: raise ProtocolError(url, response.status, body, response.headers) except ProtocolError: raise except Exception as exc: log.error('Unexpected error', exc_info=True) raise ProtocolError(url, response.status, str(exc), response.headers) return self.parse_response(body) def parse_response(self, body): """ Parse the xmlrpc response. """ p, u = self.getparser() p.feed(body) p.close() return u.close() def _build_url(self, host, handler): """ Build a url for our request based on the host, handler and use_http property """ scheme = 'https' if self.use_https else 'http' return '%s://%s%s' % (scheme, host, handler) 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): if not transport: transport = AioTransport(uri.startswith('https://')) super().__init__(uri, transport, encoding, verbose, allow_none, use_datetime, use_builtin_types) @asyncio.coroutine def __request(self, methodname, params): # call a method on the remote server request = xmlrpc.dumps(params, methodname, encoding=self.__encoding, allow_none=self.__allow_none).encode(self.__encoding) response = yield from self.__transport.request( self.__host, self.__handler, request, verbose=self.__verbose ) if len(response) == 1: response = response[0] return response def __getattr__(self, name): return _Method(self.__request, name) aioxmlrpc-0.1/aioxmlrpc/tests/0000755000175000001440000000000012335736134017662 5ustar guillaumeusers00000000000000aioxmlrpc-0.1/aioxmlrpc/tests/__init__.py0000644000175000001440000000005312335650653021772 0ustar guillaumeusers00000000000000""" Test suite for the aioxmlrpc module """aioxmlrpc-0.1/aioxmlrpc/tests/test_client.py0000644000175000001440000000530112335650421022542 0ustar guillaumeusers00000000000000from unittest import TestCase from unittest import mock import asyncio RESPONSES = { 'http://localhost/test_xmlrpc_ok': {'status': 200, 'body': """ 1 """ }, 'http://localhost/test_xmlrpc_fault': {'status': 200, 'body': """ faultCode 4 faultString You are not lucky """ }, 'http://localhost/test_http_500': {'status': 500, 'body': """ I am really broken """ } } @asyncio.coroutine def dummy_response(method, url, **kwargs): class Response: def __init__(self): response = RESPONSES[url] self.status = response['status'] self.body = response['body'] self.headers = {} @asyncio.coroutine def read_and_close(self): return self.body return Response() @asyncio.coroutine def dummy_request(*args, **kwargs): return dummy_response(*args, **kwargs) class ServerProxyTestCase(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() def tearDown(self): self.aiohttp_request.stop() def test_xmlrpc_ok(self): from aioxmlrpc.client import ServerProxy client = ServerProxy('http://localhost/test_xmlrpc_ok') response = self.loop.run_until_complete( client.name.space.proxfyiedcall() ) self.assertEqual(response, 1) def test_xmlrpc_fault(self): from aioxmlrpc.client import ServerProxy, Fault client = ServerProxy('http://localhost/test_xmlrpc_fault') 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') self.assertRaises(ProtocolError, self.loop.run_until_complete, client.name.space.proxfyiedcall() ) aioxmlrpc-0.1/aioxmlrpc/__init__.py0000644000175000001440000000007612335710557020635 0ustar guillaumeusers00000000000000""" XML-RPC Protocol for ``asyncio`` """ __version__ = '0.1' aioxmlrpc-0.1/PKG-INFO0000644000175000001440000000425312335736134015623 0ustar guillaumeusers00000000000000Metadata-Version: 1.1 Name: aioxmlrpc Version: 0.1 Summary: XML-RPC for asyncio Home-page: https://github.com/mardiros/aioxmlrpc Author: Guillaume Gauvrit Author-email: guillaume@gauvr.it License: UNKNOWN Description: ========= aioxmlrpc ========= .. image:: https://travis-ci.org/mardiros/aioxmlrpc.png?branch=master :target: https://travis-ci.org/mardiros/aioxmlrpc Getting Started =============== Asyncio version of the standard lib ``xmlrpc`` Currently only ``aioxmlrpc.client``, which works like ``xmlrpc.client`` but with coroutine is implemented. Fill free to fork me if you want to implement the server part. ``aioxmlrpc`` is based on ``aiohttp`` for the transport, and just patch the necessary from the python standard library to get it working. Installation ------------ :: pip install aioxmlrpc Exemple of usage ---------------- This example show how to print the current version of the Gandi XML-RPC api. :: @asyncio.coroutine def print_gandi_api_version(): api = ServerProxy('https://rpc.gandi.net/xmlrpc/') result = yield from api.version.info() print(result) if __name__ == '__main__': loop = asyncio.get_event_loop() loop.run_until_complete(print_gandi_api_version()) loop.stop() Changelist ========== 0.1 released on 2014-05-17 -------------------------- * Initial version implementing ``aioxmlrpc.client`` Keywords: asyncaio xml-rpc rpc Platform: UNKNOWN Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Environment :: Web Environment Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License aioxmlrpc-0.1/setup.cfg0000644000175000001440000000007312335736134016343 0ustar guillaumeusers00000000000000[egg_info] tag_build = tag_date = 0 tag_svn_revision = 0 aioxmlrpc-0.1/README.rst0000644000175000001440000000205112335711500016175 0ustar guillaumeusers00000000000000========= aioxmlrpc ========= .. image:: https://travis-ci.org/mardiros/aioxmlrpc.png?branch=master :target: https://travis-ci.org/mardiros/aioxmlrpc Getting Started =============== Asyncio version of the standard lib ``xmlrpc`` Currently only ``aioxmlrpc.client``, which works like ``xmlrpc.client`` but with coroutine is implemented. Fill free to fork me if you want to implement the server part. ``aioxmlrpc`` is based on ``aiohttp`` for the transport, and just patch the necessary from the python standard library to get it working. Installation ------------ :: pip install aioxmlrpc Exemple of usage ---------------- This example show how to print the current version of the Gandi XML-RPC api. :: @asyncio.coroutine def print_gandi_api_version(): api = ServerProxy('https://rpc.gandi.net/xmlrpc/') result = yield from api.version.info() print(result) if __name__ == '__main__': loop = asyncio.get_event_loop() loop.run_until_complete(print_gandi_api_version()) loop.stop() aioxmlrpc-0.1/aioxmlrpc.egg-info/0000755000175000001440000000000012335736134020212 5ustar guillaumeusers00000000000000aioxmlrpc-0.1/aioxmlrpc.egg-info/dependency_links.txt0000644000175000001440000000000112335736134024260 0ustar guillaumeusers00000000000000 aioxmlrpc-0.1/aioxmlrpc.egg-info/PKG-INFO0000644000175000001440000000425312335736134021313 0ustar guillaumeusers00000000000000Metadata-Version: 1.1 Name: aioxmlrpc Version: 0.1 Summary: XML-RPC for asyncio Home-page: https://github.com/mardiros/aioxmlrpc Author: Guillaume Gauvrit Author-email: guillaume@gauvr.it License: UNKNOWN Description: ========= aioxmlrpc ========= .. image:: https://travis-ci.org/mardiros/aioxmlrpc.png?branch=master :target: https://travis-ci.org/mardiros/aioxmlrpc Getting Started =============== Asyncio version of the standard lib ``xmlrpc`` Currently only ``aioxmlrpc.client``, which works like ``xmlrpc.client`` but with coroutine is implemented. Fill free to fork me if you want to implement the server part. ``aioxmlrpc`` is based on ``aiohttp`` for the transport, and just patch the necessary from the python standard library to get it working. Installation ------------ :: pip install aioxmlrpc Exemple of usage ---------------- This example show how to print the current version of the Gandi XML-RPC api. :: @asyncio.coroutine def print_gandi_api_version(): api = ServerProxy('https://rpc.gandi.net/xmlrpc/') result = yield from api.version.info() print(result) if __name__ == '__main__': loop = asyncio.get_event_loop() loop.run_until_complete(print_gandi_api_version()) loop.stop() Changelist ========== 0.1 released on 2014-05-17 -------------------------- * Initial version implementing ``aioxmlrpc.client`` Keywords: asyncaio xml-rpc rpc Platform: UNKNOWN Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Environment :: Web Environment Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License aioxmlrpc-0.1/aioxmlrpc.egg-info/not-zip-safe0000644000175000001440000000000112335650421022432 0ustar guillaumeusers00000000000000 aioxmlrpc-0.1/aioxmlrpc.egg-info/top_level.txt0000644000175000001440000000001212335736134022735 0ustar guillaumeusers00000000000000aioxmlrpc aioxmlrpc-0.1/aioxmlrpc.egg-info/SOURCES.txt0000644000175000001440000000053412335736134022100 0ustar guillaumeusers00000000000000CHANGES.rst LICENSE MANIFEST.in README.rst setup.py aioxmlrpc/__init__.py aioxmlrpc/client.py aioxmlrpc.egg-info/PKG-INFO aioxmlrpc.egg-info/SOURCES.txt aioxmlrpc.egg-info/dependency_links.txt aioxmlrpc.egg-info/not-zip-safe aioxmlrpc.egg-info/requires.txt aioxmlrpc.egg-info/top_level.txt aioxmlrpc/tests/__init__.py aioxmlrpc/tests/test_client.pyaioxmlrpc-0.1/aioxmlrpc.egg-info/requires.txt0000644000175000001440000000000712335736134022607 0ustar guillaumeusers00000000000000aiohttpaioxmlrpc-0.1/setup.py0000644000175000001440000000272612335712003016230 0ustar guillaumeusers00000000000000import os import re import sys from setuptools import setup, find_packages py_version = sys.version_info[:2] if py_version < (3, 3): raise RuntimeError('Unsupported Python version. Python 3.3+ required') here = os.path.abspath(os.path.dirname(__file__)) NAME = 'aioxmlrpc' with open(os.path.join(here, 'README.rst')) as readme: README = readme.read() with open(os.path.join(here, 'CHANGES.rst')) as changes: CHANGES = changes.read() with open(os.path.join(here, NAME, '__init__.py')) as version: VERSION = re.compile(r".*__version__ = '(.*?)'", re.S).match(version.read()).group(1) requires = ['aiohttp'] if py_version < (3, 4): requires.append('asyncio') setup(name=NAME, version=VERSION, description='XML-RPC for asyncio', long_description=README + '\n\n' + CHANGES, classifiers=[ 'Programming Language :: Python', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Environment :: Web Environment', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License' ], author='Guillaume Gauvrit', author_email='guillaume@gauvr.it', url='https://github.com/mardiros/aioxmlrpc', keywords='asyncaio xml-rpc rpc', packages=find_packages(), include_package_data=True, zip_safe=False, test_suite='{}.tests'.format(NAME), install_requires=requires ) aioxmlrpc-0.1/MANIFEST.in0000644000175000001440000000007012335650421016247 0ustar guillaumeusers00000000000000include LICENSE include *.rst recursive-exclude . *.pyc aioxmlrpc-0.1/CHANGES.rst0000644000175000001440000000020312335712255016315 0ustar guillaumeusers00000000000000Changelist ========== 0.1 released on 2014-05-17 -------------------------- * Initial version implementing ``aioxmlrpc.client``