[Web-SIG] Form field dictionaries

Ian Bicking ianb at colorstudy.com
Fri Oct 24 13:02:23 EDT 2003


On Friday, October 24, 2003, at 11:40 AM, Barry Warsaw wrote:
> BTW, I'll note interestingly enough that in some recent cgi-ish
> applications I've written, I've always wanted __getitem__() to return a
> list.  If there's one form variable by that name, I coerce the 
> singleton
> string to a list of one element.  For various reasons, it's been quite
> handy to treat everything uniformly in this manner.
>
> Maybe that's another option for the library.

No, please no options!  You already could get this through some 
getlist() method, or just make a wrapper, or just fiddle with the 
request in place:

req.lfields = {}
for name, value in req.fields(): # or whatever
     if not isinstance(value, list): value = [value]
     request.lfields[name] = value

Any of these will leave the request object usable by other code that 
expects normal behavior.

--
Ian Bicking | ianb at colorstudy.com | http://blog.ianbicking.org




More information about the Web-SIG mailing list