next up previous contents index
Next: 11.1.5 Caring about security Up: 11.1 Standard Module cgi Previous: 11.1.3 Old classes

11.1.4 Functions

These are useful if you want more control, or if you want to employ some of the algorithms implemented in this module in other circumstances.

parse(fp)
: Parse a query in the environment or from a file (default sys.stdin).

parse_qs(qs)
: parse a query string given as a string argument (data of type application/x-www-form-urlencoded).

parse_multipart(fp, pdict)
: parse input of type multipart/form-data (for file uploads). Arguments are fp for the input file and pdict for the 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.

Note that this does not parse nested multipart parts - use FieldStorage for that.

parse_header(string)
: parse a header like Content-type into a main content-type and a dictionary of parameters.

test()
: robust test CGI script, usable as main program. Writes minimal HTTP headers and formats all information provided to the script in HTML form.

print_environ()
: format the shell environment in HTML.

print_form(form)
: format a form in HTML.

print_directory()
: format the current directory in HTML.

print_environ_usage()
: print a list of useful (used by CGI) environment variables in HTML.

escape()
: convert the characters ``&'', ``<'' and ``>'' to HTML-safe sequences. Use this if you need to display text that might contain such characters in HTML. To translate URLs for inclusion in the HREF attribute of an <A> tag, use urllib.quote().


next up previous contents index
Next: 11.1.5 Caring about security Up: 11.1 Standard Module cgi Previous: 11.1.3 Old classes

guido@cnri.reston.va.us