[Patches] [Patch #101120] add .get() to cgi.FieldStorage and cgi.FormContentDict

Guido van Rossum guido@beopen.com
Thu, 24 Aug 2000 08:36:28 -0500


> Date: 2000-Aug-24 08:27
> By: ping
> 
> Comment:
> Hi, Jeremy.
> 
> I actually think the motivations for these changes are pretty clear.
> They directly address two things:
> 
> 1.  The doc strings say keep_blank_values is supposed to control
> whether blank values are kept.  This currently doesn't work at all.
> 
> 2.  The TeX documentation says the FieldStorage object is supposed
> to behave like a dictionary.  Dictionaries are expected to provide a
> .get() method, but the FieldStorage doesn't.
> 
> Both of these things are basically bugs.  The only decisions that
> remain have to do with backward compatibility when we fix #1 -- this
> is easily addressed by defaulting keep_blank_values to 1 -- and with
> determining the most effective way to implement .get() when we fix
> #2.
> 
> The implementation of .get() in this patch greatly simplifies most
> CGI scripts.  As shown in the examples in my previous comment, it
> can reduce four or five lines of mucking with the .value attribute
> to a single call.

Ping,

It may be me, but I'm getting annoyed by this.  For any object that
implements a partial mapping protocol, any mapping methods that it
implement should behave according to the mapping protocol, and be
consistent with the others.  So it's fine to leave e.e. items() out,
but it's not okay to implement items() as an alias for has_key().

Adding the functionality you want is great, but it shouldn't be called
get().  Call it getvalue() and I'm happy.

The words "behave like a dictionary" have such a vague meaning that
lacking a get() method can't be seen as a violation.  However having
a get() method that does something different *is* a violation!

--Guido van Rossum (home page: http://www.pythonlabs.com/~guido/)