Access to form data is provided via the FieldStorage class. This class is similar to the standard library module cgi FieldStorage.
req[, keep_blank_values, strict_parsing, file_callback, field_callback])|
The optional argument keep_blank_values is a flag indicating whether blank values in URL encoded form data should be treated as blank strings. The default is false, which means that blank values are ignored as if they were not included.
The optional argument strict_parsing is not yet implemented.
The optional argument file_callback allows the application to override both file creation/deletion semantics and location. See 4.6.2 ``FieldStorage Examples'' for additional information. New in version 3.2
The optional argument field_callback allows the application to override both the creation/deletion semantics and behaviour. New in version 3.2
During initialization, FieldStorage class reads all of the
data provided by the client. Since all data provided by the client is
consumed at this point, there should be no more than one
FieldStorage class instantiated per single request, nor should
you make any attempts to read client data before or after
instantiating a FieldStorage. A suggested strategy for dealing
with this is that any handler should first check for the existance of
attribute within the request object. If this exists, it
should be taken to be an existing instance of the FieldStorage
class and that should be used. If the attribute does not exist
and needs to be created, it should be cached as the form
attribute of the request object so later handler code can use it.
When the FieldStorage class instance is created, the data read
from the client is then parsed into separate fields and packaged in
Field objects, one per field. For HTML form inputs of type
, a temporary file is created that can later be accessed via
the file attribute of a Field object.
The FieldStorage class has a mapping object interface, i.e. it can be treated like a dictionary in most instances, but is not strictly compatible as is it missing some methods provided by dictionaries and some methods don't behave entirely like their counterparts, especially when there is more than one value associated with a form field. When used as a mapping, the keys are form input names, and the returned dictionary value can be:
In addition to standard mapping object methods, FieldStorage objects have the following attributes:
If the value associated with a field should be replaced when it
already exists, rather than an additional value being associated
with the field, the dictionary like subscript operator should
be used to set the value, or the existing field deleted altogether
first using the del
if name is a valid form field. The in
operator is also supported and will call this method.
operator is also supported and will return the number of names
which would be returned by this method.