[Q] Bug in cgi.FieldStorage?

Ames Andreas (MPA/DF) Andreas.Ames at tenovis.com
Mon Aug 23 13:15:11 EDT 2004


Hello,

Tim Roberts wrote:

>>if fs:
>>   ...
>
> What question do you intuitively expect that statement to be asking?

class Request:
      def __init__(self, fs = None)
          if fs:
             self._fs = fs
          else:
             self._fs = FieldStorage(...)

      def retry(self):
          return self.__class__(self._fs)

Something like that.  I cannot say why, but I find it somewhat odd
that

if fs:

can throw a TypeError.  OTOH, that might be my C heritage:

char *ptr = 0;
...
if (ptr) {
   ...
}

FWIW, there are some more things I don't like about cgi.FieldStorage:

1) Tryig sometimes to be a list and a file at other times is a bit
   confusing for me as a user.

2) Doing the whole parsing from within the constructor isn't very
   nice, for example for derivations.

3) Calling the constructor directly from read_multipart prevents me
   from specifying custom constructor arguments.  I'd prefer an
   overwriteable factory method.


cheers,

andreas




More information about the Python-list mailing list