diff --git a/django/template/context.py b/django/template/context.py
index 1ef7e88..0a8edf4 100644
a
|
b
|
class BaseContext(object):
|
30 | 30 | def __repr__(self): |
31 | 31 | return repr(self.dicts) |
32 | 32 | |
33 | | def __iter__(self): |
| 33 | def iteritems(self): |
| 34 | # Track the keys yielded so we don't send items more than once. |
| 35 | yielded_keys = set() |
34 | 36 | for d in reversed(self.dicts): |
35 | | yield d |
| 37 | for k in d: |
| 38 | if k not in yielded_keys: |
| 39 | yielded_keys.add(k) |
| 40 | yield (k, d[k]) |
| 41 | |
| 42 | def iterkeys(self): |
| 43 | return (item[0] for item in self.iteritems()) |
| 44 | |
| 45 | __iter__ = iterkeys |
| 46 | |
| 47 | def itervalues(self): |
| 48 | return (item[1] for item in self.iteritems()) |
| 49 | |
| 50 | def keys(self): |
| 51 | return list(self.iterkeys()) |
| 52 | |
| 53 | def items(self): |
| 54 | return list(self.iteritems()) |
| 55 | |
| 56 | def values(self): |
| 57 | return list(self.itervalues()) |
| 58 | |
| 59 | def __len__(self): |
| 60 | return len(set().union(*self.dicts)) |
36 | 61 | |
37 | 62 | def push(self): |
38 | 63 | d = {} |
… |
… |
class BaseContext(object):
|
65 | 90 | return True |
66 | 91 | return False |
67 | 92 | |
68 | | def __contains__(self, key): |
69 | | return self.has_key(key) |
| 93 | __contains__ = has_key |
70 | 94 | |
71 | 95 | def get(self, key, otherwise=None): |
72 | 96 | for d in reversed(self.dicts): |
… |
… |
class RenderContext(BaseContext):
|
122 | 146 | template context. |
123 | 147 | """ |
124 | 148 | def __iter__(self): |
125 | | for d in self.dicts[-1]: |
126 | | yield d |
| 149 | return self.dicts[-1].__iter__() |
127 | 150 | |
128 | 151 | def has_key(self, key): |
129 | | return key in self.dicts[-1] |
| 152 | return self.dicts[-1].has_key(key) |
130 | 153 | |
131 | 154 | def get(self, key, otherwise=None): |
132 | | d = self.dicts[-1] |
133 | | if key in d: |
134 | | return d[key] |
135 | | return otherwise |
| 155 | return self.dicts[-1].get(key, otherwise) |
| 156 | |
| 157 | def keys(self): |
| 158 | return self.dicts[-1].keys() |
| 159 | |
| 160 | def items(self): |
| 161 | return self.dicts[-1].items() |
| 162 | |
| 163 | def values(self): |
| 164 | return self.dicts[-1].values() |
| 165 | |
| 166 | def iterkeys(self): |
| 167 | return self.dicts[-1].iterkeys() |
| 168 | |
| 169 | def iteritems(self): |
| 170 | return self.dicts[-1].iteritems() |
| 171 | |
| 172 | def itervalues(self): |
| 173 | return self.dicts[-1].itervalues() |
| 174 | |
| 175 | def __len__(self): |
| 176 | return len(self.dicts[-1]) |
136 | 177 | |
137 | 178 | # This is a function rather than module-level procedural code because we only |
138 | 179 | # want it to execute if somebody uses RequestContext. |