summaryrefslogtreecommitdiff
path: root/django/utils/datastructures.py
diff options
context:
space:
mode:
authorJoseph Kocherhans <joseph@jkocherhans.com>2010-02-22 23:38:18 +0000
committerJoseph Kocherhans <joseph@jkocherhans.com>2010-02-22 23:38:18 +0000
commitb3d20ade47aadce5bd02ff33ea7dc0e19cf004cb (patch)
tree2fed7947493acecbd875527f7519f4df694da5f4 /django/utils/datastructures.py
parent49d6a82261feda6ee1bf23bb17184e932e232172 (diff)
downloaddjango-b3d20ade47aadce5bd02ff33ea7dc0e19cf004cb.tar.gz
Fixed #12820. Implemented other dict methods for MergeDict. Thanks, Gisle Aas.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12498 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils/datastructures.py')
-rw-r--r--django/utils/datastructures.py30
1 files changed, 26 insertions, 4 deletions
diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py
index d6fc9dc56f..3cbbe27b91 100644
--- a/django/utils/datastructures.py
+++ b/django/utils/datastructures.py
@@ -37,11 +37,32 @@ class MergeDict(object):
return dict_.getlist(key)
return []
- def items(self):
- item_list = []
+ def iteritems(self):
+ seen = set()
for dict_ in self.dicts:
- item_list.extend(dict_.items())
- return item_list
+ for item in dict_.iteritems():
+ k, v = item
+ if k in seen:
+ continue
+ seen.add(k)
+ yield item
+
+ def iterkeys(self):
+ for k, v in self.iteritems():
+ yield k
+
+ def itervalues(self):
+ for k, v in self.iteritems():
+ yield v
+
+ def items(self):
+ return list(self.iteritems())
+
+ def keys(self):
+ return list(self.iterkeys())
+
+ def values(self):
+ return list(self.itervalues())
def has_key(self, key):
for dict_ in self.dicts:
@@ -50,6 +71,7 @@ class MergeDict(object):
return False
__contains__ = has_key
+ __iter__ = iterkeys
def copy(self):
"""Returns a copy of this object."""