Why is CGI module so complicated?

Ian Clarke I.Clarke at strs.co.uk
Wed Aug 11 07:18:17 EDT 1999


> : Can anyone explain what the point of the FieldStorage and
> : MiniFieldStorage objects are?

> Ian, please read my reply in the previous thread:
>   http://www.dejanews.com/getdoc.xp/AN=502365247

Well, unfortunately that link didn't work, but I managed to find the
comment I believe you are referring to, in which case I assume you were
indicating that the FieldStorage and MiniFieldStorage objects were used
for the case where a file upload is taking place.

I can't help but feel that this is not the best way.  How about go with
the method I described in my first post (where cgi fields are returned
as the types that they actually are, rather than being encased in
MiniFieldStorage objects).  Were more than one item is selected for a
given field a list could be returned, and for a file upload a tuple
could be returned containing the filename and the contents of the file -
or if that is not considered extendable enough, a CGIFileUpload object
could be returned containing the necessary fields.

This would mean that for the vast majority of CGI fields which are just
normal text, retrieval is very straight-forward and intuitive, just like
accessing strings stored in a dictionary.  More complexity is only
introduced when the user wants to do more complicated stuff (and even
then, it is pretty simple).  As mentioned in my previous post, it would
also allow the fields to be used as the substitutions for a
TemplateDocument directly, which can be quite a useful trick.

If I get some spare time today I will create a small module which will
provide this interface to CGI (although if anyone else wants to do it,
feel free!).  It would obviously be better if (assuming I can convince
others that this is a better way) this was integrated into the built-in
cgi module.

Ian.




More information about the Python-list mailing list