|
Server : Apache/2.2.2 (Fedora) System : Linux App1.pathumtani.go.th 2.6.20-1.2320.fc5smp #1 SMP Tue Jun 12 19:40:16 EDT 2007 i686 User : apache ( 48) PHP Version : 5.2.9 Disable Function : NONE Directory : /var/www/manual/mod/mod_python/ |
Upload File : |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="modpython.css" type='text/css'>
<link rel="first" href="modpython.html" title='Mod_python Manual'>
<link rel='contents' href='contents.html' title="Contents">
<link rel='index' href='genindex.html' title='Index'>
<link rel='last' href='about.html' title='About this document...'>
<link rel='help' href='about.html' title='About this document...'>
<LINK REL="next" href="pyapi-util-fstor-fld.html">
<LINK REL="prev" href="pyapi-util.html">
<LINK REL="parent" href="pyapi-util.html">
<LINK REL="next" href="pyapi-util-fstor-fld.html">
<meta name='aesop' content='information'>
<META NAME="description" CONTENT="FieldStorage class">
<META NAME="keywords" CONTENT="modpython">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<title>4.6.1 FieldStorage class</title>
</head>
<body>
<DIV CLASS="navigation">
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><a rel="prev" title="4.6 util - Miscellaneous"
href="pyapi-util.html"><img src='previous.gif'
border='0' height='32' alt='Previous Page' width='32'></A></td>
<td><a rel="parent" title="4.6 util - Miscellaneous"
href="pyapi-util.html"><img src='up.gif'
border='0' height='32' alt='Up One Level' width='32'></A></td>
<td><a rel="next" title="4.6.2 Field class"
href="pyapi-util-fstor-fld.html"><img src='next.gif'
border='0' height='32' alt='Next Page' width='32'></A></td>
<td align="center" width="100%">Mod_python Manual</td>
<td><a rel="contents" title="Table of Contents"
href="contents.html"><img src='contents.gif'
border='0' height='32' alt='Contents' width='32'></A></td>
<td><img src='blank.gif'
border='0' height='32' alt='' width='32'></td>
<td><a rel="index" title="Index"
href="genindex.html"><img src='index.gif'
border='0' height='32' alt='Index' width='32'></A></td>
</tr></table>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="pyapi-util.html">4.6 util - Miscellaneous</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="pyapi-util.html">4.6 util - Miscellaneous</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="pyapi-util-fstor-fld.html">4.6.2 Field class</A>
<br><hr>
</DIV>
<!--End of Navigation Panel-->
<H2><A NAME="SECTION006610000000000000000"> </A>
<BR>
4.6.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>.
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><span class="typelabel">class</span> <a name="l2h-183"><tt class="class">FieldStorage</tt></a></b>(</nobr></td>
<td><var>req</var><big>[</big><var>, keep_blank_values, strict_parsing</var><big>]</big>)</td></tr></table>
<dd>
This class provides uniform access to HTML form data submitted by the
client. <var>req</var> is an instance of the mod_python request 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.
<P>
During initialization, <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 single 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 mapping, the keys are
form input names, and the returned dictionary value can be:
<P>
<UL>
<LI>An instance of <tt class="class">StringField</tt>, containing the form input
value. This is only when there is a single value corresponding to the
input name. <tt class="class">StringField</tt> is a subclass of <tt class="class">str</tt> which
provides the additional <tt class="member">value</tt> attribute for compatibility
with standard library <tt class="module">cgi</tt> module.
</LI>
<LI>An instance of a <tt class="class">Field</tt> class, if the input is a file upload.
</LI>
<LI>A list of <tt class="class">StringField</tt> 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>
<div class="note"><b class="label">Note:</b>
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. In all other cases the
return is an instance of <tt class="class">StringField</tt>. This means that you
do not need to use the <tt class="member">.value</tt> attribute to access values
of fields in most cases.
</div>
<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-184"><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>
<tt class="class">FieldStorage</tt> methods:
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><a name="l2h-185"><tt class="method">getfirst</tt></a></b>(</nobr></td>
<td><var>name</var><big>[</big><var>, default</var><big>]</big>)</td></tr></table>
<dd>
Always returns only one value associated with form field
<var>name</var>. If no such form field or value exists then the method
returns the value specified by the optional parameter
<var>default</var>. This parameter defaults to <code>None</code> if not
specified.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><a name="l2h-186"><tt class="method">getlist</tt></a></b>(</nobr></td>
<td><var>name</var>)</td></tr></table>
<dd>
This method always returns a list of values associated with form
field <var>name</var>. The method returns an empty list if no such form
field or value exists for <var>name</var>. It returns a list consisting
of one item if only one such value exists.
</dl>
<P>
</dl>
<P>
<DIV CLASS="navigation">
<p><hr>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><a rel="prev" title="4.6 util - Miscellaneous"
rel="prev" title="4.6 util - Miscellaneous"
href="pyapi-util.html"><img src='previous.gif'
border='0' height='32' alt='Previous Page' width='32'></A></td>
<td><a rel="parent" title="4.6 util - Miscellaneous"
rel="parent" title="4.6 util - Miscellaneous"
href="pyapi-util.html"><img src='up.gif'
border='0' height='32' alt='Up One Level' width='32'></A></td>
<td><a rel="next" title="4.6.2 Field class"
rel="next" title="4.6.2 Field class"
href="pyapi-util-fstor-fld.html"><img src='next.gif'
border='0' height='32' alt='Next Page' width='32'></A></td>
<td align="center" width="100%">Mod_python Manual</td>
<td><a rel="contents" title="Table of Contents"
rel="contents" title="Table of Contents"
href="contents.html"><img src='contents.gif'
border='0' height='32' alt='Contents' width='32'></A></td>
<td><img src='blank.gif'
border='0' height='32' alt='' width='32'></td>
<td><a rel="index" title="Index"
rel="index" title="Index"
href="genindex.html"><img src='index.gif'
border='0' height='32' alt='Index' width='32'></A></td>
</tr></table>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="pyapi-util.html">4.6 util - Miscellaneous</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="pyapi-util.html">4.6 util - Miscellaneous</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="pyapi-util-fstor-fld.html">4.6.2 Field class</A>
<hr>
<span class="release-info">Release 3.2.8, documentation updated on February 19, 2006.</span>
</DIV>
<!--End of Navigation Panel-->
</BODY>
</HTML>