[Web-SIG] Form field dictionaries

Steve Holden sholden at holdenweb.com
Wed Oct 29 10:11:33 EST 2003


[David Fraser]
> Barry Warsaw wrote:
>
> >On Wed, 2003-10-29 at 09:29, Gregory (Grisha) Trubetskoy wrote:
> >
> >
> >
> >>I am in favor of form['fieldname'] to act the same as
> getfirst() only if
> >>there is a single element, otherwise it should return a list.
> >>
> >>
> >
> >+1
> >
> >
> >
> -2!
> (That's two factorial :-)
> I want form['fieldname'] to always return a single element.
> You should always know when you're wanting a list.
> Returning a list otherwise requires lots of exceptional-case-checking
> code that is unneccessary.
> But then I'm just repeating myself...
>
In which case, let _me_ repeat _myself_ :-)

If an argument has multiple values, this should only be handled if the
processing element (page code) has indicated that multiple values are
acceptable for that argument. When an argument is possibly multi-valued,
form['fieldname'] should *always* be a list, even if it has only one
element [and I don't see why it shouldn't be legal to see an empty list
if the argument doesn't appear in the URL or POST input at all]. If no
indication has been given that multiple occurrences are acceptable then
an exception should be raised which, if not trapped by the web app,
should eventually result in (say) a 422 (unprocessable entity) or a 406
(not acceptable) server response.

When an argument is *not* allowed to be multi-valued then
form['fieldname'] should return a string, and an error should be raised
if the argument has multiple occurrences. If the argument doesn't appear
in the URL or POST data at all then it's arguable that a KeyError should
be raised, again resulting in a server error if untrapped.

I'd be prepared to allow a "sloppy" option to have form['fieldname']
return an empty string under those circumstances, a la ASP, and to
return the first of multiple occurrences. But I *do* think that "sloppy"
would be an apposite name for such tactics.

if we're building a new API then for heaven's sake let's not repeat the
mistakes of earlier generations. And let's try not to have each of these
discussions more that two or three times a month :-)

regards
--
Steve Holden          +1 703 278 8281        http://www.holdenweb.com/
Improve the Internet           http://vancouver-webpages.com/CacheNow/
Python Web Programming                http://pydish.holdenweb.com/pwp/
Interview with GvR August 14, 2003       http://www.onlamp.com/python/






More information about the Web-SIG mailing list