This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: cgi.FieldStorage.__len__ eventually throws TypeError
Type: behavior Stage: test needed
Components: Library (Lib) Versions: Python 2.6
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, jlgijsbers, yxcv
Priority: normal Keywords: easy

Created on 2004-08-24 13:32 by yxcv, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg60552 - (view) Author: Andreas Ames (yxcv) Date: 2004-08-24 13:32
This makes it hazardous to do the following:

fs = cgi.FieldStorage(...)
if fs:
 ...

Suggestions:

1)  Fix __len__; sorry, but I don't know how.

2) Create FieldStorage.__nonzero__; a hack.

3) ?
msg60553 - (view) Author: Johannes Gijsbers (jlgijsbers) * (Python triager) Date: 2004-08-30 14:47
Logged In: YES 
user_id=469548

As far as I can tell, cgi.FieldStorage.__len__ only raises a
TypeError if the FieldStorage is not indexable. It's
reasonable not to support len() on an unindexable FieldStorage.

I'm just wondering why you would want to do:

fs = cgi.FieldStorage(...)
if fs:
...

Defining __nonzero__ seems reasonable if there's a reason
for testing a FieldStorage for truth value.
msg60554 - (view) Author: Andreas Ames (yxcv) Date: 2004-09-02 12:26
Logged In: YES 
user_id=898176

For a code snippet please look at:

http://mail.python.org/pipermail/python-list/2004-August/235988.html

AFAIK, cgi.FieldStorage is meant to either (sort of) 'be' a
list or a
file after having parsed the request.  So one could possibly
take the
builtin file object as kind of evidence:

>>> f = file('/etc/passwd')
>>> len(f)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: len() of unsized object
>>> if f:
...     print 'yes'
... else:
...     print 'no'
...
yes
>>>
msg112203 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-07-31 21:08
I don't see the bug here.
History
Date User Action Args
2022-04-11 14:56:06adminsetgithub: 40818
2010-07-31 21:08:08georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg112203

resolution: works for me
2009-04-22 15:22:08ajaksu2setkeywords: + easy
2009-02-14 14:43:41ajaksu2setstage: test needed
type: behavior
versions: + Python 2.6, - Python 2.3
2004-08-24 13:32:25yxcvcreate