{ "info": { "author": "Jeff Rand", "author_email": "jeff.rand@axial.net", "bugtrack_url": null, "classifiers": [], "description": "==============\nrpc_exceptions\n==============\n\nSimple, transparent, name-spaced exceptions across JSON-RPC services.\n\nInstalling\n==========\n\nThe rpc_exceptions project lives on github_, and is available via pip_.\n\n.. _github: https://github.com/axialmarket/rpc_exceptions\n.. _pip: https://pypi.python.org/pypi/rpc_exceptions/0.1\n\nInstalling v0.1 From Pip\n------------------------\n\n::\n\n sudo pip install rpc_exceptions==0.1\n\nInstalling v0.1 From Source\n---------------------------\n\n::\n\n curl https://github.com/axialmarket/rpc_exceptions/achive/version_0.1.tar.gz | tar vzxf -\n cd rpc_exceptions\n sudo python setup.py install\n\nExamples\n========\n\nDefine a base exception with an api_name, exceptions for that API, and instantiate `RPCExceptionHandler` with those exceptions:\n\n::\n\n from rpc_exceptions import RPCExceptionHandler, WrappedRPCError\n\n class TestError(WrappedRPCError):\n api_name = 'test'\n\n class PEBCAKError(TestError):\n code = -1\n _default_message = 'Problem exists between chair and keyboard'\n\n class FUBARError(TestError):\n code = -2\n _default_message = 'FUBARed'\n\n error_handler = RPCExceptionHandler([ PEBCAKError, FUBARError ])\n\nDecorate exposed functions with the instantiated RPCExceptionHandler's wrap_rpc_exception decorator:\n\n::\n\n from wrapped_rpc.exceptions import error_handler, PEBCAKError, FUBARError\n @error_handler.wrap_rpc_exception\n def fail1(arg):\n raise PEBCAKError\n\n @error_handler.wrap_rpc_exception\n def fail2(arg):\n raise FUBARError\n\nCoerce error codes and messages to exceptions the instantiated RPCExceptionHandler's get_exception_instance method:\n\n::\n\n #client using tinyrpc\n from wrapped_rpc.exceptions import error_handler, PEBCAKError, FUBARError\n from tinyrpc import RPCClient, RPCError\n from tinyrpc.protocols.jsonrpc import JSONRPCProtocol\n from tinyrpc.transports.http import HttpPostClientTransport\n\n class WrappedRPCClient(RPCClient):\n def __init__(self, protocol, transport, api_name):\n self.protocol = protocol\n self.transport = transport\n self.api_name = api_name\n\n def _send_and_handle_reply(self, req):\n reply = self.transport.send_message(req.serialize())\n response = self.protocol.parse_reply(reply)\n if hasattr(response, 'error'):\n try:\n raise error_handler.get_exception_instance(\n response._jsonrpc_error_code,\n self.api_name, response.error)\n except KeyError:\n raise RPCError('Error calling remote procedure: %s' %\\\n response.error)\n return response\n\n rpc_client = WrappedRPCClient(\n JSONRPCProtocol(),\n HttpPostClientTransport('http://localhost:1234'),\n 'test'\n )\n server = rpc_client.get_proxy()\n\n try:\n server.fail1('foo')\n except PEBCAKError as e:\n print 'code: %s, message: %s' % (e.code, e.msg)\n\n try:\n server.fail2('bar')\n except FUBARError as e:\n print 'code: %s, message: %s' % (e.code, e.msg)\n\nLicense\n=======\n\nBSD, See LICENSE.txt_\n\n.. _LICENSE.txt: https://github.com/axialmarket/rpc_exceptions/blob/master/LICENSE.txt", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/axialmarket/rpc_exceptions", "keywords": null, "license": "3-BSD", "maintainer": null, "maintainer_email": null, "name": "rpc_exceptions", "package_url": "https://pypi.org/project/rpc_exceptions/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/rpc_exceptions/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/axialmarket/rpc_exceptions" }, "release_url": "https://pypi.org/project/rpc_exceptions/0.1/", "requires_dist": null, "requires_python": null, "summary": "RPC Exceptions", "version": "0.1" }, "last_serial": 1075475, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "4b6a647b278cd97095ea505cb16159eb", "sha256": "eb40500c497014cccffc7fcbb1e274073eb10e8d79bf1cae62f65baed2114d63" }, "downloads": -1, "filename": "rpc_exceptions-0.1.tar.gz", "has_sig": false, "md5_digest": "4b6a647b278cd97095ea505cb16159eb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3774, "upload_time": "2014-04-29T13:39:46", "url": "https://files.pythonhosted.org/packages/fa/89/cad1332eace9bf167cd13977aced8a4f7e486b9cd28fcc7a7ab711fb20e7/rpc_exceptions-0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "4b6a647b278cd97095ea505cb16159eb", "sha256": "eb40500c497014cccffc7fcbb1e274073eb10e8d79bf1cae62f65baed2114d63" }, "downloads": -1, "filename": "rpc_exceptions-0.1.tar.gz", "has_sig": false, "md5_digest": "4b6a647b278cd97095ea505cb16159eb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3774, "upload_time": "2014-04-29T13:39:46", "url": "https://files.pythonhosted.org/packages/fa/89/cad1332eace9bf167cd13977aced8a4f7e486b9cd28fcc7a7ab711fb20e7/rpc_exceptions-0.1.tar.gz" } ] }