Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Doc/library/cgi.rst

    r2 r391  
    1414   single: Common Gateway Interface
    1515
     16**Source code:** :source:`Lib/cgi.py`
     17
     18--------------
     19
    1620Support module for Common Gateway Interface (CGI) scripts.
    1721
     
    7882
    7983   import cgitb
    80    cgitb.enable(display=0, logdir="/tmp")
     84   cgitb.enable(display=0, logdir="/path/to/logdir")
    8185
    8286It's very helpful to use this feature during script development. The reports
     
    9498The :class:`FieldStorage` instance can be indexed like a Python dictionary.
    9599It allows membership testing with the :keyword:`in` operator, and also supports
    96 the standard dictionary method :meth:`keys` and the built-in function
     100the standard dictionary method :meth:`~dict.keys` and the built-in function
    97101:func:`len`.  Form fields containing empty strings are ignored and do not appear
    98102in the dictionary; to keep such values, provide a true value for the optional
     
    116120Here the fields, accessed through ``form[key]``, are themselves instances of
    117121:class:`FieldStorage` (or :class:`MiniFieldStorage`, depending on the form
    118 encoding). The :attr:`value` attribute of the instance yields the string value
    119 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.
     122encoding). The :attr:`~FieldStorage.value` attribute of the instance yields
     123the string value of the field.  The :meth:`~FieldStorage.getvalue` method
     124returns this string value directly; it also accepts an optional second argument
     125as a default to return if the requested key is not present.
    122126
    123127If the submitted form data contains more than one field with the same name, the
     
    126130this situation, ``form.getvalue(key)`` would return a list of strings. If you
    127131expect this possibility (when your HTML form contains multiple fields with the
    128 same name), use the :func:`getlist` function, which always returns a list of
    129 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::
     132same name), use the :meth:`~FieldStorage.getlist` method, which always returns
     133a list of values (so that you do not need to special-case the single item
     134case).  For example, this code concatenates any number of username fields,
     135separated by commas::
    132136
    133137   value = form.getlist("username")
     
    135139
    136140If 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`
     142method reads the entire file in memory as a string.  This may not be what you
     143want. You can test for an uploaded file by testing either the
     144:attr:`~FieldStorage.filename` attribute or the :attr:`~FieldStorage.file`
    140145attribute.  You can then read the data at leisure from the :attr:`!file`
    141146attribute::
     
    152157If an error is encountered when obtaining the contents of an uploaded file
    153158(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 for the
    155 field will be set to the value -1.
     159a Back or Cancel button) the :attr:`~FieldStorage.done` attribute of the
     160object for the field will be set to the value -1.
    156161
    157162The file upload draft standard entertains the possibility of uploading multiple
     
    222227values.  That's annoying and leads to less readable scripts.
    223228
    224 A more convenient approach is to use the methods :meth:`getfirst` and
    225 :meth:`getlist` provided by this higher level interface.
     229A more convenient approach is to use the methods :meth:`~FieldStorage.getfirst`
     230and :meth:`~FieldStorage.getlist` provided by this higher level interface.
    226231
    227232
     
    281286
    282287
    283 .. function:: parse(fp[, keep_blank_values[, strict_parsing]])
     288.. function:: parse(fp[, environ[, keep_blank_values[, strict_parsing]]])
    284289
    285290   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 are
     291   ``sys.stdin`` and environment defaults to ``os.environ``).  The *keep_blank_values* and *strict_parsing* parameters are
    287292   passed to :func:`urlparse.parse_qs` unchanged.
    288293
     
    350355   sequences.  Use this if you need to display text that might contain such
    351356   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.
    356364
    357365
Note: See TracChangeset for help on using the changeset viewer.