A General Handling of Form Data
This incoming handler does not replace CGI scripts but it obviates the need for many of them. If the page-generator needs the form itself, you need a CGI script. Otherwise, incoming should be sufficient.
If "incoming" is a key in the cgi.form, ming.cgi expects these keys in the form data:
- file - must be a entry in FILES
- page - valid ming.cgi page target
It will use these USER CONSTS in Constants.py:
- FILES_DIR = "../data/files" # Must be read/write dir for the webserver
- FILE_MAXLINES = 1000 # Upper limit on file length
- INCOMING_MAX = 64*1024 # 64 kb
- FILES = "3.files" # Lists filenames accessible in FILES_DIR, lives in cgi-bin
FILES contains name only, one on each line, no paths. If form's file is in FILES, ming.cgi reads up FILES_DIR+os.sep+file It then opens it for writing and writes a datestamp of the form
stamp|xxxxxxxxx.xxxwhere the Xs are time in seconds converted to string, followed by
key|form[key].value()\nfor all keys but file, page, incoming, submit, and debug. (It only writes after testing sizes against INCOMING_MAX.) Then it writes "---\n" and closes the file.
Finally, it opens form["page"].value() in the client browser.
So, you can have a page with a form. It's incoming value triggers both the writing of the data and the triggering of the page which uses the data.
It is useful to have an empty dir with single-page subdirs for these page targets. I have, for example, /singles/thanks dir with a key file and a thankyou file. It thanks you for filling out a form and links back to a useful page.
Files are truncated at FILE_MAXLINES. So your code must handle abrupt truncation. I use try-except clauses.