From d0f0fd0d81a5ea457386c3e39105aa3bf0e75993 Mon Sep 17 00:00:00 2001 From: cce Date: Thu, 21 Sep 2006 05:56:36 +0000 Subject: - 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. --- paste/util/multidict.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 -- cgit v1.2.1