📄 functions_in_cgi_module.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>11.2.4 Functions</title>
<META NAME="description" CONTENT="11.2.4 Functions">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="lib.css" tppabs="http://www.python.org/doc/current/lib/lib.css">
<LINK REL="next" HREF="node243.html" tppabs="http://www.python.org/doc/current/lib/node243.html">
<LINK REL="previous" HREF="node241.html" tppabs="http://www.python.org/doc/current/lib/node241.html">
<LINK REL="up" href="module-cgi.html" tppabs="http://www.python.org/doc/current/lib/module-cgi.html">
<LINK REL="next" HREF="node243.html" tppabs="http://www.python.org/doc/current/lib/node243.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A HREF="node241.html" tppabs="http://www.python.org/doc/current/lib/node241.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="module-cgi.html" tppabs="http://www.python.org/doc/current/lib/module-cgi.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A HREF="node243.html" tppabs="http://www.python.org/doc/current/lib/node243.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" HREF="node241.html" tppabs="http://www.python.org/doc/current/lib/node241.html">11.2.3 Old classes</A>
<b class="navlabel">Up:</b> <a class="sectref" href="module-cgi.html" tppabs="http://www.python.org/doc/current/lib/module-cgi.html">11.2 cgi </A>
<b class="navlabel">Next:</b> <a class="sectref" HREF="node243.html" tppabs="http://www.python.org/doc/current/lib/node243.html">11.2.5 Caring about security</A>
<br><hr></DIV>
<!--End of Navigation Panel-->
<H2><A NAME="SECTION0013240000000000000000">
11.2.4 Functions</A>
</H2>
<P>
These are useful if you want more control, or if you want to employ
some of the algorithms implemented in this module in other
circumstances.
<P>
<dl><dt><b><a name='l2h-1978'><tt class='function'>parse</tt></a></b> (<var>fp</var>)
<dd>
Parse a query in the environment or from a file (default
<code>sys.stdin</code>).
</dl>
<P>
<dl><dt><b><a name='l2h-1979'><tt class='function'>parse_qs</tt></a></b> (<var>qs</var><big>[</big><var>, keep_blank_values, strict_parsing</var><big>]</big>)
<dd>
Parse a query string given as a string argument (data of type
<span class="mimetype">application/x-www-form-urlencoded</span>). Data are
returned as a dictionary. The dictionary keys are the unique query
variable names and the values are lists of values for each name.
<P>
The optional argument <var>keep_blank_values</var> is
a flag indicating whether blank values in
URL encoded queries should be treated as blank strings.
A true value indicates that blanks should be retained as
blank strings. The default false value indicates that
blank values are to be ignored and treated as if they were
not included.
<P>
The optional argument <var>strict_parsing</var> is a flag indicating what
to do with parsing errors. If false (the default), errors
are silently ignored. If true, errors raise a ValueError
exception.
</dl>
<P>
<dl><dt><b><a name='l2h-1980'><tt class='function'>parse_qsl</tt></a></b> (<var>qs</var><big>[</big><var>, keep_blank_values, strict_parsing</var><big>]</big>)
<dd>
Parse a query string given as a string argument (data of type
<span class="mimetype">application/x-www-form-urlencoded</span>). Data are
returned as a list of name, value pairs.
<P>
The optional argument <var>keep_blank_values</var> is
a flag indicating whether blank values in
URL encoded queries should be treated as blank strings.
A true value indicates that blanks should be retained as
blank strings. The default false value indicates that
blank values are to be ignored and treated as if they were
not included.
<P>
The optional argument <var>strict_parsing</var> is a flag indicating what
to do with parsing errors. If false (the default), errors
are silently ignored. If true, errors raise a ValueError
exception.
</dl>
<P>
<dl><dt><b><a name='l2h-1981'><tt class='function'>parse_multipart</tt></a></b> (<var>fp, pdict</var>)
<dd>
Parse input of type <span class="mimetype">multipart/form-data</span> (for
file uploads). Arguments are <var>fp</var> for the input file and
<var>pdict</var> for a dictionary containing other parameters in
the <code>Content-Type</code> header.
<P>
Returns a dictionary just like <tt class="function">parse_qs()</tt> keys are the
field names, each value is a list of values for that field. This is
easy to use but not much good if you are expecting megabytes to be
uploaded -- in that case, use the <tt class="class">FieldStorage</tt> class instead
which is much more flexible.
<P>
Note that this does not parse nested multipart parts -- use
<tt class="class">FieldStorage</tt> for that.
</dl>
<P>
<dl><dt><b><a name='l2h-1982'><tt class='function'>parse_header</tt></a></b> (<var>string</var>)
<dd>
Parse a MIME header (such as <code>Content-Type</code>) into a main
value and a dictionary of parameters.
</dl>
<P>
<dl><dt><b><a name='l2h-1983'><tt class='function'>test</tt></a></b> ()
<dd>
Robust test CGI script, usable as main program.
Writes minimal HTTP headers and formats all information provided to
the script in HTML form.
</dl>
<P>
<dl><dt><b><a name='l2h-1984'><tt class='function'>print_environ</tt></a></b> ()
<dd>
Format the shell environment in HTML.
</dl>
<P>
<dl><dt><b><a name='l2h-1985'><tt class='function'>print_form</tt></a></b> (<var>form</var>)
<dd>
Format a form in HTML.
</dl>
<P>
<dl><dt><b><a name='l2h-1986'><tt class='function'>print_directory</tt></a></b> ()
<dd>
Format the current directory in HTML.
</dl>
<P>
<dl><dt><b><a name='l2h-1987'><tt class='function'>print_environ_usage</tt></a></b> ()
<dd>
Print a list of useful (used by CGI) environment variables in
HTML.
</dl>
<P>
<dl><dt><b><a name='l2h-1988'><tt class='function'>escape</tt></a></b> (<var>s</var><big>[</big><var>, quote</var><big>]</big>)
<dd>
Convert the characters
"<tt class="character">&</tt>", "<tt class="character"><</tt>" and "<tt class="character">></tt>" in string <var>s</var> to
HTML-safe sequences. Use this if you need to display text that might
contain such characters in HTML. If the optional flag <var>quote</var> is
true, the double quote character ("<tt class="character">"</tt>") is also translated;
this helps for inclusion in an HTML attribute value, e.g. in <code><A
HREF="..."></code>.
</dl>
<P>
<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A HREF="node241.html" tppabs="http://www.python.org/doc/current/lib/node241.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="module-cgi.html" tppabs="http://www.python.org/doc/current/lib/module-cgi.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A HREF="node243.html" tppabs="http://www.python.org/doc/current/lib/node243.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" HREF="node241.html" tppabs="http://www.python.org/doc/current/lib/node241.html">11.2.3 Old classes</A>
<b class="navlabel">Up:</b> <a class="sectref" href="module-cgi.html" tppabs="http://www.python.org/doc/current/lib/module-cgi.html">11.2 cgi </A>
<b class="navlabel">Next:</b> <a class="sectref" HREF="node243.html" tppabs="http://www.python.org/doc/current/lib/node243.html">11.2.5 Caring about security</A>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>See <i><a href="about.html" tppabs="http://www.python.org/doc/current/lib/about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -