Web programming and a different "type" problem (was: Slice confusion : a[n:p] is a list exclude the last element p)

Jon Ribbens jon+usenet at unequivocal.co.uk
Mon Apr 28 20:23:07 EDT 2003


In article <vaqvrb3ipqblf2 at corp.supernews.com>, Cameron Laird wrote:
> 'Doesn't work, though.  Here's where the special case
> enters:  if only one datum with the indicated name is
> present as input, Zope and the others return it as a
> simple string, rather than a list with that string as 
> its sole member.

jonpy (jonpy.sf.net) avoids this problem. You name your multiple field
with a '*' suffix (e.g. <input type="checkbox" name="foo*">). All
fields with a '*' suffix are *always* lists when examined in your
Python program. All fields without a '*' suffix are *always* strings
(if there is more than one field with the same name but no '*' suffix
then all but one are discarded). e.g.:

  for foo in req.params.get("foo*", ()):
    process(foo)

It seems to me that allowing the Evil User to manipulate the type of
Python variables, as everything except jonpy seems to allow, is
fundamentally a bad idea.




More information about the Python-list mailing list