diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py
index 85cdd44..2b586d7 100644
a
|
b
|
|
| 1 | from copy import deepcopy |
| 2 | |
| 3 | |
1 | 4 | class MergeDict(object): |
2 | 5 | """ |
3 | 6 | A simple class for creating new "virtual" dictionaries that actually look |
… |
… |
class SortedDict(dict):
|
72 | 75 | self.keyOrder.append(key) |
73 | 76 | |
74 | 77 | def __deepcopy__(self, memo): |
75 | | from copy import deepcopy |
76 | 78 | return self.__class__([(key, deepcopy(value, memo)) |
77 | 79 | for key, value in self.iteritems()]) |
78 | 80 | |
79 | 81 | def __setitem__(self, key, value): |
80 | | super(SortedDict, self).__setitem__(key, value) |
81 | | if key not in self.keyOrder: |
| 82 | if key not in self: |
82 | 83 | self.keyOrder.append(key) |
| 84 | super(SortedDict, self).__setitem__(key, value) |
83 | 85 | |
84 | 86 | def __delitem__(self, key): |
85 | 87 | super(SortedDict, self).__delitem__(key) |
86 | 88 | self.keyOrder.remove(key) |
87 | 89 | |
88 | 90 | def __iter__(self): |
89 | | for k in self.keyOrder: |
90 | | yield k |
| 91 | return iter(self.keyOrder) |
91 | 92 | |
92 | 93 | def pop(self, k, *args): |
93 | 94 | result = super(SortedDict, self).pop(k, *args) |
… |
… |
class SortedDict(dict):
|
108 | 109 | |
109 | 110 | def iteritems(self): |
110 | 111 | for key in self.keyOrder: |
111 | | yield key, super(SortedDict, self).__getitem__(key) |
| 112 | yield key, self[key] |
112 | 113 | |
113 | 114 | def keys(self): |
114 | 115 | return self.keyOrder[:] |
… |
… |
class SortedDict(dict):
|
117 | 118 | return iter(self.keyOrder) |
118 | 119 | |
119 | 120 | def values(self): |
120 | | return map(super(SortedDict, self).__getitem__, self.keyOrder) |
| 121 | return map(self.__getitem__, self.keyOrder) |
121 | 122 | |
122 | 123 | def itervalues(self): |
123 | 124 | for key in self.keyOrder: |
124 | | yield super(SortedDict, self).__getitem__(key) |
| 125 | yield self[key] |
125 | 126 | |
126 | 127 | def update(self, dict_): |
127 | | for k, v in dict_.items(): |
128 | | self.__setitem__(k, v) |
| 128 | for k, v in dict_.iteritems(): |
| 129 | self[k] = v |
129 | 130 | |
130 | 131 | def setdefault(self, key, default): |
131 | | if key not in self.keyOrder: |
| 132 | if key not in self: |
132 | 133 | self.keyOrder.append(key) |
133 | 134 | return super(SortedDict, self).setdefault(key, default) |
134 | 135 | |
… |
… |
class MultiValueDict(dict):
|
222 | 223 | dict.__setitem__(result, copy.deepcopy(key, memo), |
223 | 224 | copy.deepcopy(value, memo)) |
224 | 225 | return result |
225 | | |
| 226 | |
226 | 227 | def __getstate__(self): |
227 | 228 | obj_dict = self.__dict__.copy() |
228 | 229 | obj_dict['_data'] = dict([(k, self.getlist(k)) for k in self]) |
229 | 230 | return obj_dict |
230 | | |
| 231 | |
231 | 232 | def __setstate__(self, obj_dict): |
232 | 233 | data = obj_dict.pop('_data', {}) |
233 | 234 | for k, v in data.items(): |
234 | 235 | self.setlist(k, v) |
235 | 236 | self.__dict__.update(obj_dict) |
236 | | |
| 237 | |
237 | 238 | def get(self, key, default=None): |
238 | 239 | """ |
239 | 240 | Returns the last data value for the passed key. If key doesn't exist |
… |
… |
class MultiValueDict(dict):
|
301 | 302 | def values(self): |
302 | 303 | """Returns a list of the last value on every key list.""" |
303 | 304 | return [self[key] for key in self.keys()] |
304 | | |
| 305 | |
305 | 306 | def itervalues(self): |
306 | 307 | """Yield the last value on every key list.""" |
307 | 308 | for key in self.iterkeys(): |
308 | 309 | yield self[key] |
309 | | |
| 310 | |
310 | 311 | def copy(self): |
311 | 312 | """Returns a copy of this object.""" |
312 | 313 | return self.__deepcopy__() |