Commit fa843769 authored by Guido van Rossum's avatar Guido van Rossum

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.
parent 3234d5dc
...@@ -564,6 +564,28 @@ class FieldStorage: ...@@ -564,6 +564,28 @@ class FieldStorage:
else: else:
return default 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): def keys(self):
"""Dictionary style keys() method.""" """Dictionary style keys() method."""
if self.list is None: if self.list is None:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment