Issue 1015249: cgi.FieldStorage.len eventually throws TypeError (original) (raw)

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 "", 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:06 admin set github: 40818
2010-07-31 21:08:08 georg.brandl set status: open -> closednosy: + georg.brandlmessages: + resolution: works for me
2009-04-22 15:22:08 ajaksu2 set keywords: + easy
2009-02-14 14:43:41 ajaksu2 set stage: test neededtype: behaviorversions: + Python 2.6, - Python 2.3
2004-08-24 13:32:25 yxcv create