{ "info": { "author": "Bystroushaak", "author_email": "bystrousak@kitakitsune.org", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2.7", "Topic :: Internet :: WWW/HTTP", "Topic :: Software Development :: Libraries", "Topic :: Utilities" ], "description": "AttributeWrapper\n================\n\n.. image:: https://badge.fury.io/py/attribute_wrapper.png\n :target: http://badge.fury.io/py/attribute_wrapper\n\n.. image:: https://pypip.in/d/attribute_wrapper/badge.png\n :target: https://crate.io/packages/attribute_wrapper?version=latest\n\nThis wrapper maps attribute calls to HTTP API. The package provides similar\nfunctionality as `Tortilla `_, but it is\nimplemented in smaller and simpler code.\n\nThis simplicity gives you ability to subclass and modify functionality as you\nneed.\n\nExamples\n--------\nBasic access\n++++++++++++\n\n.. code-block:: python\n\n from attribute_wrapper import HTTPWrapper\n\n r = HTTPWrapper(\"http://kitakitsune.org\")\n data = r.get()\n\nThis will download content of http://kitakitsune.org and return it as string. The ``.get()`` call determines the HTTP method, which is used to perform the request.\n\nAttribute path composition\n++++++++++++++++++++++++++\nThe dot attribute access notation is used to compose the path of required HTTP resource. For example::\n\n r.raw.get()\n\nis translated to GET request for http://kitakitsune.org/raw.\n\nSpecial characters\n++++++++++++++++++\nThe dot notation in python is restricted only to A-Z, a-z, 0-9 and _, which may be sometimes too much restricting. Thats why the ``GenericWrapper`` has the attribute ``.specials``, which contains mappings of special sequences to URL characters.\n\nThe ``.specials`` table is at this moment implemented by following structure:\n\n.. code-block:: python\n\n {\n \"__dot__\": \".\",\n \"__slash__\": \"/\",\n \"__dash__\": \"-\",\n }\n\nWhich means that URL containing this substrings will be translated as expected:\n\n.. code-block:: python\n\n r.raw.doctene_knihy__dot__txt.get()\n\nis translated to http://kitakitsune.org/raw/doctene_knihy.txt\n\nThis functionality can be changed by replacing ``.specials`` dictionary table with something else, or with blank dictionary to disable it.\n\nUnderscore method\n+++++++++++++++++\nMore complicated paths should be handled using ``_`` method::\n\n r._(\"compl?icated/$path/\").get()\n\nwhich is translated to http://kitakitsune.org/compl?icated/$path/.\n\nAutomatic suffix\n++++++++++++++++\nIf you work with API, which expects that each file ends with suffix like ``.json`` or ``.html``, you can modify the ``.suffix`` attribute or add ``suffix`` parameter when you are instancing the class:\n\n.. code-block:: python\n\n r = HTTPWrapper(\"http://kitakitsune.org\", suffix=\".txt\")\n\n # this will return content of the http://kitakitsune.org, because the suffix\n # is ignored in root of the path\n r.get()\n\n # this will return http://kitakitsune.org/raw/doctene_knihy.txt\n r.raw.doctene_knihy.get()\n\nParameters\n++++++++++\nThe method handling call at last attribute accepts keyword parameters, which are sent to server as form data:\n\n.. code-block:: python\n\n r.post(something=\"else\")\n\nThis will send ``{\"something\": \"else\"}`` dictionary as POST data to server.\n\nJSONWrapper\n+++++++++++\nAs example subclass, there is also ``JSONWrapper``, which translates all parameters to JSON and send it as HTTP **body** to server. This may be specially useful with some of the REST API.\n\nSubclassing\n-----------\nThe code is actually really simple (138 lines!) and it should be (at least I think) easy to understand. If you need some new functionality, you can just simply subclass the ``GenericWrapper`` class and rewrite the ``.download_handler()`` method to reflect your needs.\n\nFor example - the ``JSONWrapper`` is implemented in few lines of code:\n\n.. code-block:: python\n\n import json\n\n class JSONWrapper(GenericWrapper):\n def download_handler(self, method, url, data):\n if data:\n data = json.dumps(data)\n\n headers = {\n 'content-type': 'application/json'\n }\n\n resp = requests.request(method, url, headers=headers, data=data)\n\n # handle http errors\n resp.raise_for_status()\n\n return json.loads(resp.text)\n\nYour code\n+++++++++\nFeel free to send pull request with you own classes (don't forget to document it). I would like to make this package useful and I will gladly incorporate your code, so you don't need to create your own package.\n\nInstallation\n------------\nThe code is hosted at `PYPI `_,\nand you can easily install it using the following command:\n\n.. code-block:: bash\n\n sudo pip install attribute_wrapper\n\nTesting\n-------\nThis project uses `py.test `_ for testing. Just run\n``py.test`` from the root of the project::\n\n bystrousak:/h/D/c0d3z/python/libs/attribute_wrapper,0$ py.test\n ============================= test session starts ==============================\n platform linux2 -- Python 2.7.6 -- py-1.4.23 -- pytest-2.6.0\n collected 8 items \n\n tests/test_wrapper.py ........\n\n =========================== 8 passed in 0.12 seconds ===========================\n\n\nChangelog\n=========\n\n0.2.0\n-----\n - Added full test coverage.\n - Added ValueError exception when calling the root object without method.\n - Fixed some typos in comments.\n - Added testing section to README.rst.\n - Added special underscore method ``GenericWrapper._(path)`` for complicated paths.\n\n0.1.2\n-----\n - Added handling of HTTP errors.\n\n0.1.1\n-----\n - Fixed package metadata problems.\n\n0.1.0\n-----\n - Project created.", "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/Bystroushaak/attribute_wrapper", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "attribute_wrapper", "package_url": "https://pypi.org/project/attribute_wrapper/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/attribute_wrapper/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/Bystroushaak/attribute_wrapper" }, "release_url": "https://pypi.org/project/attribute_wrapper/0.2.0/", "requires_dist": null, "requires_python": null, "summary": "Class wrapper, which maps attribute calls to HTTP API.", "version": "0.2.0" }, "last_serial": 1404652, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "ef9173b13d1dd24f1a09308e5c2c0200", "sha256": "08b108c2b0bdaa74735b60a7664c1326bc60d89f8e4ca7d9019c1868053e1551" }, "downloads": -1, "filename": "attribute_wrapper-0.1.0.tar.gz", "has_sig": false, "md5_digest": "ef9173b13d1dd24f1a09308e5c2c0200", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5021, "upload_time": "2015-01-24T10:29:41", "url": "https://files.pythonhosted.org/packages/ba/5f/368a8031974edeaae8938cfe870ba5a9816e7d636e54a8c1d5e8e8046dc3/attribute_wrapper-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "27764f6fc5ffccd92c4c789a13ca6037", "sha256": "f525809253be1e1f350425aa1274a086514a9b45a427b26fef17cf6480af57ac" }, "downloads": -1, "filename": "attribute_wrapper-0.1.1.tar.gz", "has_sig": false, "md5_digest": "27764f6fc5ffccd92c4c789a13ca6037", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5798, "upload_time": "2015-01-24T10:35:54", "url": "https://files.pythonhosted.org/packages/2a/43/379eff627ffe825175cf3cb49a4162e2e93a5ea886bcfc135e6b3bf91010/attribute_wrapper-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "b9d8d7d8e9bdbaff22e5f07f28a137f4", "sha256": "0fa37b32853e406dcb5cd24f147bce94457bd4bd125d15d078d1e0d4cd2d39b5" }, "downloads": -1, "filename": "attribute_wrapper-0.1.2.tar.gz", "has_sig": false, "md5_digest": "b9d8d7d8e9bdbaff22e5f07f28a137f4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5932, "upload_time": "2015-01-24T13:19:30", "url": "https://files.pythonhosted.org/packages/15/2a/c3c20ccfe8ac3898129dc1df94ecc2641287f5cea424aa6e8e6256e16cbf/attribute_wrapper-0.1.2.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "6fbd164c0b8f8e1039eab2dff29d95bc", "sha256": "7f85b990fdbc7f90fb9a4eea39727987c0ba1d659dc8b5f6f7b4219617d00442" }, "downloads": -1, "filename": "attribute_wrapper-0.2.0.tar.gz", "has_sig": false, "md5_digest": "6fbd164c0b8f8e1039eab2dff29d95bc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6459, "upload_time": "2015-01-31T23:50:19", "url": "https://files.pythonhosted.org/packages/6d/07/69dac0de458ef6a5706d4a6e47a56baced2f2d5ec05cca9d55f975214d0c/attribute_wrapper-0.2.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6fbd164c0b8f8e1039eab2dff29d95bc", "sha256": "7f85b990fdbc7f90fb9a4eea39727987c0ba1d659dc8b5f6f7b4219617d00442" }, "downloads": -1, "filename": "attribute_wrapper-0.2.0.tar.gz", "has_sig": false, "md5_digest": "6fbd164c0b8f8e1039eab2dff29d95bc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6459, "upload_time": "2015-01-31T23:50:19", "url": "https://files.pythonhosted.org/packages/6d/07/69dac0de458ef6a5706d4a6e47a56baced2f2d5ec05cca9d55f975214d0c/attribute_wrapper-0.2.0.tar.gz" } ] }