cgi (version 2.6)
index
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/cgi.py
Module Docs

Support module for CGI (Common Gateway Interface) scripts.
 
This module defines a number of utilities for use by CGI scripts
written in Python.

 
Modules
       
UserDict
mimetools
os
rfc822
sys
urlparse

 
Classes
       
UserDict.UserDict
FormContentDict
FormContent
SvFormContentDict
InterpFormContentDict
FieldStorage
MiniFieldStorage

 
class FieldStorage
    Store a sequence of fields, reading multipart/form-data.
 
This class provides naming, typing, files stored on disk, and
more.  At the top level, it is accessible like a dictionary, whose
keys are the field names.  (Note: None can occur as a field name.)
The items are either a Python list (if there's multiple values) or
another FieldStorage or MiniFieldStorage object.  If it's a single
object, it has the following attributes:
 
name: the field name, if specified; otherwise None
 
filename: the filename, if specified; otherwise None; this is the
    client side filename, *not* the file name on which it is
    stored (that's a temporary file you don't deal with)
 
value: the value as a *string*; for file uploads, this
    transparently reads the file every time you request the value
 
file: the file(-like) object from which you can read the data;
    None if the data is stored a simple string
 
type: the content-type, or None if not specified
 
type_options: dictionary of options specified on the content-type
    line
 
disposition: content-disposition, or None if not specified
 
disposition_options: dictionary of corresponding options
 
headers: a dictionary(-like) object (sometimes rfc822.Message or a
    subclass thereof) containing *all* headers
 
The class is subclassable, mostly for the purpose of overriding
the make_file() method, which is called internally to come up with
a file open for reading and writing.  This makes it possible to
override the default choice of storing all files in a temporary
directory and unlinking them as soon as they have been opened.
 
  Methods defined here:
__contains__(self, key)
Dictionary style __contains__ method.
__getattr__(self, name)
__getitem__(self, key)
Dictionary style indexing.
__init__(self, fp=None, headers=None, outerboundary='', environ={'VERSIONER_PYTHON_PREFER_32_BIT': 'no', 'TERM_P...2HTML', '_JAVA_OPTIONS': '-Dfile.encoding=UTF-8'}, keep_blank_values=0, strict_parsing=0)
Constructor.  Read multipart/* until last part.
 
Arguments, all optional:
 
fp              : file pointer; default: sys.stdin
    (not used when the request method is GET)
 
headers         : header dictionary-like object; default:
    taken from environ as per CGI spec
 
outerboundary   : terminating multipart boundary
    (for internal use only)
 
environ         : environment dictionary; default: os.environ
 
keep_blank_values: flag indicating whether blank values in
    percent-encoded forms 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.
 
strict_parsing: flag indicating what to do with parsing errors.
    If false (the default), errors are silently ignored.
    If true, errors raise a ValueError exception.
__iter__(self)
__len__(self)
Dictionary style len(x) support.
__nonzero__(self)
__repr__(self)
Return a printable representation.
getfirst(self, key, default=None)
Return the first value received.
getlist(self, key)
Return list of received values.
getvalue(self, key, default=None)
Dictionary style get() method, including 'value' lookup.
has_key(self, key)
Dictionary style has_key() method.
keys(self)
Dictionary style keys() method.
make_file(self, binary=None)
Overridable: return a readable & writable file.
 
The file will be used as follows:
- data is written to it
- seek(0)
- data is read from it
 
The 'binary' argument is unused -- the file is always opened
in binary mode.
 
This version opens a temporary file for reading and writing,
and immediately deletes (unlinks) it.  The trick (on Unix!) is
that the file can still be used, but it can't be opened by
another process, and it will automatically be deleted when it
is closed or when the current process terminates.
 
If you want a more permanent file, you derive a class which
overrides this method.  If you want a visible temporary file
that is nevertheless automatically deleted when the script
terminates, try defining a __del__ method in a derived class
which unlinks the temporary files you have created.
read_binary(self)
Internal: read binary data.
read_lines(self)
Internal: read lines until EOF or outerboundary.
read_lines_to_eof(self)
Internal: read lines until EOF.
read_lines_to_outerboundary(self)
Internal: read lines until outerboundary.
read_multi(self, environ, keep_blank_values, strict_parsing)
Internal: read a part that is itself multipart.
read_single(self)
Internal: read an atomic part.
read_urlencoded(self)
Internal: read data in query string format.
skip_lines(self)
Internal: skip lines until outer boundary if defined.

Data and other attributes defined here:
FieldStorageClass = None
bufsize = 8192

 
class FormContent(FormContentDict)
    This class is present for backwards compatibility only.
 
 
Method resolution order:
FormContent
FormContentDict
UserDict.UserDict

Methods defined here:
indexed_value(self, key, location)
length(self, key)
pars(self)
stripped(self, key)
value(self, key)
values(self, key)

Methods inherited from FormContentDict:
__init__(self, environ={'VERSIONER_PYTHON_PREFER_32_BIT': 'no', 'TERM_P...2HTML', '_JAVA_OPTIONS': '-Dfile.encoding=UTF-8'}, keep_blank_values=0, strict_parsing=0)

Methods inherited from UserDict.UserDict:
__cmp__(self, dict)
__contains__(self, key)
__delitem__(self, key)
__getitem__(self, key)
__len__(self)
__repr__(self)
__setitem__(self, key, item)
clear(self)
copy(self)
get(self, key, failobj=None)
has_key(self, key)
items(self)
iteritems(self)
iterkeys(self)
itervalues(self)
keys(self)
pop(self, key, *args)
popitem(self)
setdefault(self, key, failobj=None)
update(self, dict=None, **kwargs)

Class methods inherited from UserDict.UserDict:
fromkeys(cls, iterable, value=None) from __builtin__.classobj

Data and other attributes inherited from UserDict.UserDict:
__hash__ = None

 
class FormContentDict(UserDict.UserDict)
    Form content as dictionary with a list of values per field.
 
form = FormContentDict()
 
form[key] -> [value, value, ...]
key in form -> Boolean
form.keys() -> [key, key, ...]
form.values() -> [[val, val, ...], [val, val, ...], ...]
form.items() ->  [(key, [val, val, ...]), (key, [val, val, ...]), ...]
form.dict == {key: [val, val, ...], ...}
 
  Methods defined here:
__init__(self, environ={'VERSIONER_PYTHON_PREFER_32_BIT': 'no', 'TERM_P...2HTML', '_JAVA_OPTIONS': '-Dfile.encoding=UTF-8'}, keep_blank_values=0, strict_parsing=0)

Methods inherited from UserDict.UserDict:
__cmp__(self, dict)
__contains__(self, key)
__delitem__(self, key)
__getitem__(self, key)
__len__(self)
__repr__(self)
__setitem__(self, key, item)
clear(self)
copy(self)
get(self, key, failobj=None)
has_key(self, key)
items(self)
iteritems(self)
iterkeys(self)
itervalues(self)
keys(self)
pop(self, key, *args)
popitem(self)
setdefault(self, key, failobj=None)
update(self, dict=None, **kwargs)
values(self)

Class methods inherited from UserDict.UserDict:
fromkeys(cls, iterable, value=None) from __builtin__.classobj

Data and other attributes inherited from UserDict.UserDict:
__hash__ = None

 
class InterpFormContentDict(SvFormContentDict)
    This class is present for backwards compatibility only.
 
 
Method resolution order:
InterpFormContentDict
SvFormContentDict
FormContentDict
UserDict.UserDict

Methods defined here:
__getitem__(self, key)
items(self)
values(self)

Methods inherited from SvFormContentDict:
getlist(self, key)

Methods inherited from FormContentDict:
__init__(self, environ={'VERSIONER_PYTHON_PREFER_32_BIT': 'no', 'TERM_P...2HTML', '_JAVA_OPTIONS': '-Dfile.encoding=UTF-8'}, keep_blank_values=0, strict_parsing=0)

Methods inherited from UserDict.UserDict:
__cmp__(self, dict)
__contains__(self, key)
__delitem__(self, key)
__len__(self)
__repr__(self)
__setitem__(self, key, item)
clear(self)
copy(self)
get(self, key, failobj=None)
has_key(self, key)
iteritems(self)
iterkeys(self)
itervalues(self)
keys(self)
pop(self, key, *args)
popitem(self)
setdefault(self, key, failobj=None)
update(self, dict=None, **kwargs)

Class methods inherited from UserDict.UserDict:
fromkeys(cls, iterable, value=None) from __builtin__.classobj

Data and other attributes inherited from UserDict.UserDict:
__hash__ = None

 
class MiniFieldStorage
    Like FieldStorage, for use when no file uploads are possible.
 
  Methods defined here:
__init__(self, name, value)
Constructor from field name and value.
__repr__(self)
Return printable representation.

Data and other attributes defined here:
disposition = None
disposition_options = {}
file = None
filename = None
headers = {}
list = None
type = None
type_options = {}

 
class SvFormContentDict(FormContentDict)
    Form content as dictionary expecting a single value per field.
 
If you only expect a single value for each field, then form[key]
will return that single value.  It will raise an IndexError if
that expectation is not true.  If you expect a field to have
possible multiple values, than you can use form.getlist(key) to
get all of the values.  values() and items() are a compromise:
they return single strings where there is a single value, and
lists of strings otherwise.
 
 
Method resolution order:
SvFormContentDict
FormContentDict
UserDict.UserDict

Methods defined here:
__getitem__(self, key)
getlist(self, key)
items(self)
values(self)

Methods inherited from FormContentDict:
__init__(self, environ={'VERSIONER_PYTHON_PREFER_32_BIT': 'no', 'TERM_P...2HTML', '_JAVA_OPTIONS': '-Dfile.encoding=UTF-8'}, keep_blank_values=0, strict_parsing=0)

Methods inherited from UserDict.UserDict:
__cmp__(self, dict)
__contains__(self, key)
__delitem__(self, key)
__len__(self)
__repr__(self)
__setitem__(self, key, item)
clear(self)
copy(self)
get(self, key, failobj=None)
has_key(self, key)
iteritems(self)
iterkeys(self)
itervalues(self)
keys(self)
pop(self, key, *args)
popitem(self)
setdefault(self, key, failobj=None)
update(self, dict=None, **kwargs)

Class methods inherited from UserDict.UserDict:
fromkeys(cls, iterable, value=None) from __builtin__.classobj

Data and other attributes inherited from UserDict.UserDict:
__hash__ = None

 
Functions
       
escape(s, quote=None)
Replace special characters "&", "<" and ">" to HTML-safe sequences.
If the optional flag quote is true, the quotation mark character (")
is also translated.
parse(fp=None, environ={'VERSIONER_PYTHON_PREFER_32_BIT': 'no', 'TERM_P...2HTML', '_JAVA_OPTIONS': '-Dfile.encoding=UTF-8'}, keep_blank_values=0, strict_parsing=0)
Parse a query in the environment or from a file (default stdin)
 
Arguments, all optional:
 
fp              : file pointer; default: sys.stdin
 
environ         : environment dictionary; default: os.environ
 
keep_blank_values: flag indicating whether blank values in
    percent-encoded forms 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.
 
strict_parsing: flag indicating what to do with parsing errors.
    If false (the default), errors are silently ignored.
    If true, errors raise a ValueError exception.
parse_header(line)
Parse a Content-type like header.
 
Return the main content-type and a dictionary of options.
parse_multipart(fp, pdict)
Parse multipart input.
 
Arguments:
fp   : input file
pdict: dictionary containing other parameters of content-type header
 
Returns a dictionary just like parse_qs(): 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 FieldStorage class instead which is much more flexible.  Note
that content-type is the raw, unparsed contents of the content-type
header.
 
XXX This does not parse nested multipart parts -- use FieldStorage for
that.
 
XXX This should really be subsumed by FieldStorage altogether -- no
point in having two implementations of the same parsing algorithm.
Also, FieldStorage protects itself better against certain DoS attacks
by limiting the size of the data read in one chunk.  The API here
does not support that kind of protection.  This also affects parse()
since it can call parse_multipart().
parse_qs(qs, keep_blank_values=0, strict_parsing=0)
Parse a query given as a string argument.
parse_qsl(qs, keep_blank_values=0, strict_parsing=0)
Parse a query given as a string argument.
print_arguments()
print_directory()
Dump the current directory as HTML.
print_environ(environ={'VERSIONER_PYTHON_PREFER_32_BIT': 'no', 'TERM_P...2HTML', '_JAVA_OPTIONS': '-Dfile.encoding=UTF-8'})
Dump the shell environment as HTML.
print_environ_usage()
Dump a list of environment variables used by CGI as HTML.
print_exception(type=None, value=None, tb=None, limit=None)
print_form(form)
Dump the contents of a form as HTML.

 
Data
        __all__ = ['MiniFieldStorage', 'FieldStorage', 'FormContentDict', 'SvFormContentDict', 'InterpFormContentDict', 'FormContent', 'parse', 'parse_qs', 'parse_qsl', 'parse_multipart', 'parse_header', 'print_exception', 'print_environ', 'print_form', 'print_directory', 'print_arguments', 'print_environ_usage', 'escape']
__version__ = '2.6'