Ticket #2620: 2620.patch
File 2620.patch, 975 bytes (added by , 18 years ago) |
---|
-
django/utils/datastructures.py
old new 1 class NoDefault(object): 2 pass 3 1 4 class MergeDict(object): 2 5 """ 3 6 A simple class for creating new "virtual" dictionaries that actualy look … … 14 17 pass 15 18 raise KeyError 16 19 17 def get(self, key, default ):20 def get(self, key, default=NoDefault): 18 21 try: 19 22 return self[key] 20 23 except KeyError: -
new file tests/othertests/datastructures.py
- + 1 from django.utils.datastructures import MergeDict 2 3 dict1 = {'a': 1, 'b': 2} 4 dict2 = {'a': 10, 'c': 20} 5 6 dictm = MergeDict(dict1, dict2) 7 assert dictm['a'] == 1 8 assert dictm['b'] == 2 9 assert dictm['c'] == 20 10 assert dictm.get('b') == 2 11 assert dictm.get('b', 7) == 2 12 assert dictm.get('x', 7) == 7