[Python-checkins] CVS: python/dist/src/Lib cgi.py,1.66,1.67
Guido van Rossum
gvanrossum@users.sourceforge.net
Wed, 05 Sep 2001 12:45:36 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv26272
Modified Files:
cgi.py
Log Message:
Class FieldStorage: add two new methods, getfirst() and getlist(),
that provide a somewhat more uniform interface to getting values.
This is from SF patch #453691.
Index: cgi.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/cgi.py,v
retrieving revision 1.66
retrieving revision 1.67
diff -C2 -d -r1.66 -r1.67
*** cgi.py 2001/08/09 21:40:30 1.66
--- cgi.py 2001/09/05 19:45:34 1.67
***************
*** 565,568 ****
--- 565,590 ----
return default
+ def getfirst(self, key, default=None):
+ """ Return the first value received."""
+ if self.has_key(key):
+ value = self[key]
+ if type(value) is type([]):
+ return value[0].value
+ else:
+ return value.value
+ else:
+ return default
+
+ def getlist(self, key):
+ """ Return list of received values."""
+ if self.has_key(key):
+ value = self[key]
+ if type(value) is type([]):
+ return map(lambda v: v.value, value)
+ else:
+ return [value.value]
+ else:
+ return []
+
def keys(self):
"""Dictionary style keys() method."""