mirror of https://github.com/django/django.git
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
This commit is contained in:
parent
93b1f9ad6e
commit
1d8db5ad89
1
AUTHORS
1
AUTHORS
|
@ -126,6 +126,7 @@ answer newbie questions, and generally made Django that much better:
|
||||||
Oliver Rutherfurd <http://rutherfurd.net/>
|
Oliver Rutherfurd <http://rutherfurd.net/>
|
||||||
Ivan Sagalaev (Maniac) <http://www.softwaremaniacs.org/>
|
Ivan Sagalaev (Maniac) <http://www.softwaremaniacs.org/>
|
||||||
David Schein
|
David Schein
|
||||||
|
Pete Shinners <pete@shinners.org>
|
||||||
sopel
|
sopel
|
||||||
Thomas Steinacher <tom@eggdrop.ch>
|
Thomas Steinacher <tom@eggdrop.ch>
|
||||||
Radek Švarz <http://www.svarz.cz/translate/>
|
Radek Švarz <http://www.svarz.cz/translate/>
|
||||||
|
|
|
@ -187,17 +187,23 @@ class MultiValueDict(dict):
|
||||||
"Returns a copy of this object."
|
"Returns a copy of this object."
|
||||||
return self.__deepcopy__()
|
return self.__deepcopy__()
|
||||||
|
|
||||||
def update(self, other_dict):
|
def update(self, *args, **kwargs):
|
||||||
"update() extends rather than replaces existing key lists."
|
"update() extends rather than replaces existing key lists. Also accepts keyword args."
|
||||||
if isinstance(other_dict, MultiValueDict):
|
if len(args) > 1:
|
||||||
for key, value_list in other_dict.lists():
|
raise TypeError, "update expected at most 1 arguments, got %d", len(args)
|
||||||
self.setlistdefault(key, []).extend(value_list)
|
if args:
|
||||||
else:
|
other_dict = args[0]
|
||||||
try:
|
if isinstance(other_dict, MultiValueDict):
|
||||||
for key, value in other_dict.items():
|
for key, value_list in other_dict.lists():
|
||||||
self.setlistdefault(key, []).append(value)
|
self.setlistdefault(key, []).extend(value_list)
|
||||||
except TypeError:
|
else:
|
||||||
raise ValueError, "MultiValueDict.update() takes either a MultiValueDict or dictionary"
|
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):
|
class DotExpandedDict(dict):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue