1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>4.4.1 FieldStorage class</title>
<META NAME="description" CONTENT="4.4.1 FieldStorage class">
<META NAME="keywords" CONTENT="modpython">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<link rel="STYLESHEET" href="modpython.css">
<link rel="first" href="modpython.html">
<link rel="contents" href="contents.html" title="Contents">
<link rel="index" href="genindex.html" title="Index">
<LINK REL="next" href="pyapi-util-funcs.html">
<LINK REL="previous" href="pyapi-util.html">
<LINK REL="up" href="pyapi-util.html">
<LINK REL="next" href="pyapi-util-fstor-fld.html">
</head>
<body>
<DIV CLASS="navigation">
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="pyapi-util.html"><img src="icons/previous.gif"
border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="pyapi-util.html"><img src="icons/up.gif"
border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A href="pyapi-util-fstor-fld.html"><img src="icons/next.gif"
border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Mod_python Manual</td>
<td><A href="contents.html"><img src="icons/contents.gif"
border="0" height="32"
alt="Contents" width="32"></A></td>
<td><img src="icons/blank.gif"
border="0" height="32"
alt="" width="32"></td>
<td><A href="genindex.html"><img src="icons/index.gif"
border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="pyapi-util.html">4.4 util - Miscellaneous</A>
<b class="navlabel">Up:</b> <a class="sectref" href="pyapi-util.html">4.4 util - Miscellaneous</A>
<b class="navlabel">Next:</b> <a class="sectref" href="pyapi-util-fstor-fld.html">4.4.1.1 Field class</A>
<br><hr>
</DIV>
<!--End of Navigation Panel-->
<H2><A NAME="SECTION006410000000000000000"> </A>
<BR>
4.4.1 FieldStorage class
</H2>
<P>
Access to form data is provided via the <tt class="class">FieldStorage</tt>
class. This class is similar to the standard library module <tt class="module">cgi</tt>
<tt class="class">FieldStorage</tt> (but there are a few differences).
<P>
<dl><dt><b><span class="typelabel">class</span> <a name="l2h-121"><tt class="class">FieldStorage</tt></a></b>(<var>req</var><big>[</big><var>, keep_blank_values, strict_parsing</var><big>]</big>)
<dd>
This class provides uniform access to HTML form data submitted by the client.
<var>req</var> is an instance of the mod_python <tt class="class">Request</tt> object.
<P>
The optional argument <var>keep_blank_values</var> is a flag indicating whether
blank values in URL encoded form data should be treated as blank strings. The
default is false, which means that blank values are ignored as if they were
not included.
<P>
The optional argument <var>strict_parsing</var> is not yet implemented.
</dl>
<P>
While being instantiated, the <tt class="class">FieldStorage</tt> class reads all of
the data provided by the client. Since all data provided by the client
is consumed at this point, there should be no more than one
<tt class="class">FieldStorage</tt> class instantiated per signle request, nor should
you make any attempts to read client data before or after
instantiating a <tt class="class">FieldStorage</tt>.
<P>
The data read from the client is then parsed into separate fields
and packaged in <tt class="class">Field</tt> objects, one per field. For HTML form
inputs of type <code>file</code>, a temporary file is created that can later be
accessed via the <tt class="member">file</tt> attribute of a <tt class="class">Field</tt> object.
<P>
The <tt class="class">FieldStorage</tt> class has a mapping object interface, i.e. it
can be treated like a dictionary. When used as a dictionary, the dictionary
keys are form input names, and the returned dictionary value can be:
<P>
<UL>
<LI>A string, containing the form input value. This is only when there is a single
value corresponding to the input name.
</LI>
<LI>An instances of a <tt class="class">Field</tt> class, if the input is a file upload.
</LI>
<LI>A list of strings and/or <tt class="class">Field</tt> objects. This is when multiple values
exist, such as for a <code><select></code> HTML form element.
</LI>
</UL>
<P>
Note that unlike the standard library <tt class="module">cgi</tt> module
<tt class="class">FieldStorage</tt> class, a
<tt class="class">Field</tt> object is returned <i>only</i> when it is a file
upload. This means that you do not need to use the <tt class="member">.value</tt>
attribute to access values of fields in most cases.
<P>
In addition to standard mapping object methods, <tt class="class">FieldStorage</tt> objects
have the following attributes:
<P>
<dl><dt><b><a name="l2h-122"><tt class="member">list</tt></a></b>
<dd>
This is a list of <tt class="class">Field</tt> objects, one for each input. Multiple
inputs with the same name will have multiple elements in this list.
</dl>
<P>
<p><hr>
<!--Table of Child-Links-->
<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></a>
<UL CLASS="ChildLinks">
<LI><A href="pyapi-util-fstor-fld.html">4.4.1.1 Field class</a>
</ul>
<!--End of Table of Child-Links-->
<DIV CLASS="navigation">
<p><hr>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="pyapi-util.html"><img src="icons/previous.gif"
border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="pyapi-util.html"><img src="icons/up.gif"
border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A href="pyapi-util-fstor-fld.html"><img src="icons/next.gif"
border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Mod_python Manual</td>
<td><A href="contents.html"><img src="icons/contents.gif"
border="0" height="32"
alt="Contents" width="32"></A></td>
<td><img src="icons/blank.gif"
border="0" height="32"
alt="" width="32"></td>
<td><A href="genindex.html"><img src="icons/index.gif"
border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="pyapi-util.html">4.4 util - Miscellaneous</A>
<b class="navlabel">Up:</b> <a class="sectref" href="pyapi-util.html">4.4 util - Miscellaneous</A>
<b class="navlabel">Next:</b> <a class="sectref" href="pyapi-util-fstor-fld.html">4.4.1.1 Field class</A>
<hr>
<span class="release-info">Release 2.7.10, documentation updated on December 07, 2003.</span>
</DIV>
<!--End of Navigation Panel-->
</BODY>
</HTML>
|