{ "info": { "author": "Zope Corporation and Contributors", "author_email": "zope-dev@zope.org", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Framework :: Zope3", "Intended Audience :: Developers", "Programming Language :: Python", "Topic :: Internet :: WWW/HTTP :: WSGI :: Application" ], "description": "``zope.httpform`` is a library that, given a WSGI or CGI environment\ndictionary, will return a dictionary back containing converted\nform/query string elements. The form and query string elements\ncontained in the environment are converted into simple Python types when\nthe form element names are decorated with special suffixes. For\nexample, in an HTML form that you'd like this library to process,\nyou might say::\n\n
\n Age : \n \n
\n\nLikewise, in the query string of the URL, you could put::\n\n http://example.com/mypage?age:int=20\n\nIn both of these cases, when provided the WSGI or CGI environment,\nand asked to return a value, this library will return a dictionary\nlike so::\n\n {'age':20}\n\nThis functionality has lived for a long time inside Zope's publisher,\nbut now it has been factored into this small library, making it easier\nto explain, test, and use.\n\n.. contents::\n\nForm/Query String Element Parsing\n---------------------------------\n\n``zope.httpform`` provides a way for you to specify form input types in\nthe form, rather than in your application code. Instead of converting\nthe *age* variable to an integer in a controller or view, you can\nindicate that it is an integer in the form itself::\n\n Age \n\nThe ``:int`` appended to the form input name tells this library to\nconvert the form input to an integer when it is invoked. If the\nuser of your form types something that cannot be converted to an\ninteger in the above case (such as \"22 going on 23\") then this library\nwill raise a ValueError.\n\nHere is a list of the standard parameter converters.\n\n``:boolean``\n\n Converts a variable to true or false. Empty strings are evaluated as\n false and non-empty strings are evaluated as true.\n\n``:int``\n\n Converts a variable to an integer.\n\n``:long``\n\n Converts a variable to a long integer.\n\n``:float``\n\n Converts a variable to a floating point number.\n\n``:string``\n\n Converts a variable to a string. Most variables are strings already,\n so this converter is not often used except to simplify file uploads.\n\n``:text``\n\n Converts a variable to a string with normalized line breaks.\n Different browsers on various platforms encode line endings\n differently, so this script makes sure the line endings are\n consistent, regardless of how they were encoded by the browser.\n\n``:list``\n\n Converts a variable to a Python list.\n\n``:tuple``\n\n Converts a variable to a Python tuple.\n\n``:tokens``\n\n Converts a string to a list by breaking it on white spaces.\n\n``:lines``\n\n Converts a string to a list by breaking it on new lines.\n\n``:required``\n\n Raises an exception if the variable is not present.\n\n``:ignore_empty``\n\n Excludes the variable from the form data if the variable is an empty\n string.\n\nThese converters all work in more or less the same way to coerce a\nform variable, which is a string, into another specific type.\n\nThe ``:list`` and ``:tuple`` converters can be used in combination with\nother converters. This allows you to apply additional converters to\neach element of the list or tuple. Consider this form::\n\n
\n\n

I like the following numbers

\n\n One
\n\n Two
\n\n Three
\n\n Four
\n\n 5
\n\n \n
\n\nBy using the ``:list`` and ``:int`` converters together, this library\nwill convert each selected item to an integer and then combine all\nselected integers into a list named *favorite_numbers*.\n\nA more complex type of form conversion is to convert a series of\ninputs into *records*. Records are structures that have\nattributes. Using records, you can combine a number of form inputs\ninto one variable with attributes. The available record converters\nare:\n\n``:record``\n\n Converts a variable to a record attribute.\n\n``:records``\n\n Converts a variable to a record attribute in a list of records.\n\n``:default``\n\n Provides a default value for a record attribute if the variable is\n empty.\n\n``:ignore_empty``\n\n Skips a record attribute if the variable is empty.\n\nHere are some examples of how these converters are used::\n\n
\n\n First Name
\n Last Name
\n Age
\n\n \n
\n\nIf the information represented by this form post is passed to\n``zope.httpform``, the resulting dictionary will container one parameter,\n*person*. The *person* variable will have the attributes *fname*,\n*lname* and *age*. Here's an example of how you might use\n``zope.httpform`` to process the form post (assuming you have a WSGI\nor CGI environment in hand)::\n\n from zope.httpform import parse\n\n info = parse(environ, environ['wsgi.input'])\n person = info['person']\n full_name = \"%s %s\" % (person.fname, person.lname)\n if person.age < 21:\n return (\"Sorry, %s. You are not old enough to adopt an \"\n \"aardvark.\" % full_name)\n return \"Thanks, %s. Your aardvark is on its way.\" % full_name\n\nThe *records* converter works like the *record* converter except\nthat it produces a list of records, rather than just one. Here is\nan example form::\n\n
\n\n

Please, enter information about one or more of your next of\n kin.

\n\n

\n First Name \n Last Name \n

\n\n

\n First Name \n Last Name \n

\n\n

\n First Name \n Last Name \n

\n\n \n
\n\nIf you call ``zope.httpform``'s parse method with the information\nfrom this form post, a dictionary will be returned from it with a\nvariable called *people* that is a list of records. Each record will\nhave *fname* and *lname* attributes. Note the difference between the\n*records* converter and the *list:record* converter: the former would\ncreate a list of records, whereas the latter would produce a single\nrecord whose attributes *fname* and *lname* would each be a list of\nvalues.\n\nThe order of combined modifiers does not matter; for example,\n``:int:list`` is identical to ``:list:int``.\n\nGotchas\n-------\n\nThe file pointer passed to ``zope.httpform.parse()`` will be\nconsumed. For all intents and purposes this means you should make a\ntempfile copy of the ``wsgi.input`` file pointer before calling\n``parse()`` if you intend to use the POST file input data in your\napplication.\n\nAcknowledgements\n----------------\n\nThis documentation was graciously donated by the team at\nAgendaless Consulting. The ``zope.httpform`` package is\nexpected to replace the ``repoze.monty`` package.\n\n\nCHANGES\n=======\n\nVersion 1.0.2 (2009-07-24)\n--------------------------\n\n- Include package data in release.\n\n- Default to UTF-8 decoding\n\n- Fixed a test failure on Python 2.6\n\n\nVersion 1.0.1 (2009-02-07)\n--------------------------\n\n- Fixed some misleading documentation.\n\n- Relaxed the requirement for REQUEST_METHOD because the zope.publisher\n tests do not set it.\n\n- Used documentation and design ideas from repoze.monty. Thanks,\n Chris and Agendaless.\n\n\nVersion 1.0.0 (2009-02-06)\n--------------------------\n\n- First release of zope.httpform. Extracted from zope.publisher 3.5.5.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://pypi.python.org/pypi/zope.httpform", "keywords": null, "license": "ZPL 2.1", "maintainer": null, "maintainer_email": null, "name": "zope.httpform", "package_url": "https://pypi.org/project/zope.httpform/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/zope.httpform/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://pypi.python.org/pypi/zope.httpform" }, "release_url": "https://pypi.org/project/zope.httpform/1.0.2/", "requires_dist": null, "requires_python": null, "summary": "HTTP Form Data Parser", "version": "1.0.2" }, "last_serial": 802378, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "4926b6825b92ddcc6b930531c468e9f6", "sha256": "b6e655486d0c9ff439e16153b43a00e153edd50b36b911f0c715b657c33211e8" }, "downloads": -1, "filename": "zope.httpform-1.0.0.tar.gz", "has_sig": false, "md5_digest": "4926b6825b92ddcc6b930531c468e9f6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12252, "upload_time": "2009-02-06T07:29:43", "url": "https://files.pythonhosted.org/packages/c7/98/2f1805dcb05d8d5b4b3be2134908374e6974da4367d6bff52d283752611f/zope.httpform-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "55dc00aab21dac77a18e7e1a739ea4df", "sha256": "b528fddc405b17549ddd9d884ccf7965eb0ff5968c901b6bed9502463c401baf" }, "downloads": -1, "filename": "zope.httpform-1.0.1.tar.gz", "has_sig": false, "md5_digest": "55dc00aab21dac77a18e7e1a739ea4df", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15766, "upload_time": "2009-02-08T00:14:10", "url": "https://files.pythonhosted.org/packages/f4/c0/e6fe80d645b29b826efeb55022b6e035aedcb233ad8c899e199f8d084552/zope.httpform-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "df409152d1722e63f1a877addff1eea6", "sha256": "062643757df63c09e9cb2086f09e3f785c353d4b706eff52ee3850ca7e8a85d8" }, "downloads": -1, "filename": "zope.httpform-1.0.2.tar.gz", "has_sig": false, "md5_digest": "df409152d1722e63f1a877addff1eea6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18704, "upload_time": "2009-07-24T21:34:36", "url": "https://files.pythonhosted.org/packages/c7/42/9cebaf9931df85d7f7e75975f1611c04e89f7286aa7d9bf7ee16353e1dd3/zope.httpform-1.0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "df409152d1722e63f1a877addff1eea6", "sha256": "062643757df63c09e9cb2086f09e3f785c353d4b706eff52ee3850ca7e8a85d8" }, "downloads": -1, "filename": "zope.httpform-1.0.2.tar.gz", "has_sig": false, "md5_digest": "df409152d1722e63f1a877addff1eea6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18704, "upload_time": "2009-07-24T21:34:36", "url": "https://files.pythonhosted.org/packages/c7/42/9cebaf9931df85d7f7e75975f1611c04e89f7286aa7d9bf7ee16353e1dd3/zope.httpform-1.0.2.tar.gz" } ] }