{ "info": { "author": "Tim Heap", "author_email": "tim@timheap.me", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python" ], "description": "========================================================\naccept-types - Use the correct accept type for a request\n========================================================\n\n``accept-types`` helps your application respond to a HTTP request in a way that a client prefers.\nThe ``Accept`` header of an HTTP request informs the server which MIME types the client is expecting\nback from this request, with weighting to indicate the most prefered. If your server can respond in\nmultiple formats (e.g.: JSON, XML, HTML), the client can easily tell your server which is the\nprefered format without resorting to hacks like '&format=json' on the end of query strings.\n\n\nUsage\n=====\n\n``get_best_match``\n------------------\n\nWhen provided with an ``Accept`` header and a list of types your server can respond with, this function\nreturns the clients most prefered type. This function will only return one of the acceptable types you\npassed in, or ``None`` if no suitable type was found:\n\n.. code:: python\n\n\tfrom accept_type import get_best_match\n\n\tdef get_the_info(request):\n\t\tinfo = gather_info()\n\n\t\treturn_type = get_best_match(request.META.get('HTTP_ACCEPT'), ['text/html', 'application/xml', 'text/json'])\n\n\t\tif return_type == 'application/xml':\n\t\t\treturn render_xml(info)\n\n\t\telif return_type == 'text/json':\n\t\t\treturn render_json(info)\n\n\t\telif return_type == 'text/html':\n\t\t\treturn render_html(info)\n\n\t\telif return_type == None:\n\t\t\treturn HttpResponse406()\n\n``parse_header``\n----------------\n\nWhen provided with an ``Accept`` header, this will parse it and return a sorted list of the clients\naccepted mime types. These will be instances of the ``AcceptableType`` class.\n\n.. code:: python\n\n\t>>> from accept_type import parse_header\n\t>>> parse_header('text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')\n\t['text/html, weight 1', 'application/xhtml+xml, weight 1', 'application/xml, weight 0.9', '*/*, weight 0.8']\n\n``AcceptableType``\n------------------\n\n``AcceptableType`` instances represent one of the types that a client is willing to accept. This\ntype could include wildcards, to match more than one MIME type.\n\n.. code:: python\n\n\t>>> from accept_type import AcceptableType\n\t>>> type = AcceptableType('image/*;q=0.9')\n\tAcceptableType\n\t>>> type.mime_type\n\t'image/*'\n\t>>> type.weight\n\t0.9\n\t>>> type.matches('image/png')\n\tTrue\n\t>>> type.matches('text/html')\n\tFalse\n\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://bitbucket.org/tim_heap/python-accept-types", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "accept-types", "package_url": "https://pypi.org/project/accept-types/", "platform": "", "project_url": "https://pypi.org/project/accept-types/", "project_urls": { "Homepage": "https://bitbucket.org/tim_heap/python-accept-types" }, "release_url": "https://pypi.org/project/accept-types/0.4.1/", "requires_dist": null, "requires_python": "", "summary": "Determine the best content to send in an HTTP response", "version": "0.4.1" }, "last_serial": 5758888, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "74780c0a4e4d3c99ac5545c8cbd37a69", "sha256": "9d202ffd6a428353287cdf8950d8d6befcc328ed8c8d6cf2074a5056ef5ed68b" }, "downloads": -1, "filename": "accept-types-0.1.0.tar.gz", "has_sig": false, "md5_digest": "74780c0a4e4d3c99ac5545c8cbd37a69", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2932, "upload_time": "2014-09-30T04:28:32", "url": "https://files.pythonhosted.org/packages/c4/e9/c1e7c38a986c89794c62896612feb5afe795ebb752571066646717a1ca3a/accept-types-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "c2fe97fae568c17f9c413edb4fcd31f1", "sha256": "d0947bd02ea3ee4faca781823badca2d0f4f1732f083d3c7d91ec0de2ceef4fb" }, "downloads": -1, "filename": "accept-types-0.2.0.tar.gz", "has_sig": false, "md5_digest": "c2fe97fae568c17f9c413edb4fcd31f1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2994, "upload_time": "2014-09-30T04:36:37", "url": "https://files.pythonhosted.org/packages/5b/a3/bf21686f82bbc9629b6a73584894f4a21ad566fc09bda8406569a019e9e2/accept-types-0.2.0.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "048b984ec4e5923a2b47f7ae9741efe9", "sha256": "9ae86512bf3a3eaad6a2793617a34eb15b384593e6c28697bef9b15ac237017a" }, "downloads": -1, "filename": "accept-types-0.3.0.tar.gz", "has_sig": false, "md5_digest": "048b984ec4e5923a2b47f7ae9741efe9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3001, "upload_time": "2015-10-12T04:11:59", "url": "https://files.pythonhosted.org/packages/5c/61/1c8f5fd3184bc270dd67ccab3b4abb1c663840178642591a4241d70c7381/accept-types-0.3.0.tar.gz" } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "80b3abfcdd6ca83f1aeb7b3eabc90455", "sha256": "782184693e21bbb26896f6a14df32ce0c685229a1b94d9dfff3f282dda83e0b0" }, "downloads": -1, "filename": "accept_types-0.4.0-py3-none-any.whl", "has_sig": false, "md5_digest": "80b3abfcdd6ca83f1aeb7b3eabc90455", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 4993, "upload_time": "2019-08-28T00:32:15", "url": "https://files.pythonhosted.org/packages/cf/51/a501962bd6d229c0e713924aac84336f465f687c83d1fb38e0129f73a3a3/accept_types-0.4.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e21f90c0d72a2759069707c9fc69375f", "sha256": "abbe13ea19e0b9f48cc276b618afb0d9e43ab73a051938773fdfd78650078873" }, "downloads": -1, "filename": "accept-types-0.4.0.tar.gz", "has_sig": false, "md5_digest": "e21f90c0d72a2759069707c9fc69375f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3698, "upload_time": "2019-08-28T00:32:17", "url": "https://files.pythonhosted.org/packages/53/8c/f2928624a3dfdf165aa7670f17ea463c9430eaa5ee3895e21be3f250bdbd/accept-types-0.4.0.tar.gz" } ], "0.4.1": [ { "comment_text": "", "digests": { "md5": "92230a07a9d82dace81a40f81720d43b", "sha256": "c87feccdffb66b02f9343ff387d7fd5c451ccb2e1221fbd37ea0cedef5cf290f" }, "downloads": -1, "filename": "accept_types-0.4.1-py3-none-any.whl", "has_sig": false, "md5_digest": "92230a07a9d82dace81a40f81720d43b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 4995, "upload_time": "2019-08-30T07:52:02", "url": "https://files.pythonhosted.org/packages/08/24/559c0f1959134a0e7615a0ece082734209b1942365ec479cbe3bcca9098b/accept_types-0.4.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "824024083f014833e2094c655dec1a53", "sha256": "fb27099716d8f0360408c8ca86d69dbfed44455834b70d1506250abe521b535a" }, "downloads": -1, "filename": "accept-types-0.4.1.tar.gz", "has_sig": false, "md5_digest": "824024083f014833e2094c655dec1a53", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3703, "upload_time": "2019-08-30T07:52:04", "url": "https://files.pythonhosted.org/packages/a3/84/6f51d94019411892c9f7fa9d461d4cef06beb35d54cd9944ea19728c4d45/accept-types-0.4.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "92230a07a9d82dace81a40f81720d43b", "sha256": "c87feccdffb66b02f9343ff387d7fd5c451ccb2e1221fbd37ea0cedef5cf290f" }, "downloads": -1, "filename": "accept_types-0.4.1-py3-none-any.whl", "has_sig": false, "md5_digest": "92230a07a9d82dace81a40f81720d43b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 4995, "upload_time": "2019-08-30T07:52:02", "url": "https://files.pythonhosted.org/packages/08/24/559c0f1959134a0e7615a0ece082734209b1942365ec479cbe3bcca9098b/accept_types-0.4.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "824024083f014833e2094c655dec1a53", "sha256": "fb27099716d8f0360408c8ca86d69dbfed44455834b70d1506250abe521b535a" }, "downloads": -1, "filename": "accept-types-0.4.1.tar.gz", "has_sig": false, "md5_digest": "824024083f014833e2094c655dec1a53", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3703, "upload_time": "2019-08-30T07:52:04", "url": "https://files.pythonhosted.org/packages/a3/84/6f51d94019411892c9f7fa9d461d4cef06beb35d54cd9944ea19728c4d45/accept-types-0.4.1.tar.gz" } ] }