~ubuntu-branches/ubuntu/jaunty/libapache2-mod-python/jaunty

« back to all changes in this revision

Viewing changes to doc-html/pyapi-util-fstor.html

  • Committer: Bazaar Package Importer
  • Author(s): Thom May
  • Date: 2004-09-06 20:27:57 UTC
  • Revision ID: james.westby@ubuntu.com-20040906202757-yzpyu1bcabgpjtiu
Tags: upstream-3.1.3
ImportĀ upstreamĀ versionĀ 3.1.3

Show diffs side-by-side

added added

removed removed

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