[ python-Bugs-444913 ] cgi.FieldStorage doesn't have __nonzero_

SourceForge.net noreply at sourceforge.net
Fri Jun 22 12:44:25 CEST 2007


Bugs item #444913, was opened at 2001-07-26 20:21
Message generated for change (Comment added) made by petersidor
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=444913&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: None
Status: Closed
Resolution: Wont Fix
Priority: 5
Private: No
Submitted By: Ian Bicking (ianbicking)
Assigned to: Nobody/Anonymous (nobody)
Summary: cgi.FieldStorage doesn't have __nonzero_

Initial Comment:
In some cases cgi.FieldStorage raises an exception on
__len__, which means that if you test for truth it will
raise an exception (very confusing!).  It should just
implement 
  def __nonzero__(self): return 1
or something.


----------------------------------------------------------------------

Comment By: Peter Sidor (petersidor)
Date: 2007-06-22 10:44

Message:
Logged In: YES 
user_id=1825058
Originator: NO

Truth is always to be tested for. :)

I am doing something like this:

FORM = cgi.FieldStorage()
for f in FORM:
	if f in ['uploaded_file']:
		uploadedFile = FORM[k]
		break

Later on, I use a function to actually save the uploaded file, perform a
couple checks, etc.

But it would be definitely nice to be able to test against that object,
ie:
if uploadedFile:
	print "stuff"
...instead of, say, storing something into another variable.

----------------------------------------------------------------------

Comment By: Ian Bicking (ianbicking)
Date: 2001-07-26 20:50

Message:
Logged In: YES 
user_id=210337

Logically false or true would be fine -- or just capture the
exception and return false (or true) on exception from
__len__.

I was using some code that returned a string or None, but
the FieldStorage object on file upload.  I wanted None to be
'', so I did:

value = value or ''

And got what at first seemed like a very weird exception
(since the call to __len__ was implicit).  It would be nice
if the FieldStorage for the file upload was true (as it
isn't empty).

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2001-07-26 20:42

Message:
Logged In: YES 
user_id=21627

Adding this nonzero method would break 
backwards-compatibility: Currently, an object created with
cgi.FieldStorage()
is logically false, whereas it would be true with this 
change. Can you give an example where you need to check 
the truth of a FieldStorage?


----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-07-26 20:31

Message:
Logged In: YES 
user_id=6380

You shouldn't be testing for truth.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=444913&group_id=5470


More information about the Python-bugs-list mailing list