Changeset 391 for python/trunk/Doc/library/cgi.rst
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Doc/library/cgi.rst
r2 r391 14 14 single: Common Gateway Interface 15 15 16 **Source code:** :source:`Lib/cgi.py` 17 18 -------------- 19 16 20 Support module for Common Gateway Interface (CGI) scripts. 17 21 … … 78 82 79 83 import cgitb 80 cgitb.enable(display=0, logdir="/ tmp")84 cgitb.enable(display=0, logdir="/path/to/logdir") 81 85 82 86 It's very helpful to use this feature during script development. The reports … … 94 98 The :class:`FieldStorage` instance can be indexed like a Python dictionary. 95 99 It allows membership testing with the :keyword:`in` operator, and also supports 96 the standard dictionary method :meth:` keys` and the built-in function100 the standard dictionary method :meth:`~dict.keys` and the built-in function 97 101 :func:`len`. Form fields containing empty strings are ignored and do not appear 98 102 in the dictionary; to keep such values, provide a true value for the optional … … 116 120 Here the fields, accessed through ``form[key]``, are themselves instances of 117 121 :class:`FieldStorage` (or :class:`MiniFieldStorage`, depending on the form 118 encoding). The :attr:` value` attribute of the instance yields the string value119 of the field. The :meth:`getvalue` method returns this string value directly; 120 it also accepts an optional second argument as a default to return if the 121 requested key is not present.122 encoding). The :attr:`~FieldStorage.value` attribute of the instance yields 123 the string value of the field. The :meth:`~FieldStorage.getvalue` method 124 returns this string value directly; it also accepts an optional second argument 125 as a default to return if the requested key is not present. 122 126 123 127 If the submitted form data contains more than one field with the same name, the … … 126 130 this situation, ``form.getvalue(key)`` would return a list of strings. If you 127 131 expect this possibility (when your HTML form contains multiple fields with the 128 same name), use the : func:`getlist` function, which always returns a list of129 values (so that you do not need to special-case the single item case). For 130 example, this code concatenates any number of username fields, separated by 131 commas::132 same name), use the :meth:`~FieldStorage.getlist` method, which always returns 133 a list of values (so that you do not need to special-case the single item 134 case). For example, this code concatenates any number of username fields, 135 separated by commas:: 132 136 133 137 value = form.getlist("username") … … 135 139 136 140 If a field represents an uploaded file, accessing the value via the 137 :attr:`value` attribute or the :func:`getvalue` method reads the entire file in 138 memory as a string. This may not be what you want. You can test for an uploaded 139 file by testing either the :attr:`filename` attribute or the :attr:`!file` 141 :attr:`~FieldStorage.value` attribute or the :func:`~FieldStorage.getvalue` 142 method reads the entire file in memory as a string. This may not be what you 143 want. You can test for an uploaded file by testing either the 144 :attr:`~FieldStorage.filename` attribute or the :attr:`~FieldStorage.file` 140 145 attribute. You can then read the data at leisure from the :attr:`!file` 141 146 attribute:: … … 152 157 If an error is encountered when obtaining the contents of an uploaded file 153 158 (for example, when the user interrupts the form submission by clicking on 154 a Back or Cancel button) the :attr:` done` attribute of the object forthe155 field will be set to the value -1.159 a Back or Cancel button) the :attr:`~FieldStorage.done` attribute of the 160 object for the field will be set to the value -1. 156 161 157 162 The file upload draft standard entertains the possibility of uploading multiple … … 222 227 values. That's annoying and leads to less readable scripts. 223 228 224 A more convenient approach is to use the methods :meth:` getfirst` and225 :meth:`getlist` provided by this higher level interface.229 A more convenient approach is to use the methods :meth:`~FieldStorage.getfirst` 230 and :meth:`~FieldStorage.getlist` provided by this higher level interface. 226 231 227 232 … … 281 286 282 287 283 .. function:: parse(fp[, keep_blank_values[, strict_parsing]])288 .. function:: parse(fp[, environ[, keep_blank_values[, strict_parsing]]]) 284 289 285 290 Parse a query in the environment or from a file (the file defaults to 286 ``sys.stdin`` ). The *keep_blank_values* and *strict_parsing* parameters are291 ``sys.stdin`` and environment defaults to ``os.environ``). The *keep_blank_values* and *strict_parsing* parameters are 287 292 passed to :func:`urlparse.parse_qs` unchanged. 288 293 … … 350 355 sequences. Use this if you need to display text that might contain such 351 356 characters in HTML. If the optional flag *quote* is true, the quotation mark 352 character (``'"'``) is also translated; this helps for inclusion in an HTML 353 attribute value, as in ``<A HREF="...">``. If the value to be quoted might 354 include single- or double-quote characters, or both, consider using the 355 :func:`quoteattr` function in the :mod:`xml.sax.saxutils` module instead. 357 character (``"``) is also translated; this helps for inclusion in an HTML 358 attribute value delimited by double quotes, as in ``<a href="...">``. Note 359 that single quotes are never translated. 360 361 If the value to be quoted might include single- or double-quote characters, 362 or both, consider using the :func:`~xml.sax.saxutils.quoteattr` function in the 363 :mod:`xml.sax.saxutils` module instead. 356 364 357 365
Note:
See TracChangeset
for help on using the changeset viewer.