summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcce <devnull@localhost>2006-09-21 05:56:36 +0000
committercce <devnull@localhost>2006-09-21 05:56:36 +0000
commitd0f0fd0d81a5ea457386c3e39105aa3bf0e75993 (patch)
treebe66bcaf4cfb6d5a2f67290d96b19f563052db32
parent3559f127031598b0dcc2a243454d2c15309a109b (diff)
downloadpaste-d0f0fd0d81a5ea457386c3e39105aa3bf0e75993.tar.gz
- adding dict_of_lists() to multidict to return a standard
argument dictionary where values corresponding to a given key are returned in a list If you used the all_as_list argument to parse_formvars that was removed w/o backwards compatibility, you can convert your code to add .dict_of_lists() on the return value of parse_formvars as a replacement.
-rw-r--r--paste/util/multidict.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/paste/util/multidict.py b/paste/util/multidict.py
index 3d1cc46..37a9d8c 100644
--- a/paste/util/multidict.py
+++ b/paste/util/multidict.py
@@ -90,6 +90,20 @@ class MultiDict(DictMixin):
result[key] = value
return result
+ def dict_of_lists(self):
+ """
+ Returns a dictionary where each key is associated with a
+ list of values.
+ """
+ result = {}
+ multi = {}
+ for key, value in self._items:
+ if key in result:
+ result[key].append(value)
+ else:
+ result[key] = [value]
+ return result
+
def __delitem__(self, key):
items = self._items
found = False