This function, given a CGI form, extracts the data from it, based on valuelist passed in. Any non-present values are set to '' - although this can be changed. (e.g. to return None so you can test for missing keywords - where '' is a valid answer but to have the field missing isn't.)
(valuelist, theform, notpresent='')
| 48 | # Private functions and variables |
| 49 | |
| 50 | def getform(valuelist, theform, notpresent=''): |
| 51 | """This function, given a CGI form, extracts the data from it, based on |
| 52 | valuelist passed in. Any non-present values are set to '' - although this can be changed. |
| 53 | (e.g. to return None so you can test for missing keywords - where '' is a valid answer but to have the field missing isn't.)""" |
| 54 | data = {} |
| 55 | for field in valuelist: |
| 56 | if not theform.has_key(field): |
| 57 | data[field] = notpresent |
| 58 | else: |
| 59 | if type(theform[field]) != type([]): |
| 60 | data[field] = theform[field].value |
| 61 | else: |
| 62 | values = map(lambda x: x.value, theform[field]) # allows for list type values |
| 63 | data[field] = values |
| 64 | return data |
| 65 | |
| 66 | |
| 67 | theformhead = """<HTML><HEAD><TITLE>cgi-shell.py - a CGI by Fuzzyman</TITLE></HEAD> |
no test coverage detected