Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit 1d8db5ad89740e7e1783c964cf74148db1ac5876 1 parent 93b1f9a
Adrian Holovaty authored August 31, 2006
1  AUTHORS
@@ -126,6 +126,7 @@ answer newbie questions, and generally made Django that much better:
126 126
     Oliver Rutherfurd <http://rutherfurd.net/>
127 127
     Ivan Sagalaev (Maniac) <http://www.softwaremaniacs.org/>
128 128
     David Schein
  129
+    Pete Shinners <pete@shinners.org>
129 130
     sopel
130 131
     Thomas Steinacher <tom@eggdrop.ch>
131 132
     Radek Švarz <http://www.svarz.cz/translate/>
28  django/utils/datastructures.py
@@ -187,17 +187,23 @@ def copy(self):
187 187
         "Returns a copy of this object."
188 188
         return self.__deepcopy__()
189 189
 
190  
-    def update(self, other_dict):
191  
-        "update() extends rather than replaces existing key lists."
192  
-        if isinstance(other_dict, MultiValueDict):
193  
-            for key, value_list in other_dict.lists():
194  
-                self.setlistdefault(key, []).extend(value_list)
195  
-        else:
196  
-            try:
197  
-                for key, value in other_dict.items():
198  
-                    self.setlistdefault(key, []).append(value)
199  
-            except TypeError:
200  
-                raise ValueError, "MultiValueDict.update() takes either a MultiValueDict or dictionary"
  190
+    def update(self, *args, **kwargs):
  191
+        "update() extends rather than replaces existing key lists. Also accepts keyword args."
  192
+        if len(args) > 1:
  193
+            raise TypeError, "update expected at most 1 arguments, got %d", len(args)
  194
+        if args:
  195
+            other_dict = args[0]
  196
+            if isinstance(other_dict, MultiValueDict):
  197
+                for key, value_list in other_dict.lists():
  198
+                    self.setlistdefault(key, []).extend(value_list)
  199
+            else:
  200
+                try:
  201
+                    for key, value in other_dict.items():
  202
+                        self.setlistdefault(key, []).append(value)
  203
+                except TypeError:
  204
+                    raise ValueError, "MultiValueDict.update() takes either a MultiValueDict or dictionary"
  205
+        for key, value in kwargs.iteritems():
  206
+            self.setlistdefault(key, []).append(value)
201 207
 
202 208
 class DotExpandedDict(dict):
203 209
     """

0 notes on commit 1d8db5a

Please sign in to comment.
Something went wrong with that request. Please try again.