{ "info": { "author": "Agendaless Consulting", "author_email": "repoze-dev@lists.repoze.org", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "Programming Language :: Python", "Topic :: Internet :: WWW/HTTP", "Topic :: Internet :: WWW/HTTP :: Dynamic Content", "Topic :: Internet :: WWW/HTTP :: WSGI" ], "description": "repoze.monty Form Element Marshalling\n=====================================\n\n``repoze.monty`` is a library that, given a WSGI environment\ndictionary (and a ``wsgi.input`` file pointer if the request is a POST\nrequest), will return a dictionary back containing \"converted\"\nform/query string elements. The form and query string elements\ncontained in the request 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 monty to convert a form\nelement for, you might say::\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 environment and the\n``wsgi.input`` file pointer, and asked to return a value, monty might\nreturn a dictionary like so::\n\n {'age':20}\n\n``repoze.monty`` is a generalized version of the form marshalling\nmachinery originated in Zope 2.\n\nForm/Query String Element Marshalling\n-------------------------------------\n\n``repoze.monty`` 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 vierw, 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 ``repoze.monty`` to\nconvert the form input to an integer when it is invoked. This process\nis called *marshalling*. If the user of your form types something that\ncannot be converted to an integer in the above case (such as \"22 going\non 23\") then Zope will raise a ValueError.\n\nHere is a list of ``repoze.monty``'s basic parameter converters.\n\n*boolean*\n \n Converts a variable to true or false. Variables that are 0, None, an\n empty string, or an empty sequence are false, all others are 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 seldom used.\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 request 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\nBy using the *list* and *date* converters together, ``repoze.monty``\nwill convert each selected time to a date and then combine all\nselected dates 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\nIf the information represented by this form post is passed to\n``repoze.monty``, the result 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``repoze.monty`` to process the form post (assuming you have a WSGI\nenvironment in hand)::\n\n from repoze.monty import marshal\n\n info = marshal(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\nIf you call ``repoze.monty``'s marshal 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 ``repoze.monty``'s marshal method 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``marshal`` if you intend to use the POST file input data in your\napplication.\n\nReporting Bugs / Development Versions\n-------------------------------------\n\nVisit http://bugs.repoze.org to report bugs. Visit\nhttp://svn.repoze.org to download development or tagged versions.\n\n\n\n0.1\n\n Initial release.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://www.repoze.org", "keywords": "web wsgi zope", "license": "ZPL 2.1", "maintainer": null, "maintainer_email": null, "name": "repoze.monty", "package_url": "https://pypi.org/project/repoze.monty/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/repoze.monty/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://www.repoze.org" }, "release_url": "https://pypi.org/project/repoze.monty/0.1/", "requires_dist": null, "requires_python": null, "summary": "A form field marshaller for WSGI (stolen from Zope)", "version": "0.1" }, "last_serial": 798820, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "b90abb03624a86f77c82578582e60b67", "sha256": "c604865ea974ee9620b964618ac5dd338e4599d2a7613d4e457d4f73dd64d209" }, "downloads": -1, "filename": "repoze.monty-0.1.tar.gz", "has_sig": false, "md5_digest": "b90abb03624a86f77c82578582e60b67", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17339, "upload_time": "2008-07-30T19:08:26", "url": "https://files.pythonhosted.org/packages/ee/a4/6feeac210545e2092d1e41fe736f8d89bd66d2183d68ceb7c2abfca55a01/repoze.monty-0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "b90abb03624a86f77c82578582e60b67", "sha256": "c604865ea974ee9620b964618ac5dd338e4599d2a7613d4e457d4f73dd64d209" }, "downloads": -1, "filename": "repoze.monty-0.1.tar.gz", "has_sig": false, "md5_digest": "b90abb03624a86f77c82578582e60b67", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17339, "upload_time": "2008-07-30T19:08:26", "url": "https://files.pythonhosted.org/packages/ee/a4/6feeac210545e2092d1e41fe736f8d89bd66d2183d68ceb7c2abfca55a01/repoze.monty-0.1.tar.gz" } ] }