4.4.1 FieldStorage class

Access to form data is provided via the FieldStorage class. This class is similar to the standard library module cgi FieldStorage (but there are a few differences).

FieldStorage (req[, keep_blank_values, strict_parsing])
This class provides uniform access to HTML form data submitted by the client. req is an instance of the mod_python Request object.

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.

While being instantiated, the 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 signle request, nor should you make any attempts to read client data before or after instantiating a FieldStorage.

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 file, 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. When used as a dictionary, the dictionary 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:

list
This is a list of Field objects, one for each input. Multiple inputs with the same name will have multiple elements in this list.


Subsections