diff options
author | Guido van Rossum <guido@python.org> | 2001-09-05 19:45:34 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2001-09-05 19:45:34 (GMT) |
commit | 1bfb388d86db61944ab8a13403b185bef931abfb (patch) | |
tree | 2ebfbfd2b5c8c4cc2ded79241e19188ba49071c9 | |
parent | 09f1ad854237542315ec86151aa56b143e54d1d2 (diff) | |
download | cpython-1bfb388d86db61944ab8a13403b185bef931abfb.zip cpython-1bfb388d86db61944ab8a13403b185bef931abfb.tar.gz cpython-1bfb388d86db61944ab8a13403b185bef931abfb.tar.bz2 |
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.
-rwxr-xr-x | Lib/cgi.py | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -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: |