Django

Code

Changeset 3692

Show
Ignore:
Timestamp:
08/31/06 16:51:19 (2 years ago)
Author:
adrian
Message:

Fixed #2441 -- Improved MultiValueDict?.update() to take keyword args, like Python 2.4 built-in dict. Thanks for the patch, Pete Shinners

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/AUTHORS

    r3601 r3692  
    127127    Ivan Sagalaev (Maniac) <http://www.softwaremaniacs.org/> 
    128128    David Schein 
     129    Pete Shinners <pete@shinners.org> 
    129130    sopel 
    130131    Thomas Steinacher <tom@eggdrop.ch> 
  • django/trunk/django/utils/datastructures.py

    r3113 r3692  
    188188        return self.__deepcopy__() 
    189189 
    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) 
    201207 
    202208class DotExpandedDict(dict):