#!/usr/bin/python ################################################################## # run test5 logic with formMockup instead of cgi.FieldStorage() # to test: python test5_mockup.cgi > temp.html, and open temp.html ################################################################## from formMockup import formMockup form = formMockup(name='Bob', shoesize='Small', language=['Python', 'C++', 'HTML'], comment='ni, Ni, NI') # rest same as original, less form assignment import cgi, sys, string print "Content-type: text/html" # plus blank line html = """ test5.cgi

Greetings


Your name is %(name)s

You wear rather %(shoesize)s shoes

Your current job: %(job)s

You program in %(language)s

You also said:

%(comment)s


""" data = {} for field in ['name', 'shoesize', 'job', 'language', 'comment']: if not form.has_key(field): data[field] = '(unknown)' else: if type(form[field]) != type([]): data[field] = form[field].value else: values = map(lambda x: x.value, form[field]) data[field] = string.join(values, ' and ') print html % data