""tools for simulating the result of cgi fieldstorage(calluseful for testing cgi scripts outside the web ""class fieldmockupdef __init__(selfstr)self value str mocked-up input object def formmockup(**kwargs)pass field=value args mockup {multichoice[valuefor (keyvaluein kwargs items()if type(value!listsimple fields have value mockup[keyfieldmockup(str(value)elsemultichoice have list mockup[key[to dofile upload fields for pick in valuemockup[keyappend(fieldmockup(pick)return mockup def selftest()use this form if fields can be hardcoded form formmockup(name='bob'job='hacker'food=['spam''eggs''ham']print(form['name'valueprint(form['job'valuefor item in form['food']print(item valueend='use real dict if keys are in variables or computed print(form {'name'fieldmockup('brian')'age'fieldmockup( )or dict(for key in form keys()print(form[keyvalueif __name__ ='__main__'selftest(when we place our mock-up class in the module formmockup pyit automatically becomes reusable tool and may be imported by any script we care to write for readabilitythe dummy field simulation class has been renamed fieldmockup here for conveniencewe've also added formmockup utility function that builds up an entire form dictionary from passed-in keyword arguments assuming you can hardcode the names of the form to be fakedthe mock-up can be created in single call this module includes self-test function invoked when the file is run from the command linewhich demonstrates how its exports are used here is its test outputgenerated by making and querying two form mock-up objectsassumingof coursethat this module can be found on the python module search path when those scripts are run since python searches the current directory for imported modules by defaultthis generally works without sys path changes if all of our files are in our main web directory for other applicationswe may need to add this directory to pythonpath or use package (directory pathimports refactoring code for maintainability