| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> |
| 5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> |
| 6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> |
| 7 | <link rel="first" href="lib.html" title='Python Library Reference' /> |
| 8 | <link rel='contents' href='contents.html' title="Contents" /> |
| 9 | <link rel='index' href='genindex.html' title='Index' /> |
| 10 | <link rel='last' href='about.html' title='About this document...' /> |
| 11 | <link rel='help' href='about.html' title='About this document...' /> |
| 12 | <link rel="next" href="cgi-security.html" /> |
| 13 | <link rel="prev" href="node473.html" /> |
| 14 | <link rel="parent" href="module-cgi.html" /> |
| 15 | <link rel="next" href="cgi-security.html" /> |
| 16 | <meta name='aesop' content='information' /> |
| 17 | <title>11.2.5 Functions</title> |
| 18 | </head> |
| 19 | <body> |
| 20 | <DIV CLASS="navigation"> |
| 21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> |
| 22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 23 | <tr> |
| 24 | <td class='online-navigation'><a rel="prev" title="11.2.4 Old classes" |
| 25 | href="node473.html"><img src='../icons/previous.png' |
| 26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 27 | <td class='online-navigation'><a rel="parent" title="11.2 cgi " |
| 28 | href="module-cgi.html"><img src='../icons/up.png' |
| 29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 30 | <td class='online-navigation'><a rel="next" title="11.2.6 Caring about security" |
| 31 | href="cgi-security.html"><img src='../icons/next.png' |
| 32 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 33 | <td align="center" width="100%">Python Library Reference</td> |
| 34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 35 | href="contents.html"><img src='../icons/contents.png' |
| 36 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 38 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 39 | <td class='online-navigation'><a rel="index" title="Index" |
| 40 | href="genindex.html"><img src='../icons/index.png' |
| 41 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 42 | </tr></table> |
| 43 | <div class='online-navigation'> |
| 44 | <b class="navlabel">Previous:</b> |
| 45 | <a class="sectref" rel="prev" href="node473.html">11.2.4 Old classes</A> |
| 46 | <b class="navlabel">Up:</b> |
| 47 | <a class="sectref" rel="parent" href="module-cgi.html">11.2 cgi </A> |
| 48 | <b class="navlabel">Next:</b> |
| 49 | <a class="sectref" rel="next" href="cgi-security.html">11.2.6 Caring about security</A> |
| 50 | </div> |
| 51 | <hr /></div> |
| 52 | </DIV> |
| 53 | <!--End of Navigation Panel--> |
| 54 | |
| 55 | <H2><A NAME="SECTION0013250000000000000000"> |
| 56 | 11.2.5 Functions</A> |
| 57 | </H2> |
| 58 | <A NAME="Functions_in_cgi_module"></A> |
| 59 | <P> |
| 60 | These are useful if you want more control, or if you want to employ |
| 61 | some of the algorithms implemented in this module in other |
| 62 | circumstances. |
| 63 | |
| 64 | <P> |
| 65 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 66 | <td><nobr><b><tt id='l2h-3161' xml:id='l2h-3161' class="function">parse</tt></b>(</nobr></td> |
| 67 | <td><var>fp</var><big>[</big><var>, keep_blank_values</var><big>[</big><var>, |
| 68 | strict_parsing</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> |
| 69 | <dd> |
| 70 | Parse a query in the environment or from a file (the file defaults |
| 71 | to <code>sys.stdin</code>). The <var>keep_blank_values</var> and |
| 72 | <var>strict_parsing</var> parameters are passed to <tt class="function">parse_qs()</tt> |
| 73 | unchanged. |
| 74 | </dl> |
| 75 | |
| 76 | <P> |
| 77 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 78 | <td><nobr><b><tt id='l2h-3162' xml:id='l2h-3162' class="function">parse_qs</tt></b>(</nobr></td> |
| 79 | <td><var>qs</var><big>[</big><var>, keep_blank_values</var><big>[</big><var>, |
| 80 | strict_parsing</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> |
| 81 | <dd> |
| 82 | Parse a query string given as a string argument (data of type |
| 83 | <span class="mimetype">application/x-www-form-urlencoded</span>). Data are |
| 84 | returned as a dictionary. The dictionary keys are the unique query |
| 85 | variable names and the values are lists of values for each name. |
| 86 | |
| 87 | <P> |
| 88 | The optional argument <var>keep_blank_values</var> is |
| 89 | a flag indicating whether blank values in |
| 90 | URL encoded queries should be treated as blank strings. |
| 91 | A true value indicates that blanks should be retained as |
| 92 | blank strings. The default false value indicates that |
| 93 | blank values are to be ignored and treated as if they were |
| 94 | not included. |
| 95 | |
| 96 | <P> |
| 97 | The optional argument <var>strict_parsing</var> is a flag indicating what |
| 98 | to do with parsing errors. If false (the default), errors |
| 99 | are silently ignored. If true, errors raise a ValueError |
| 100 | exception. |
| 101 | |
| 102 | <P> |
| 103 | Use the <tt class="function"><tt class="module"><a href="module-urllib.html">urllib</a></tt>.urlencode()</tt> function to convert |
| 104 | such dictionaries into query strings. |
| 105 | |
| 106 | <P> |
| 107 | </dl> |
| 108 | |
| 109 | <P> |
| 110 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 111 | <td><nobr><b><tt id='l2h-3163' xml:id='l2h-3163' class="function">parse_qsl</tt></b>(</nobr></td> |
| 112 | <td><var>qs</var><big>[</big><var>, keep_blank_values</var><big>[</big><var>, |
| 113 | strict_parsing</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> |
| 114 | <dd> |
| 115 | Parse a query string given as a string argument (data of type |
| 116 | <span class="mimetype">application/x-www-form-urlencoded</span>). Data are |
| 117 | returned as a list of name, value pairs. |
| 118 | |
| 119 | <P> |
| 120 | The optional argument <var>keep_blank_values</var> is |
| 121 | a flag indicating whether blank values in |
| 122 | URL encoded queries should be treated as blank strings. |
| 123 | A true value indicates that blanks should be retained as |
| 124 | blank strings. The default false value indicates that |
| 125 | blank values are to be ignored and treated as if they were |
| 126 | not included. |
| 127 | |
| 128 | <P> |
| 129 | The optional argument <var>strict_parsing</var> is a flag indicating what |
| 130 | to do with parsing errors. If false (the default), errors |
| 131 | are silently ignored. If true, errors raise a ValueError |
| 132 | exception. |
| 133 | |
| 134 | <P> |
| 135 | Use the <tt class="function"><tt class="module"><a href="module-urllib.html">urllib</a></tt>.urlencode()</tt> function to convert |
| 136 | such lists of pairs into query strings. |
| 137 | </dl> |
| 138 | |
| 139 | <P> |
| 140 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 141 | <td><nobr><b><tt id='l2h-3164' xml:id='l2h-3164' class="function">parse_multipart</tt></b>(</nobr></td> |
| 142 | <td><var>fp, pdict</var>)</td></tr></table></dt> |
| 143 | <dd> |
| 144 | Parse input of type <span class="mimetype">multipart/form-data</span> (for |
| 145 | file uploads). Arguments are <var>fp</var> for the input file and |
| 146 | <var>pdict</var> for a dictionary containing other parameters in |
| 147 | the <span class="mailheader">Content-Type:</span> header. |
| 148 | |
| 149 | <P> |
| 150 | Returns a dictionary just like <tt class="function">parse_qs()</tt> keys are the |
| 151 | field names, each value is a list of values for that field. This is |
| 152 | easy to use but not much good if you are expecting megabytes to be |
| 153 | uploaded -- in that case, use the <tt class="class">FieldStorage</tt> class instead |
| 154 | which is much more flexible. |
| 155 | |
| 156 | <P> |
| 157 | Note that this does not parse nested multipart parts -- use |
| 158 | <tt class="class">FieldStorage</tt> for that. |
| 159 | </dl> |
| 160 | |
| 161 | <P> |
| 162 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 163 | <td><nobr><b><tt id='l2h-3165' xml:id='l2h-3165' class="function">parse_header</tt></b>(</nobr></td> |
| 164 | <td><var>string</var>)</td></tr></table></dt> |
| 165 | <dd> |
| 166 | Parse a MIME header (such as <span class="mailheader">Content-Type:</span>) into a main |
| 167 | value and a dictionary of parameters. |
| 168 | </dl> |
| 169 | |
| 170 | <P> |
| 171 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 172 | <td><nobr><b><tt id='l2h-3166' xml:id='l2h-3166' class="function">test</tt></b>(</nobr></td> |
| 173 | <td><var></var>)</td></tr></table></dt> |
| 174 | <dd> |
| 175 | Robust test CGI script, usable as main program. |
| 176 | Writes minimal HTTP headers and formats all information provided to |
| 177 | the script in HTML form. |
| 178 | </dl> |
| 179 | |
| 180 | <P> |
| 181 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 182 | <td><nobr><b><tt id='l2h-3167' xml:id='l2h-3167' class="function">print_environ</tt></b>(</nobr></td> |
| 183 | <td><var></var>)</td></tr></table></dt> |
| 184 | <dd> |
| 185 | Format the shell environment in HTML. |
| 186 | </dl> |
| 187 | |
| 188 | <P> |
| 189 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 190 | <td><nobr><b><tt id='l2h-3168' xml:id='l2h-3168' class="function">print_form</tt></b>(</nobr></td> |
| 191 | <td><var>form</var>)</td></tr></table></dt> |
| 192 | <dd> |
| 193 | Format a form in HTML. |
| 194 | </dl> |
| 195 | |
| 196 | <P> |
| 197 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 198 | <td><nobr><b><tt id='l2h-3169' xml:id='l2h-3169' class="function">print_directory</tt></b>(</nobr></td> |
| 199 | <td><var></var>)</td></tr></table></dt> |
| 200 | <dd> |
| 201 | Format the current directory in HTML. |
| 202 | </dl> |
| 203 | |
| 204 | <P> |
| 205 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 206 | <td><nobr><b><tt id='l2h-3170' xml:id='l2h-3170' class="function">print_environ_usage</tt></b>(</nobr></td> |
| 207 | <td><var></var>)</td></tr></table></dt> |
| 208 | <dd> |
| 209 | Print a list of useful (used by CGI) environment variables in |
| 210 | HTML. |
| 211 | </dl> |
| 212 | |
| 213 | <P> |
| 214 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 215 | <td><nobr><b><tt id='l2h-3171' xml:id='l2h-3171' class="function">escape</tt></b>(</nobr></td> |
| 216 | <td><var>s</var><big>[</big><var>, quote</var><big>]</big><var></var>)</td></tr></table></dt> |
| 217 | <dd> |
| 218 | Convert the characters |
| 219 | "<tt class="character">&</tt>", "<tt class="character"><</tt>" and "<tt class="character">></tt>" in string <var>s</var> to |
| 220 | HTML-safe sequences. Use this if you need to display text that might |
| 221 | contain such characters in HTML. If the optional flag <var>quote</var> is |
| 222 | true, the double-quote character ("<tt class="character">"</tt>") is also translated; |
| 223 | this helps for inclusion in an HTML attribute value, as in <code><A |
| 224 | HREF="..."></code>. If the value to be quoted might include single- or |
| 225 | double-quote characters, or both, consider using the |
| 226 | <tt class="function">quoteattr()</tt> function in the <tt class="module"><a href="module-xml.sax.saxutils.html">xml.sax.saxutils</a></tt> |
| 227 | module instead. |
| 228 | </dl> |
| 229 | |
| 230 | <P> |
| 231 | |
| 232 | <DIV CLASS="navigation"> |
| 233 | <div class='online-navigation'> |
| 234 | <p></p><hr /> |
| 235 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 236 | <tr> |
| 237 | <td class='online-navigation'><a rel="prev" title="11.2.4 Old classes" |
| 238 | href="node473.html"><img src='../icons/previous.png' |
| 239 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 240 | <td class='online-navigation'><a rel="parent" title="11.2 cgi " |
| 241 | href="module-cgi.html"><img src='../icons/up.png' |
| 242 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 243 | <td class='online-navigation'><a rel="next" title="11.2.6 Caring about security" |
| 244 | href="cgi-security.html"><img src='../icons/next.png' |
| 245 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 246 | <td align="center" width="100%">Python Library Reference</td> |
| 247 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 248 | href="contents.html"><img src='../icons/contents.png' |
| 249 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 250 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 251 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 252 | <td class='online-navigation'><a rel="index" title="Index" |
| 253 | href="genindex.html"><img src='../icons/index.png' |
| 254 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 255 | </tr></table> |
| 256 | <div class='online-navigation'> |
| 257 | <b class="navlabel">Previous:</b> |
| 258 | <a class="sectref" rel="prev" href="node473.html">11.2.4 Old classes</A> |
| 259 | <b class="navlabel">Up:</b> |
| 260 | <a class="sectref" rel="parent" href="module-cgi.html">11.2 cgi </A> |
| 261 | <b class="navlabel">Next:</b> |
| 262 | <a class="sectref" rel="next" href="cgi-security.html">11.2.6 Caring about security</A> |
| 263 | </div> |
| 264 | </div> |
| 265 | <hr /> |
| 266 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> |
| 267 | </DIV> |
| 268 | <!--End of Navigation Panel--> |
| 269 | <ADDRESS> |
| 270 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. |
| 271 | </ADDRESS> |
| 272 | </BODY> |
| 273 | </HTML> |