commit 9e1e44b77d83e99f457c75f503038b48a6c4f026
parent 353a2b7505744caf8f4bd793e6d6fea22535854a
Author: Dan Callaghan <djc@djc.id.au>
Date: Tue, 16 Sep 2008 02:02:22 +1000
Colubrid patch from bb r143
Diffstat:
1 file changed, 14 insertions(+), 0 deletions(-)
diff --git a/lib/colubrid/utils.py b/lib/colubrid/utils.py
@@ -105,6 +105,20 @@ class MultiDict(dict):
for key, value in other_dict.items():
self.setlistdefault(key, []).append(value)
+ def as_dict(self):
+ """
+ A MultiDict has lists as its real values, which means if we construct
+ a dict from it or use it as keyword args (really anything which touches
+ the internal dict implementation directly, instead of going through
+ __getitem__) then we will get lists everywhere.
+
+ This method returns a real dict, with the same keys as this MultiDict,
+ but with just the last value for each key (or None if it has no
+ values).
+ """
+ return dict((k, self.get(k, None)) for k in self.iterkeys())
+
+
class MergedMultiDict(object):
"""