Changeset 7062
- Timestamp:
- 02/02/08 20:02:41 (5 months ago)
- Files:
-
- django/trunk/django/utils/datastructures.py (modified) (2 diffs)
- django/trunk/tests/regressiontests/datastructures/tests.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/utils/datastructures.py
r6800 r7062 3 3 A simple class for creating new "virtual" dictionaries that actually look 4 4 up values in more than one dictionary, passed in the constructor. 5 6 If a key appears in more than one of the passed in dictionaries, only the 7 first occurrence will be used. 5 8 """ 6 9 def __init__(self, *dicts): … … 26 29 def getlist(self, key): 27 30 for dict_ in self.dicts: 28 try:31 if key in dict_.keys(): 29 32 return dict_.getlist(key) 30 except KeyError: 31 pass 32 raise KeyError 33 return [] 33 34 34 35 def items(self): django/trunk/tests/regressiontests/datastructures/tests.py
r6715 r7062 20 20 >>> md2['chris'] 21 21 'cool' 22 23 MergeDict can merge MultiValueDicts 24 >>> multi1 = MultiValueDict({'key1': ['value1'], 'key2': ['value2', 'value3']}) 25 >>> multi2 = MultiValueDict({'key2': ['value4'], 'key4': ['value5', 'value6']}) 26 >>> mm = MergeDict(multi1, multi2) 27 28 # Although 'key2' appears in both dictionaries, only the first value is used. 29 >>> mm.getlist('key2') 30 ['value2', 'value3'] 31 >>> mm.getlist('key4') 32 ['value5', 'value6'] 33 >>> mm.getlist('undefined') 34 [] 22 35 23 36 ### MultiValueDict ##########################################################
