summaryrefslogtreecommitdiff
path: root/django/utils/datastructures.py
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2006-08-31 21:51:19 +0000
committerAdrian Holovaty <adrian@holovaty.com>2006-08-31 21:51:19 +0000
commit1d8db5ad89740e7e1783c964cf74148db1ac5876 (patch)
tree224ca203a8bc7e7924aac42b1871a39ad3ab5e2f /django/utils/datastructures.py
parent93b1f9ad6eb96d7ca9e09739bc0484a6f8212e51 (diff)
downloaddjango-1d8db5ad89740e7e1783c964cf74148db1ac5876.tar.gz
Fixed #2441 -- Improved MultiValueDict.update() to take keyword args, like Python 2.4 built-in dict. Thanks for the patch, Pete Shinners
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3692 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils/datastructures.py')
-rw-r--r--django/utils/datastructures.py28
1 files changed, 17 insertions, 11 deletions
diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py
index 632e804f26..6aef313d35 100644
--- a/django/utils/datastructures.py
+++ b/django/utils/datastructures.py
@@ -187,17 +187,23 @@ class MultiValueDict(dict):
"Returns a copy of this object."
return self.__deepcopy__()
- def update(self, other_dict):
- "update() extends rather than replaces existing key lists."
- if isinstance(other_dict, MultiValueDict):
- for key, value_list in other_dict.lists():
- self.setlistdefault(key, []).extend(value_list)
- else:
- try:
- for key, value in other_dict.items():
- self.setlistdefault(key, []).append(value)
- except TypeError:
- raise ValueError, "MultiValueDict.update() takes either a MultiValueDict or dictionary"
+ def update(self, *args, **kwargs):
+ "update() extends rather than replaces existing key lists. Also accepts keyword args."
+ if len(args) > 1:
+ raise TypeError, "update expected at most 1 arguments, got %d", len(args)
+ if args:
+ other_dict = args[0]
+ if isinstance(other_dict, MultiValueDict):
+ for key, value_list in other_dict.lists():
+ self.setlistdefault(key, []).extend(value_list)
+ else:
+ try:
+ for key, value in other_dict.items():
+ self.setlistdefault(key, []).append(value)
+ except TypeError:
+ raise ValueError, "MultiValueDict.update() takes either a MultiValueDict or dictionary"
+ for key, value in kwargs.iteritems():
+ self.setlistdefault(key, []).append(value)
class DotExpandedDict(dict):
"""