cgipm

cgipm Developer's Guide

Table of Contents

Overview

The problem is to provide a cgi tool which is familiar to Perl programmers accustomed to CGI.pm. We use the basic functionality of python's standard cgi.py, but add a wrapper for syntactic sugar.

See test01.py for an example of use in an OO setting. See test02.py for an example of use in an in-line setting.

HTML Shortcuts

These allow the programmer to build html tags programmatically. E.g.:

  print q.tr(q.td(key),q.td(value))
builds
  <TR ><TD>mytxt</TD><TD>"abc"</TD></TR>
  <TR ><TD>myint</TD><TD>123</TD></TR>
  ...

Doing every single html tag would be tedious, so we support generic tagging, with tag, start_tag, and end_tag.

Both specifc and generic routines need to return strings. And they need to support variable number of arguments and variable name=value pairs.

Input control

One interesting requirement is support for debugging without actually running the cgi via a web server. There are several cases:

commandline filename
test01.py input.dat. Where input.dat is a file with
mytxt="abc def"
myint=123
myflag

stdin redirection
test01.py < input.dat

stdin user prompt
test01.py The system prompts the user to enter a series of lines, terminated with control-d.

commandline args
test01.py mytxt="abc def" myint=123 myflag

Output control

For now, we build local StringIO objects, and return their values from each routine. But we could make one for the whole instantiation of CGI, and print it only at the end.

Architecture

The cgipm.py module is a standalone module. It imports cgi, to get at FieldStorage, but saves that in its own _params data member. A using module would either instantiate a CGI object query=CGI() or inherit from CGI:

class myobj(CGI):
    CGI.__init__(self)
    ...


Creator: Harry George
Updated/Created: 2000-04-01