{ "info": { "author": "Philip J Grabner, Canary Health Inc", "author_email": "oss-pypi@canary.md", "bugtrack_url": null, "classifiers": [ "Environment :: Console", "Environment :: Web Environment", "Framework :: Pyramid", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "License :: Public Domain", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Internet", "Topic :: Internet :: WWW/HTTP", "Topic :: Internet :: WWW/HTTP :: WSGI", "Topic :: Software Development", "Topic :: Software Development :: Libraries :: Application Frameworks" ], "description": "=============\nPyramid Input\n=============\n\nThe ``pyramid_input`` package is a pyramid plugin that adds a \"tween\"\nthat parses and combines all data presented in the HTTP request in one\nstandardized request attribute. The following data is currently accepted\n(in increasing order of precedence):\n\n* Query string parameters\n* Request payload (i.e. the \"request body\") in several different formats\n\nSee `Example`_ for a detailed example.\n\n\nProject\n=======\n\n* Homepage: https://github.com/canaryhealth/pyramid_input\n* Bugs: https://github.com/canaryhealth/pyramid_input/issues\n\n\nInstallation\n============\n\n.. code:: bash\n\n $ pip install pyramid_input\n\n\nUsage\n=====\n\nEnable the tween either in your INI file via:\n\n.. code:: ini\n\n pyramid.includes = pyramid_input\n\nor in code in your package's application initialization via:\n\n.. code:: python\n\n def main(global_config, **settings):\n # ...\n config.include('pyramid_input')\n # ...\n\nIf needed, adjust pyramid_input's behaviour by setting the various\n`Configuration`_ options in your INI file.\n\nThen, access a request's input parameters, regardless of their\norigin or encoding, simply as:\n\n.. code:: python\n\n def request_handler(request):\n\n if request.input.somekey == 'some-value':\n ...\n\n\nExample\n=======\n\nThe pyramid_input tween makes all of the following requests present\nthe identical structure in the `request.input` attribute:\n\nInterpreting GET data:\n\n.. code:: text\n\n GET /path?foo=bar&zig.zag=zog&zig.zen-0=mig&zig.zen-1=mag\n\nInterpreting and merging GET and POST form data:\n\n.. code:: text\n\n POST /path?foo=bar\n Content-Type: application/x-www-form-urlencoded\n\n zig.zag=zog&zig.zen-0=mig&zig.zen-1=mag\n\nInterpreting and merging GET and JSON payload data:\n\n.. code:: text\n\n POST /path?foo=bar\n Content-Type: application/json\n\n {\"zig\": {\"zag\": \"zog\", \"zen\": [\"mig\", \"mag\"]}}\n\nInterpreting and merging GET and YAML payload data:\n\n.. code:: text\n\n POST /path?foo=bar\n Content-Type: application/yaml\n\n zig:\n zag: zog\n zen:\n - mig\n - mag\n\nInterpreting and merging GET and XML payload data:\n\n.. code:: text\n\n POST /path?foo=bar\n Content-Type: application/xml\n\n \n zog\n mig\n mag\n \n\nAll of the above will result in the identical data structure being\ncontained in the `request.input` attribute:\n\n.. code:: python\n\n request.input = {\n 'foo': 'bar',\n 'zig': {\n 'zag': 'zog',\n 'zen': ['mig', 'mag']\n }\n }\n\nPlease note that in all cases the original parameters (in\n`request.GET`, `request.POST`, `request.params`, `request.body` and\n`request.json_body`) are left as-is, so if the raw data is needed, it\ncan be accessed directly.\n\n\nQuery String Parsing\n====================\n\nThe HTTP query string parameters are \"unflattened\" using FormEncode's\n`variable_decode` implementation, which converts the key-value pairs\ninto a nested tree structure. For example, the following query string\nparameters:\n\n.. code:: text\n\n ?simple=val1&dict.subkey=val2&dict.list-0=el0&dict.list-1=el1\n\nis transformed into the structure:\n\n.. code:: yaml\n\n {\n simple: val1\n dict: {\n subkey: val2\n list: [ el0, el1 ]\n }\n }\n\nNote that query string parameters are by default overwritten by any\nHTTP request payload data.\n\n\nPayload Parsing\n===============\n\nThe request payload (aka. request body) is parsed when the request's\n``Content-Type`` is one of the following values:\n\n* ``application/x-www-form-urlencoded``, ``multipart/form-data``\n\n The standard HTTP `POST` encoding; the key-value pairs are parsed\n exactly the same way as the query string, i.e. they are unflattened\n using FormEncode's `variable_decode` implementation. Note that for\n ``multipart/form-data`` (the content-type used for standard\n HTTP-based file uploading), nothing special is done: the `file`\n object that is in `request.POST` is simply referenced as-is in\n `request.input` as well.\n\n* ``application/json``, ``application/x-json``, ``text/json``, ``text/x-json``, ``...+json``\n\n The payload is parsed using the built-in JSON parser, and no further\n processing is done. The data is required to be a dictionary unless\n the `pyramid_input.require-dict` is set to false, and if this is\n violated, request processing is aborted with a 400 \"Bad Request\"\n response error.\n\n* ``application/yaml``, ``application/x-yaml``, ``text/yaml``, ``text/x-yaml``, ``...+yaml``\n\n If the `PyYAML` package is available, the payload is parsed using\n the YAML parser, and no further processing is done. The data is\n required to be a dictionary unless the `pyramid_input.require-dict`\n is set to false, and if this is violated, request processing is\n aborted with a 400 \"Bad Request\" response error.\n\n* ``application/xml``, ``application/x-xml``, ``text/xml``, ``text/x-xml``, ``...+xml``\n\n The payload is parsed using the built-in ElementTree parser and the\n XML document is converted to a tree via a fairly simplistic mapping\n process. Note that this mapping process is \"lossy\", i.e. some\n aspects of the XML serialization (such as order of interleaved\n non-similar children nodes) are lost in the convertion.\n\n\nCombination\n===========\n\nWhen both query string paramaters and a payload is specified in the\nrequest, the output of parsing both data sources are then combined\ntogether to form a single data tree. By default (i.e. when\n`pyramid_input.combine.deep` is true), the payload data overrides the\nquery string data by overlaying and merging the two tree structures\nrecursively.\n\nA recursive deep merge basically means that dict keys get merged with\ndict keys, and all other type combinations turn into lists.\n\nThe deep merge can be disabled by setting the\n`pyramid_input.combine.deep` option to false, in which case the\npayload top-level dict keys completely override the query string\ntop-level keys, without any inspection of sub-keys.\n\nFor example, given the following query string tree structure:\n\n.. code:: yaml\n\n foo: bar\n dict:\n list: [a, b]\n item: c\n\nand the following payload tree structure:\n\n.. code:: yaml\n\n bar: foo\n dict:\n list: d \n item: e\n\na deep merge will result in:\n\n.. code:: yaml\n\n foo: bar\n bar: foo\n dict:\n list: [a, b, d]\n item: [c, e]\n\nand a non-deep merge will result in:\n\n.. code:: yaml\n\n foo: bar\n bar: foo\n dict:\n list: d\n item: e\n\n\nConfiguration\n=============\n\nThe following configuration settings can be set in your application's\n``main`` section:\n\n* ``pyramid_input.enabled`` : bool, default: true\n\n* ``pyramid_input.attribute-name`` : str, default: 'input'\n\n* ``pyramid_input.combine.deep`` : bool, default: true\n\n* ``pyramid_input.include`` : list(glob), default: `/**`\n\n* ``pyramid_input.exclude`` : list(glob), default: null\n\n* ``pyramid_input.require-dict`` : bool, default: true\n\n* ``pyramid_input.fail-unknown`` : bool, default: true\n\n If the request's Content-Type is unknown (or its parser disabled)\n and `pyramid_input.fail-unknown` is true, a 400 \"bad request\" error\n is returned. If set to false, the payload is ignored.\n\n* ``pyramid_input.native-dict`` : bool, default: false\n\n If true, `request.input` will be a standard python `dict` object.\n If false (the default), then it will be a recursive `aadict` object\n (which is a subclass of dict that supports attribute-based access to\n its items).\n\n* ``pyramid_input.error-handler`` : symbol-spec, default: null\n\n On error (such as a 400 \"Bad Request\" for invalid JSON), this\n function is called with the `pyramid.httpexceptions.Exception`\n subclass that caused the error. The default implementation has\n this function signature equivalent:\n\n .. code:: python\n\n def function(request, error):\n return error\n\n* ``pyramid_input.reparse-methods`` : list(str), default: 'PATCH'\n\n Enable a workaround for pyramid 1.4.2+ that does not properly parse\n the `application/x-www-form-urlencoded` request body if the request\n method is PATCH. It is unknown if other methods have this issue or\n if it has been fixed.\n\n* ``pyramid_input.json.enable`` : bool, default: true\n\n* ``pyramid_input.json.parser`` : symbol-spec, default: null\n\n Specifies the JSON parser. If not specified, uses Pyramid's\n pre-existing ``Request.json_body`` attribute.\n\n* ``pyramid_input.yaml.enable`` : bool, default: true\n\n* ``pyramid_input.yaml.parser`` : symbol-spec, default: 'yaml.load'\n\n* ``pyramid_input.xml.enable`` : bool, default: true\n\n* ``pyramid_input.xml.parser`` : symbol-spec, default: 'xml.etree.ElementTree.fromstring'\n", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/canaryhealth/pyramid_input", "keywords": "web wsgi pyramid http input data normalize get post json yaml xml", "license": "MIT (http://opensource.org/licenses/MIT)", "maintainer": "", "maintainer_email": "", "name": "pyramid_input", "package_url": "https://pypi.org/project/pyramid_input/", "platform": "", "project_url": "https://pypi.org/project/pyramid_input/", "project_urls": { "Homepage": "http://github.com/canaryhealth/pyramid_input" }, "release_url": "https://pypi.org/project/pyramid_input/0.2.3/", "requires_dist": null, "requires_python": "", "summary": "A Pyramid tween that normalizes HTTP request input data.", "version": "0.2.3" }, "last_serial": 3094275, "releases": { "0.2.0": [ { "comment_text": "", "digests": { "md5": "18df4cc3788607dd8487dee838ef887e", "sha256": "17c88f89cb928658b4a5b16ec3ab18f1204c56a70b9db146f5a869b8e5f49914" }, "downloads": -1, "filename": "pyramid_input-0.2.0.tar.gz", "has_sig": false, "md5_digest": "18df4cc3788607dd8487dee838ef887e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10975, "upload_time": "2015-06-18T20:04:16", "url": "https://files.pythonhosted.org/packages/69/9c/fe977b870dfa431495c7e12315431bb6d07d6904be2204c3a9eb6a07ecba/pyramid_input-0.2.0.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "7550561306fedf7070ac5fbd996db741", "sha256": "f4c71862afd03db0fa116bad32570cecc9adc74695fbc5e936ae381d4901e98e" }, "downloads": -1, "filename": "pyramid_input-0.2.1.tar.gz", "has_sig": false, "md5_digest": "7550561306fedf7070ac5fbd996db741", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10989, "upload_time": "2015-09-08T16:48:26", "url": "https://files.pythonhosted.org/packages/31/5c/b8cc779c7311627647547702a3935daead695067e24cfda3d202ca4ebd83/pyramid_input-0.2.1.tar.gz" } ], "0.2.2": [ { "comment_text": "", "digests": { "md5": "0b2957545d0e4ea78fb3e79a2512494e", "sha256": "9ce10b4b809d5fb8f2deb01247d37703afffac54b5e87e1dfcadf69de9a3397a" }, "downloads": -1, "filename": "pyramid_input-0.2.2.tar.gz", "has_sig": false, "md5_digest": "0b2957545d0e4ea78fb3e79a2512494e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11332, "upload_time": "2015-10-07T20:20:31", "url": "https://files.pythonhosted.org/packages/09/1a/75bdfae24f6cba3d8b278dce4c606278b051c66265c3815365491b748a05/pyramid_input-0.2.2.tar.gz" } ], "0.2.3": [ { "comment_text": "", "digests": { "md5": "85547aa4710fcf6203265b8e0b2c7a0c", "sha256": "87889a1ba652940ab80ad07cb9476a69ea4bb280c188c4a58e18ce352a1fad9c" }, "downloads": -1, "filename": "pyramid_input-0.2.3.tar.gz", "has_sig": false, "md5_digest": "85547aa4710fcf6203265b8e0b2c7a0c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15169, "upload_time": "2017-08-13T22:40:16", "url": "https://files.pythonhosted.org/packages/a0/c8/75e24b7c4b6082372b8da03f27227d27084580c5936a9b8e3439789c516e/pyramid_input-0.2.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "85547aa4710fcf6203265b8e0b2c7a0c", "sha256": "87889a1ba652940ab80ad07cb9476a69ea4bb280c188c4a58e18ce352a1fad9c" }, "downloads": -1, "filename": "pyramid_input-0.2.3.tar.gz", "has_sig": false, "md5_digest": "85547aa4710fcf6203265b8e0b2c7a0c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15169, "upload_time": "2017-08-13T22:40:16", "url": "https://files.pythonhosted.org/packages/a0/c8/75e24b7c4b6082372b8da03f27227d27084580c5936a9b8e3439789c516e/pyramid_input-0.2.3.tar.gz" } ] }