From 1bfb388d86db61944ab8a13403b185bef931abfb Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 5 Sep 2001 19:45:34 +0000 Subject: 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. --- Lib/cgi.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Lib/cgi.py b/Lib/cgi.py index 55ed3d1..19304af 100755 --- a/Lib/cgi.py +++ b/Lib/cgi.py @@ -564,6 +564,28 @@ class FieldStorage: else: 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.""" if self.list is None: -- cgit v0.12