Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1bfb388

Browse files
committed
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.
1 parent 09f1ad8 commit 1bfb388

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

Lib/cgi.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,28 @@ def getvalue(self, key, default=None):
564564
else:
565565
return default
566566

567+
def getfirst(self, key, default=None):
568+
""" Return the first value received."""
569+
if self.has_key(key):
570+
value = self[key]
571+
if type(value) is type([]):
572+
return value[0].value
573+
else:
574+
return value.value
575+
else:
576+
return default
577+
578+
def getlist(self, key):
579+
""" Return list of received values."""
580+
if self.has_key(key):
581+
value = self[key]
582+
if type(value) is type([]):
583+
return map(lambda v: v.value, value)
584+
else:
585+
return [value.value]
586+
else:
587+
return []
588+
567589
def keys(self):
568590
"""Dictionary style keys() method."""
569591
if self.list is None:

0 commit comments

Comments
 (0)